[PATCH] D58179: [OpenCL][PR40707] Allow OpenCL C types in C++ mode

2019-02-19 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia closed this revision.
Anastasia added a comment.

Committed in r354121.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D58179/new/

https://reviews.llvm.org/D58179



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D58179: [OpenCL][PR40707] Allow OpenCL C types in C++ mode

2019-02-15 Thread Ronan Keryell via Phabricator via cfe-commits
keryell added a comment.

LGTM.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D58179/new/

https://reviews.llvm.org/D58179



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D58179: [OpenCL][PR40707] Allow OpenCL C types in C++ mode

2019-02-15 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh accepted this revision.
svenvh added a comment.
This revision is now accepted and ready to land.

LGTM!


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D58179/new/

https://reviews.llvm.org/D58179



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D58179: [OpenCL][PR40707] Allow OpenCL C types in C++ mode

2019-02-13 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia created this revision.
Anastasia added a reviewer: svenvh.
Herald added subscribers: ebevhan, yaxunl.

Allow all OpenCL types to be parsed in C++ mode.

I plan to enable more tests but they are currently failing for different 
reasons. This commit makes sure images can be used as they are reported in the 
bug.


https://reviews.llvm.org/D58179

Files:
  include/clang/Basic/DiagnosticParseKinds.td
  include/clang/Basic/TokenKinds.def
  lib/Parse/ParseDecl.cpp
  lib/Parse/ParseExprCXX.cpp
  lib/Parse/ParseTentative.cpp
  lib/Sema/SemaDeclAttr.cpp
  test/CodeGenOpenCL/images.cl
  test/SemaOpenCL/invalid-image.cl
  test/SemaOpenCLCXX/restricted.cl

Index: test/SemaOpenCLCXX/restricted.cl
===
--- test/SemaOpenCLCXX/restricted.cl
+++ test/SemaOpenCLCXX/restricted.cl
@@ -39,25 +39,3 @@
   thread_local int y;
   // expected-error@-1 {{OpenCL C++ version 1.0 does not support the 'thread_local' storage class specifier}}
 }
-
-// Test that access qualifiers are reserved keywords.
-kernel void test_access_qualifiers() {
-  int read_only;
-  // expected-error@-1 {{'read_only' is a reserved keyword in OpenCL C++}}
-  // expected-warning@-2 {{declaration does not declare anything}}
-  int __read_only;
-  // expected-error@-1 {{'__read_only' is a reserved keyword in OpenCL C++}}
-  // expected-warning@-2 {{declaration does not declare anything}}
-  int write_only;
-  // expected-error@-1 {{'write_only' is a reserved keyword in OpenCL C++}}
-  // expected-warning@-2 {{declaration does not declare anything}}
-  int __write_only;
-  // expected-error@-1 {{'__write_only' is a reserved keyword in OpenCL C++}}
-  // expected-warning@-2 {{declaration does not declare anything}}
-  int read_write;
-  // expected-error@-1 {{'read_write' is a reserved keyword in OpenCL C++}}
-  // expected-warning@-2 {{declaration does not declare anything}}
-  int __read_write;
-  // expected-error@-1 {{'__read_write' is a reserved keyword in OpenCL C++}}
-  // expected-warning@-2 {{declaration does not declare anything}}
-}
Index: test/SemaOpenCL/invalid-image.cl
===
--- test/SemaOpenCL/invalid-image.cl
+++ test/SemaOpenCL/invalid-image.cl
@@ -1,7 +1,8 @@
+// RUN: %clang_cc1 -verify -cl-std=c++ %s
 // RUN: %clang_cc1 -verify %s
 // RUN: %clang_cc1 -verify -D=ATTR_TEST -fms-compatibility %s
 
-void test1(image1d_t *i) {} // expected-error{{pointer to type '__read_only image1d_t' is invalid in OpenCL}}
+void test1(image1d_t *i) {} // expected-error-re{{pointer to type '{{__generic __read_only|__read_only}} image1d_t' is invalid in OpenCL}}
 
 void test2(image1d_t i) {
   image1d_t ti;// expected-error{{type '__read_only image1d_t' can only be used as a function parameter}}
Index: test/CodeGenOpenCL/images.cl
===
--- test/CodeGenOpenCL/images.cl
+++ test/CodeGenOpenCL/images.cl
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 %s -triple x86_64-unknown-linux-gnu -O0 -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 %s -triple x86_64-unknown-linux-gnu -O0 -emit-llvm -o - -cl-std=c++ | FileCheck %s
 
 __attribute__((overloadable)) void read_image(read_only image1d_t img_ro);
 __attribute__((overloadable)) void read_image(write_only image1d_t img_wo);
Index: lib/Sema/SemaDeclAttr.cpp
===
--- lib/Sema/SemaDeclAttr.cpp
+++ lib/Sema/SemaDeclAttr.cpp
@@ -6289,7 +6289,9 @@
   if (const auto *PDecl = dyn_cast(D)) {
 const Type *DeclTy = PDecl->getType().getCanonicalType().getTypePtr();
 if (AL.getName()->getName().find("read_write") != StringRef::npos) {
-  if (S.getLangOpts().OpenCLVersion < 200 || DeclTy->isPipeType()) {
+  if ((!S.getLangOpts().OpenCLCPlusPlus &&
+   S.getLangOpts().OpenCLVersion < 200) ||
+  DeclTy->isPipeType()) {
 S.Diag(AL.getLoc(), diag::err_opencl_invalid_read_write)
 << AL << PDecl->getType() << DeclTy->isImageType();
 D->setInvalidDecl(true);
Index: lib/Parse/ParseTentative.cpp
===
--- lib/Parse/ParseTentative.cpp
+++ lib/Parse/ParseTentative.cpp
@@ -1410,11 +1410,16 @@
 // cv-qualifier
   case tok::kw_const:
   case tok::kw_volatile:
+// OpenCL address space qualifiers
   case tok::kw___private:
   case tok::kw___local:
   case tok::kw___global:
   case tok::kw___constant:
   case tok::kw___generic:
+// OpenCL access qualifiers
+  case tok::kw___read_only:
+  case tok::kw___write_only:
+  case tok::kw___read_write:
 
 // GNU
   case tok::kw_restrict:
@@ -1600,6 +1605,8 @@
   case tok::kw___float128:
   case tok::kw_void:
   case tok::annot_decltype:
+#define GENERIC_IMAGE_TYPE(ImgType, Id) case tok::kw_##ImgType##_t:
+#include "clang/Basic/OpenCLImageTypes.def"
 if (NextToken().is(tok::l_paren))
   return TPResult::Ambiguous