r178906 - Add an error to check that all program scope variables are in the constant address space in OpenCL.
Tanya Lattner
tonic at nondot.org
Fri Apr 5 13:14:50 PDT 2013
Author: tbrethou
Date: Fri Apr 5 15:14:50 2013
New Revision: 178906
URL: http://llvm.org/viewvc/llvm-project?rev=178906&view=rev
Log:
Add an error to check that all program scope variables are in the constant address space in OpenCL.
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/test/SemaOpenCL/event_t.cl
cfe/trunk/test/SemaOpenCL/storageclass.cl
cfe/trunk/unittests/AST/SourceLocationTest.cpp
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=178906&r1=178905&r2=178906&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Fri Apr 5 15:14:50 2013
@@ -6205,7 +6205,9 @@ def err_sampler_argument_required : Erro
"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">;
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=178906&r1=178905&r2=178906&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Fri Apr 5 15:14:50 2013
@@ -5177,6 +5177,16 @@ bool Sema::CheckVariableDeclaration(VarD
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)
Modified: cfe/trunk/test/SemaOpenCL/event_t.cl
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaOpenCL/event_t.cl?rev=178906&r1=178905&r2=178906&view=diff
==============================================================================
--- cfe/trunk/test/SemaOpenCL/event_t.cl (original)
+++ cfe/trunk/test/SemaOpenCL/event_t.cl Fri Apr 5 15:14:50 2013
@@ -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;
Modified: cfe/trunk/test/SemaOpenCL/storageclass.cl
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaOpenCL/storageclass.cl?rev=178906&r1=178905&r2=178906&view=diff
==============================================================================
--- cfe/trunk/test/SemaOpenCL/storageclass.cl (original)
+++ cfe/trunk/test/SemaOpenCL/storageclass.cl Fri Apr 5 15:14:50 2013
@@ -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}}
Modified: cfe/trunk/unittests/AST/SourceLocationTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/AST/SourceLocationTest.cpp?rev=178906&r1=178905&r2=178906&view=diff
==============================================================================
--- cfe/trunk/unittests/AST/SourceLocationTest.cpp (original)
+++ cfe/trunk/unittests/AST/SourceLocationTest.cpp Fri Apr 5 15:14:50 2013
@@ -132,10 +132,10 @@ TEST(CompoundLiteralExpr, CompoundVector
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, VectorLiteralListBrac
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
More information about the cfe-commits
mailing list