[PATCH] D143849: [Clang][OpenCL] Allow pointers in structs as kernel arguments from 2.0
Ayal Zaks via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Feb 14 07:13:20 PST 2023
Ayal updated this revision to Diff 497317.
Ayal added a comment.
Use `-verify=expected,ocl12` instead of #ifdef'ing the test to check diagnostics emitted for 1.2 but not emitted for 2.0.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D143849/new/
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
@@ -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 at -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}}
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;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D143849.497317.patch
Type: text/x-patch
Size: 3820 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230214/ba30e0cc/attachment.bin>
More information about the cfe-commits
mailing list