Index: clang/lib/Sema/SemaDecl.cpp =================================================================== --- clang/lib/Sema/SemaDecl.cpp +++ clang/lib/Sema/SemaDecl.cpp @@ -9489,13 +9489,18 @@ // 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. - if (ParamType == PtrKernelParam || ParamType == PtrPtrKernelParam || - ParamType == InvalidAddrSpacePtrKernelParam) { + // union. This restriction was lifted in OpenCL v2.0 with the introduction + // of SVM. + if (ParamType == InvalidAddrSpacePtrKernelParam || + ((ParamType == PtrKernelParam || ParamType == PtrPtrKernelParam) && + S.getLangOpts().getOpenCLCompatibleVersion() <= 120)) { S.Diag(Param->getLocation(), diag::err_record_with_pointers_kernel_param) << PT->isUnionType() << PT; + } else if (ParamType == PtrKernelParam || ParamType == PtrPtrKernelParam) { + // and OpenCL version is at-least 2.0, so these types are allowed. + continue; } else { S.Diag(Param->getLocation(), diag::err_bad_kernel_param_type) << PT; } Index: clang/test/SemaOpenCL/invalid-kernel-parameters.cl =================================================================== --- clang/test/SemaOpenCL/invalid-kernel-parameters.cl +++ clang/test/SemaOpenCL/invalid-kernel-parameters.cl @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s -triple spir-unknown-unknown +// RUN: %clang_cc1 -fsyntax-only -verify=expected,ocl12 %s -triple spir-unknown-unknown // RUN: %clang_cc1 -fsyntax-only -verify %s -triple spir-unknown-unknown -cl-std=CL2.0 kernel void half_arg(half x) { } // expected-error{{declaring function parameter of type '__private half' is not allowed; did you forget * ?}} @@ -87,15 +87,16 @@ -typedef struct FooImage2D // expected-note{{within field of type 'FooImage2D' declared here}} +typedef struct FooImage2D // ocl12-note{{within field of type 'FooImage2D' declared here}} { // TODO: Clean up needed - we don't really need to check for image, event, etc // as a note here any longer. // They are diagnosed as an error for all struct fields (OpenCL v1.2 s6.9b,r). - image2d_t imageField; // expected-note{{field of illegal type '__read_only image2d_t' declared here}} expected-error{{the '__read_only image2d_t' type cannot be used to declare a structure or union field}} + image2d_t imageField; // ocl12-note{{field of illegal type '__read_only image2d_t' declared here}} + // expected-error@-1{{the '__read_only image2d_t' type cannot be used to declare a structure or union field}} } FooImage2D; -kernel void image_in_struct_arg(FooImage2D arg) { } // expected-error{{struct kernel parameters may not contain pointers}} +kernel void image_in_struct_arg(FooImage2D arg) { } // ocl12-error{{struct kernel parameters may not contain pointers}} typedef struct Foo // expected-note{{within field of type 'Foo' declared here}} { @@ -104,6 +105,13 @@ kernel void pointer_in_struct_arg(Foo arg) { } // expected-error{{struct kernel parameters may not contain pointers}} +typedef struct FooGlobal // ocl12-note{{within field of type 'FooGlobal' declared here}} +{ + global int* ptrField; // ocl12-note{{field of illegal pointer type '__global int *' declared here}} +} FooGlobal; + +kernel void global_pointer_in_struct_arg(FooGlobal arg) { } // ocl12-error{{struct kernel parameters may not contain pointers}} + 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}}