r354121 - [OpenCL][PR40707] Allow OpenCL C types in C++ mode.
Anastasia Stulova via cfe-commits
cfe-commits at lists.llvm.org
Fri Feb 15 04:07:57 PST 2019
Author: stulova
Date: Fri Feb 15 04:07:57 2019
New Revision: 354121
URL: http://llvm.org/viewvc/llvm-project?rev=354121&view=rev
Log:
[OpenCL][PR40707] Allow OpenCL C types in C++ mode.
Allow all OpenCL types to be parsed in C++ mode.
Modified:
cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
cfe/trunk/include/clang/Basic/TokenKinds.def
cfe/trunk/lib/Parse/ParseDecl.cpp
cfe/trunk/lib/Parse/ParseExprCXX.cpp
cfe/trunk/lib/Parse/ParseTentative.cpp
cfe/trunk/lib/Sema/SemaDeclAttr.cpp
cfe/trunk/test/CodeGenOpenCL/images.cl
cfe/trunk/test/SemaOpenCL/invalid-image.cl
cfe/trunk/test/SemaOpenCLCXX/restricted.cl
Modified: cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td?rev=354121&r1=354120&r2=354121&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td Fri Feb 15 04:07:57 2019
@@ -1133,8 +1133,6 @@ def err_opencl_logical_exclusive_or : Er
// OpenCL C++.
def err_openclcxx_virtual_function : Error<
"virtual functions are not supported in OpenCL C++">;
-def err_openclcxx_reserved : Error<
- "'%0' is a reserved keyword in OpenCL C++">;
// OpenMP support.
def warn_pragma_omp_ignored : Warning<
Modified: cfe/trunk/include/clang/Basic/TokenKinds.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/TokenKinds.def?rev=354121&r1=354120&r2=354121&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/TokenKinds.def (original)
+++ cfe/trunk/include/clang/Basic/TokenKinds.def Fri Feb 15 04:07:57 2019
@@ -550,9 +550,9 @@ ALIAS("read_only", __read_only , KE
ALIAS("write_only", __write_only , KEYOPENCLC | KEYOPENCLCXX)
ALIAS("read_write", __read_write , KEYOPENCLC | KEYOPENCLCXX)
// OpenCL builtins
-KEYWORD(__builtin_astype , KEYOPENCLC)
+KEYWORD(__builtin_astype , KEYOPENCLC | KEYOPENCLCXX)
KEYWORD(vec_step , KEYOPENCLC | KEYALTIVEC | KEYZVECTOR)
-#define GENERIC_IMAGE_TYPE(ImgType, Id) KEYWORD(ImgType##_t, KEYOPENCLC)
+#define GENERIC_IMAGE_TYPE(ImgType, Id) KEYWORD(ImgType##_t, KEYOPENCLC | KEYOPENCLCXX)
#include "clang/Basic/OpenCLImageTypes.def"
// OpenMP Type Traits
Modified: cfe/trunk/lib/Parse/ParseDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=354121&r1=354120&r2=354121&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseDecl.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDecl.cpp Fri Feb 15 04:07:57 2019
@@ -3809,19 +3809,6 @@ void Parser::ParseDeclarationSpecifiers(
getLangOpts());
break;
- // OpenCL access qualifiers:
- case tok::kw___read_only:
- case tok::kw___write_only:
- case tok::kw___read_write:
- // OpenCL C++ 1.0 s2.2: access qualifiers are reserved keywords.
- if (Actions.getLangOpts().OpenCLCPlusPlus) {
- DiagID = diag::err_openclcxx_reserved;
- PrevSpec = Tok.getIdentifierInfo()->getNameStart();
- isInvalid = true;
- }
- ParseOpenCLQualifiers(DS.getAttributes());
- break;
-
// OpenCL address space qualifiers:
case tok::kw___generic:
// generic address space is introduced only in OpenCL v2.0
@@ -3838,6 +3825,10 @@ void Parser::ParseDeclarationSpecifiers(
case tok::kw___global:
case tok::kw___local:
case tok::kw___constant:
+ // OpenCL access qualifiers:
+ case tok::kw___read_only:
+ case tok::kw___write_only:
+ case tok::kw___read_write:
ParseOpenCLQualifiers(DS.getAttributes());
break;
Modified: cfe/trunk/lib/Parse/ParseExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseExprCXX.cpp?rev=354121&r1=354120&r2=354121&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseExprCXX.cpp (original)
+++ cfe/trunk/lib/Parse/ParseExprCXX.cpp Fri Feb 15 04:07:57 2019
@@ -1998,6 +1998,13 @@ void Parser::ParseCXXSimpleTypeSpecifier
case tok::kw_bool:
DS.SetTypeSpecType(DeclSpec::TST_bool, Loc, PrevSpec, DiagID, Policy);
break;
+#define GENERIC_IMAGE_TYPE(ImgType, Id) \
+ case tok::kw_##ImgType##_t: \
+ DS.SetTypeSpecType(DeclSpec::TST_##ImgType##_t, Loc, PrevSpec, DiagID, \
+ Policy); \
+ break;
+#include "clang/Basic/OpenCLImageTypes.def"
+
case tok::annot_decltype:
case tok::kw_decltype:
DS.SetRangeEnd(ParseDecltypeSpecifier(DS));
Modified: cfe/trunk/lib/Parse/ParseTentative.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseTentative.cpp?rev=354121&r1=354120&r2=354121&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseTentative.cpp (original)
+++ cfe/trunk/lib/Parse/ParseTentative.cpp Fri Feb 15 04:07:57 2019
@@ -1410,11 +1410,16 @@ Parser::isCXXDeclarationSpecifier(Parser
// 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 @@ Parser::isCXXDeclarationSpecifier(Parser
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;
@@ -1693,6 +1700,8 @@ bool Parser::isCXXDeclarationSpecifierAT
case tok::kw_void:
case tok::kw___unknown_anytype:
case tok::kw___auto_type:
+#define GENERIC_IMAGE_TYPE(ImgType, Id) case tok::kw_##ImgType##_t:
+#include "clang/Basic/OpenCLImageTypes.def"
return true;
case tok::kw_auto:
Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=354121&r1=354120&r2=354121&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Fri Feb 15 04:07:57 2019
@@ -6324,7 +6324,9 @@ static void handleOpenCLAccessAttr(Sema
if (const auto *PDecl = dyn_cast<ParmVarDecl>(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);
Modified: cfe/trunk/test/CodeGenOpenCL/images.cl
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenOpenCL/images.cl?rev=354121&r1=354120&r2=354121&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenOpenCL/images.cl (original)
+++ cfe/trunk/test/CodeGenOpenCL/images.cl Fri Feb 15 04:07:57 2019
@@ -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);
Modified: cfe/trunk/test/SemaOpenCL/invalid-image.cl
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaOpenCL/invalid-image.cl?rev=354121&r1=354120&r2=354121&view=diff
==============================================================================
--- cfe/trunk/test/SemaOpenCL/invalid-image.cl (original)
+++ cfe/trunk/test/SemaOpenCL/invalid-image.cl Fri Feb 15 04:07:57 2019
@@ -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}}
Modified: cfe/trunk/test/SemaOpenCLCXX/restricted.cl
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaOpenCLCXX/restricted.cl?rev=354121&r1=354120&r2=354121&view=diff
==============================================================================
--- cfe/trunk/test/SemaOpenCLCXX/restricted.cl (original)
+++ cfe/trunk/test/SemaOpenCLCXX/restricted.cl Fri Feb 15 04:07:57 2019
@@ -39,25 +39,3 @@ kernel void test_storage_classes() {
thread_local int y;
// expected-error at -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 at -1 {{'read_only' is a reserved keyword in OpenCL C++}}
- // expected-warning at -2 {{declaration does not declare anything}}
- int __read_only;
- // expected-error at -1 {{'__read_only' is a reserved keyword in OpenCL C++}}
- // expected-warning at -2 {{declaration does not declare anything}}
- int write_only;
- // expected-error at -1 {{'write_only' is a reserved keyword in OpenCL C++}}
- // expected-warning at -2 {{declaration does not declare anything}}
- int __write_only;
- // expected-error at -1 {{'__write_only' is a reserved keyword in OpenCL C++}}
- // expected-warning at -2 {{declaration does not declare anything}}
- int read_write;
- // expected-error at -1 {{'read_write' is a reserved keyword in OpenCL C++}}
- // expected-warning at -2 {{declaration does not declare anything}}
- int __read_write;
- // expected-error at -1 {{'__read_write' is a reserved keyword in OpenCL C++}}
- // expected-warning at -2 {{declaration does not declare anything}}
-}
More information about the cfe-commits
mailing list