diff options
author | Tanya Lattner <tonic@nondot.org> | 2013-04-05 20:14:50 +0000 |
---|---|---|
committer | Tanya Lattner <tonic@nondot.org> | 2013-04-05 20:14:50 +0000 |
commit | 713eef4f7ca2bb26a1a1d39713ac167a397b65b3 (patch) | |
tree | f9ff613110e298d0e35f617b655d8babec6504c3 | |
parent | b8055cbc9dde9d1386d85f1e6f0876cef1646c87 (diff) | |
download | bcm5719-llvm-713eef4f7ca2bb26a1a1d39713ac167a397b65b3.tar.gz bcm5719-llvm-713eef4f7ca2bb26a1a1d39713ac167a397b65b3.zip |
Add an error to check that all program scope variables are in the constant address space in OpenCL.
llvm-svn: 178906
-rw-r--r-- | clang/include/clang/Basic/DiagnosticSemaKinds.td | 4 | ||||
-rw-r--r-- | clang/lib/Sema/SemaDecl.cpp | 10 | ||||
-rw-r--r-- | clang/test/SemaOpenCL/event_t.cl | 2 | ||||
-rw-r--r-- | clang/test/SemaOpenCL/storageclass.cl | 2 | ||||
-rw-r--r-- | clang/unittests/AST/SourceLocationTest.cpp | 8 |
5 files changed, 20 insertions, 6 deletions
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index c4815cd7ea6..fe8233b053e 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -6205,7 +6205,9 @@ def err_sampler_argument_required : Error< "sampler_t variable required - got %0">; def err_wrong_sampler_addressspace: Error< "sampler type cannot be used with the __local and __global address space qualifiers">; - +def err_opencl_global_invalid_addr_space : Error< + "global variables must have a constant address space qualifier">; + // OpenMP support. def err_omp_expected_var_arg_suggest : Error< "%0 is not a global variable, static local variable or static data member%select{|; did you mean %2?}1">; diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index adf3505633b..e9116bc91a5 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -5177,6 +5177,16 @@ bool Sema::CheckVariableDeclaration(VarDecl *NewVD, return false; } + // OpenCL v1.2 s6.5 - All program scope variables must be declared in the + // __constant address space. + if (getLangOpts().OpenCL && NewVD->isFileVarDecl() + && T.getAddressSpace() != LangAS::opencl_constant + && !T->isSamplerT()){ + Diag(NewVD->getLocation(), diag::err_opencl_global_invalid_addr_space); + NewVD->setInvalidDecl(); + return false; + } + // OpenCL v1.2 s6.8 -- The static qualifier is valid only in program // scope. if ((getLangOpts().OpenCLVersion >= 120) diff --git a/clang/test/SemaOpenCL/event_t.cl b/clang/test/SemaOpenCL/event_t.cl index 57a0981cf13..06197d0c179 100644 --- a/clang/test/SemaOpenCL/event_t.cl +++ b/clang/test/SemaOpenCL/event_t.cl @@ -2,7 +2,7 @@ event_t glb_evt; // expected-error {{the event_t type cannot be used to declare a program scope variable}} -struct evt_s { +constant struct evt_s { event_t evt; // expected-error {{the event_t type cannot be used to declare a structure or union field}} } evt_str; diff --git a/clang/test/SemaOpenCL/storageclass.cl b/clang/test/SemaOpenCL/storageclass.cl index fdfe1346218..d2678f2010d 100644 --- a/clang/test/SemaOpenCL/storageclass.cl +++ b/clang/test/SemaOpenCL/storageclass.cl @@ -2,6 +2,8 @@ static constant int A = 0; +int X = 0; // expected-error{{global variables must have a constant address space qualifier}} + // static is not allowed at local scope. void kernel foo() { static int X = 5; // expected-error{{variables in function scope cannot be declared static}} diff --git a/clang/unittests/AST/SourceLocationTest.cpp b/clang/unittests/AST/SourceLocationTest.cpp index b8d8b02d031..f6c0edc9271 100644 --- a/clang/unittests/AST/SourceLocationTest.cpp +++ b/clang/unittests/AST/SourceLocationTest.cpp @@ -132,10 +132,10 @@ TEST(CompoundLiteralExpr, CompoundVectorLiteralRange) { TEST(CompoundLiteralExpr, ParensCompoundVectorLiteralRange) { RangeVerifier<CompoundLiteralExpr> Verifier; - Verifier.expectRange(2, 11, 2, 22); + Verifier.expectRange(2, 20, 2, 31); EXPECT_TRUE(Verifier.match( "typedef int int2 __attribute__((ext_vector_type(2)));\n" - "int2 i2 = (int2)(1, 2);", + "constant int2 i2 = (int2)(1, 2);", compoundLiteralExpr(), Lang_OpenCL)); } @@ -149,10 +149,10 @@ TEST(InitListExpr, VectorLiteralListBraceRange) { TEST(InitListExpr, VectorLiteralInitListParens) { RangeVerifier<InitListExpr> Verifier; - Verifier.expectRange(2, 17, 2, 22); + Verifier.expectRange(2, 26, 2, 31); EXPECT_TRUE(Verifier.match( "typedef int int2 __attribute__((ext_vector_type(2)));\n" - "int2 i2 = (int2)(1, 2);", initListExpr(), Lang_OpenCL)); + "constant int2 i2 = (int2)(1, 2);", initListExpr(), Lang_OpenCL)); } } // end namespace ast_matchers |