[PATCH] D49723: [OpenCL] Check for invalid kernel arguments in array types
Andrew Savonichev via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Jul 24 04:34:05 PDT 2018
asavonic created this revision.
Herald added subscribers: cfe-commits, Anastasia, yaxunl.
OpenCL specification forbids use of several types as kernel
arguments. This patch improves existing diagnostic to look through
arrays.
Repository:
rC Clang
https://reviews.llvm.org/D49723
Files:
lib/Sema/SemaDecl.cpp
test/SemaOpenCL/invalid-kernel-parameters.cl
Index: test/SemaOpenCL/invalid-kernel-parameters.cl
===================================================================
--- test/SemaOpenCL/invalid-kernel-parameters.cl
+++ test/SemaOpenCL/invalid-kernel-parameters.cl
@@ -136,3 +136,9 @@
};
kernel void pointer_in_nested_struct_arg_2(struct Valid valid, struct NestedPointer arg, struct AlsoUser also) { } // expected-error 2 {{struct kernel parameters may not contain pointers}}
+
+struct ArrayOfPtr // expected-note{{within field of type 'ArrayOfPtr' declared here}}
+{
+ float *arr[3]; // expected-note{{field of illegal type 'float *[3]' declared here}}
+};
+kernel void array_of_ptr(struct ArrayOfPtr arr) {} // expected-error{{struct kernel parameters may not contain pointers}}
Index: lib/Sema/SemaDecl.cpp
===================================================================
--- lib/Sema/SemaDecl.cpp
+++ lib/Sema/SemaDecl.cpp
@@ -8079,6 +8079,15 @@
if (PT->isRecordType())
return RecordKernelParam;
+ // Look into an array argument to check if it has a forbidden type.
+ if (PT->isArrayType()) {
+ const Type *UnderlyingTy = PT->getPointeeOrArrayElementType();
+ // Call ourself to check an underlying type of an array. Since the
+ // getPointeeOrArrayElementType returns an innermost type which is not an
+ // array, this recusive call only happens once.
+ return getOpenCLKernelParameterType(S, QualType(UnderlyingTy, 0));
+ }
+
return ValidKernelParam;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D49723.157002.patch
Type: text/x-patch
Size: 1455 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180724/9359f817/attachment.bin>
More information about the cfe-commits
mailing list