"kernel parameter cannot be declared as a pointer to a pointer">;
def err_opencl_private_ptr_kernel_param : Error<
"kernel parameter cannot be declared as a pointer to the __private address space">;
+def err_opencl_non_kernel_variable : Error<
+ "non-kernel function variable cannot be declared in %0 address space">;
def err_static_function_scope : Error<
"variables in function scope cannot be declared static">;
def err_opencl_bitfields : Error<
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">;
+ "program scope variable must reside in %0 address space">;
def err_opencl_no_main : Error<"%select{function|kernel}0 cannot be called 'main'">;
def err_opencl_kernel_attr :
Error<"attribute %0 can only be applied to a kernel function">;
}
if (getLangOpts().OpenCL) {
- // Set up the special work-group-local storage class for variables in the
- // OpenCL __local address space.
- if (R.getAddressSpace() == LangAS::opencl_local) {
- SC = SC_OpenCLWorkGroupLocal;
- }
-
// OpenCL v1.2 s6.9.b p4:
// The sampler type cannot be used with the __local and __global address
// space qualifiers.
break;
case SC_PrivateExtern:
llvm_unreachable("C storage class in c++!");
- case SC_OpenCLWorkGroupLocal:
- llvm_unreachable("OpenCL storage class in c++!");
}
}
case SC_Static:
case SC_Extern:
case SC_PrivateExtern:
- case SC_OpenCLWorkGroupLocal:
break;
}
} else if (SC == SC_Register) {
// This includes arrays of objects with address space qualifiers, but not
// automatic variables that point to other address spaces.
// ISO/IEC TR 18037 S5.1.2
- if (NewVD->hasLocalStorage() && T.getAddressSpace() != 0) {
+ if (!getLangOpts().OpenCL
+ && NewVD->hasLocalStorage() && T.getAddressSpace() != 0) {
Diag(NewVD->getLocation(), diag::err_as_qualified_auto_decl);
NewVD->setInvalidDecl();
return;
}
- // 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;
- }
-
// OpenCL v1.2 s6.8 -- The static qualifier is valid only in program
// scope.
- if ((getLangOpts().OpenCLVersion >= 120)
- && NewVD->isStaticLocal()) {
+ if (getLangOpts().OpenCLVersion == 120 &&
+ !getOpenCLOptions().cl_clang_storage_class_specifiers &&
+ NewVD->isStaticLocal()) {
Diag(NewVD->getLocation(), diag::err_static_function_scope);
NewVD->setInvalidDecl();
return;
}
+ // OpenCL v1.2 s6.5 - All program scope variables must be declared in the
+ // __constant address space.
+ // OpenCL v2.0 s6.5.1 - Variables defined at program scope and static
+ // variables inside a function can also be declared in the global
+ // address space.
+ if (getLangOpts().OpenCL) {
+ if (NewVD->isFileVarDecl()) {
+ if (!T->isSamplerT() &&
+ !(T.getAddressSpace() == LangAS::opencl_constant ||
+ (T.getAddressSpace() == LangAS::opencl_global &&
+ getLangOpts().OpenCLVersion == 200))) {
+ if (getLangOpts().OpenCLVersion == 200)
+ Diag(NewVD->getLocation(), diag::err_opencl_global_invalid_addr_space)
+ << "global or constant";
+ else
+ Diag(NewVD->getLocation(), diag::err_opencl_global_invalid_addr_space)
+ << "constant";
+ NewVD->setInvalidDecl();
+ return;
+ }
+ } else {
+ // OpenCL v2.0 s6.5.1 - Variables defined at program scope and static
+ // variables inside a function can also be declared in the global
+ // address space.
+ if (NewVD->isStaticLocal() &&
+ !(T.getAddressSpace() == LangAS::opencl_constant ||
+ (T.getAddressSpace() == LangAS::opencl_global &&
+ getLangOpts().OpenCLVersion == 200))) {
+ if (getLangOpts().OpenCLVersion == 200)
+ Diag(NewVD->getLocation(), diag::err_opencl_global_invalid_addr_space)
+ << "global or constant";
+ else
+ Diag(NewVD->getLocation(), diag::err_opencl_global_invalid_addr_space)
+ << "constant";
+ NewVD->setInvalidDecl();
+ return;
+ }
+ // OpenCL v1.1 s6.5.2 and s6.5.3 no local or constant variables
+ // in functions.
+ if (T.getAddressSpace() == LangAS::opencl_constant ||
+ T.getAddressSpace() == LangAS::opencl_local) {
+ FunctionDecl *FD = getCurFunctionDecl();
+ if (FD && !FD->hasAttr<OpenCLKernelAttr>()) {
+ if (T.getAddressSpace() == LangAS::opencl_constant)
+ Diag(NewVD->getLocation(), diag::err_opencl_non_kernel_variable)
+ << "constant";
+ else
+ Diag(NewVD->getLocation(), diag::err_opencl_non_kernel_variable)
+ << "local";
+ NewVD->setInvalidDecl();
+ return;
+ }
+ }
+ }
+ }
+
if (NewVD->hasLocalStorage() && T.isObjCGCWeak()
&& !NewVD->hasAttr<BlocksAttr>()) {
if (getLangOpts().getGC() != LangOptions::NonGC)
// OpenCL 1.1 6.5.2: "Variables allocated in the __local address space inside
// a kernel function cannot be initialized."
- if (VDecl->getStorageClass() == SC_OpenCLWorkGroupLocal) {
+ if (VDecl->getType().getAddressSpace() == LangAS::opencl_local) {
Diag(VDecl->getLocation(), diag::err_local_cant_init);
VDecl->setInvalidDecl();
return;
case SC_Register:
Error = 4;
break;
- case SC_OpenCLWorkGroupLocal:
- llvm_unreachable("Unexpected storage class");
}
if (Error != -1) {
Diag(VD->getOuterLocStart(), diag::err_for_range_storage_class)
// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL1.2
-static constant int A = 0;
+static constant int G1 = 0;
+constant int G2 = 0;
+int G3 = 0; // expected-error{{program scope variable must reside in constant address space}}
+global int G4 = 0; // expected-error{{program scope variable must reside in constant address space}}
-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}}
- auto int Y = 7; // expected-error{{OpenCL does not support the 'auto' storage class specifier}}
+ // static is not allowed at local scope before CL2.0
+ static int S1 = 5; // expected-error{{variables in function scope cannot be declared static}}
+ static constant int S2 = 5; // expected-error{{variables in function scope cannot be declared static}}
+
+ constant int L1 = 0;
+ local int L2;
+
+ auto int L3 = 7; // expected-error{{OpenCL does not support the 'auto' storage class specifier}}
}
static void kernel bar() { // expected-error{{kernel functions cannot be declared static}}
}
+
+void f() {
+ constant int L1 = 0; // expected-error{{non-kernel function variable cannot be declared in constant address space}}
+ local int L2; // expected-error{{non-kernel function variable cannot be declared in local address space}}
+ {
+ constant int L1 = 0; // expected-error{{non-kernel function variable cannot be declared in constant address space}}
+ local int L2; // expected-error{{non-kernel function variable cannot be declared in local address space}}
+ }
+}