Ayal created this revision. Ayal added reviewers: asavonic, Anastasia, yaxunl. Herald added subscribers: Naghasan, ldrumm. Herald added a project: All. Ayal requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits.
Structs that contain global or local pointers can be passed as kernel arguments starting OpenCL v2.0 which introduces shared virtual memory. Trying to revive a patch considered in D49723 <https://reviews.llvm.org/D49723> Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D143849 Files: clang/lib/Sema/SemaDecl.cpp clang/test/SemaOpenCL/invalid-kernel-parameters.cl 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}} 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}} 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(),
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits