Index: clang/lib/Sema/SemaDecl.cpp =================================================================== --- clang/lib/Sema/SemaDecl.cpp +++ clang/lib/Sema/SemaDecl.cpp @@ -9489,7 +9489,12 @@ // OpenCL v1.2 s6.9.p: // Arguments to kernel functions that are declared to be a struct or union // do not allow OpenCL objects to be passed as elements of the struct or - // union. + // union. This restriction was lifted in OpenCL v2.0 with the introduction + // of SVM. + if (S.getLangOpts().getOpenCLCompatibleVersion() > 120 && + (ParamType == PtrKernelParam || ParamType == PtrPtrKernelParam)) + continue; + if (ParamType == PtrKernelParam || ParamType == PtrPtrKernelParam || ParamType == InvalidAddrSpacePtrKernelParam) { S.Diag(Param->getLocation(), Index: clang/test/SemaOpenCL/invalid-kernel-parameters.cl =================================================================== --- clang/test/SemaOpenCL/invalid-kernel-parameters.cl +++ clang/test/SemaOpenCL/invalid-kernel-parameters.cl @@ -87,6 +87,7 @@ +#if __OPENCL_C_VERSION__ <= CL_VERSION_1_2 typedef struct FooImage2D // expected-note{{within field of type 'FooImage2D' declared here}} { // TODO: Clean up needed - we don't really need to check for image, event, etc @@ -96,6 +97,7 @@ } FooImage2D; kernel void image_in_struct_arg(FooImage2D arg) { } // expected-error{{struct kernel parameters may not contain pointers}} +#endif typedef struct Foo // expected-note{{within field of type 'Foo' declared here}} { @@ -104,6 +106,15 @@ kernel void pointer_in_struct_arg(Foo arg) { } // expected-error{{struct kernel parameters may not contain pointers}} +#if __OPENCL_C_VERSION__ <= CL_VERSION_1_2 +typedef struct FooGlobal // expected-note{{within field of type 'FooGlobal' declared here}} +{ + global int* ptrField; // expected-note{{field of illegal pointer type '__global int *' declared here}} +} FooGlobal; + +kernel void global_pointer_in_struct_arg(FooGlobal arg) { } // expected-error{{struct kernel parameters may not contain pointers}} +#endif + typedef union FooUnion // expected-note{{within field of type 'FooUnion' declared here}} { int* ptrField; // expected-note-re{{field of illegal pointer type '__{{private|generic}} int *' declared here}}