diff options
author | Matt Arsenault <Matthew.Arsenault@amd.com> | 2013-07-23 01:23:36 +0000 |
---|---|---|
committer | Matt Arsenault <Matthew.Arsenault@amd.com> | 2013-07-23 01:23:36 +0000 |
commit | e6c8afcf449728a5096834393fc4a1acfad9b49d (patch) | |
tree | b77281779c78ed68814b4d7db0d6abf887fee612 /test/SemaOpenCL/invalid-kernel-parameters.cl | |
parent | 17b3c0dd701df22eced2e90bba752fdb46abae6a (diff) | |
download | clang-e6c8afcf449728a5096834393fc4a1acfad9b49d.tar.gz |
Error on more illegal kernel argument types for OpenCL
bool, half, pointers and structs / unions containing any
of these are not allowed. Does not yet reject size_t and
related integer types that are also disallowed.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@186908 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/SemaOpenCL/invalid-kernel-parameters.cl')
-rw-r--r-- | test/SemaOpenCL/invalid-kernel-parameters.cl | 132 |
1 files changed, 132 insertions, 0 deletions
diff --git a/test/SemaOpenCL/invalid-kernel-parameters.cl b/test/SemaOpenCL/invalid-kernel-parameters.cl new file mode 100644 index 0000000000..de32eae882 --- /dev/null +++ b/test/SemaOpenCL/invalid-kernel-parameters.cl @@ -0,0 +1,132 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +#pragma OPENCL EXTENSION cl_khr_fp16 : enable + + +// Disallowed: parameters with type +// bool, half, size_t, ptrdiff_t, intptr_t, and uintptr_t +// or a struct / union with any of these types in them + +// TODO: Ban int types, size_t, ptrdiff_t ... + +kernel void bool_arg(bool x) { } // expected-error{{'bool' cannot be used as the type of a kernel parameter}} + +kernel void half_arg(half x) { } // expected-error{{'half' cannot be used as the type of a kernel parameter}} + +typedef struct ContainsBool // expected-note{{within field of type 'ContainsBool' declared here}} +{ + bool x; // expected-note{{field of illegal type 'bool' declared here}} +} ContainsBool; + +kernel void bool_in_struct_arg(ContainsBool x) { } // expected-error{{'ContainsBool' (aka 'struct ContainsBool') cannot be used as the type of a kernel parameter}} + + + +typedef struct FooImage2D // expected-note{{within field of type 'FooImage2D' declared here}} +{ + image2d_t imageField; // expected-note{{field of illegal type 'image2d_t' declared here}} +} FooImage2D; + +kernel void image_in_struct_arg(FooImage2D arg) { } // expected-error{{struct kernel parameters may not contain pointers}} + +typedef struct Foo // expected-note{{within field of type 'Foo' declared here}} +{ + int* ptrField; // expected-note{{field of illegal pointer type 'int *' declared here}} +} Foo; + +kernel void pointer_in_struct_arg(Foo arg) { } // expected-error{{struct kernel parameters may not contain pointers}} + +typedef union FooUnion // expected-note{{within field of type 'FooUnion' declared here}} +{ + int* ptrField; // expected-note{{field of illegal pointer type 'int *' declared here}} +} FooUnion; + +kernel void pointer_in_union_arg(FooUnion arg) { }// expected-error{{union kernel parameters may not contain pointers}} + +typedef struct NestedPointer // expected-note 2 {{within field of type 'NestedPointer' declared here}} +{ + int x; + struct InnerNestedPointer + { + int* ptrField; // expected-note 3 {{field of illegal pointer type 'int *' declared here}} + } inner; // expected-note 3 {{within field of type 'struct InnerNestedPointer' declared here}} +} NestedPointer; + +kernel void pointer_in_nested_struct_arg(NestedPointer arg) { }// expected-error{{struct kernel parameters may not contain pointers}} + +struct NestedPointerComplex // expected-note{{within field of type 'NestedPointerComplex' declared here}} +{ + int foo; + float bar; + + struct InnerNestedPointerComplex + { + int innerFoo; + int* innerPtrField; // expected-note{{field of illegal pointer type 'int *' declared here}} + } inner; // expected-note{{within field of type 'struct InnerNestedPointerComplex' declared here}} + + float y; + float z[4]; +}; + +kernel void pointer_in_nested_struct_arg_complex(struct NestedPointerComplex arg) { }// expected-error{{struct kernel parameters may not contain pointers}} + +typedef struct NestedBool // expected-note 2 {{within field of type 'NestedBool' declared here}} +{ + int x; + struct InnerNestedBool + { + bool boolField; // expected-note 2 {{field of illegal type 'bool' declared here}} + } inner; // expected-note 2 {{within field of type 'struct InnerNestedBool' declared here}} +} NestedBool; + +kernel void bool_in_nested_struct_arg(NestedBool arg) { } // expected-error{{'NestedBool' (aka 'struct NestedBool') cannot be used as the type of a kernel parameter}} + +// Warning emitted again for argument used in other kernel +kernel void bool_in_nested_struct_arg_again(NestedBool arg) { } // expected-error{{'NestedBool' (aka 'struct NestedBool') cannot be used as the type of a kernel parameter}} + + +// Check for note with a struct not defined inside the struct +typedef struct NestedBool2Inner +{ + bool boolField; // expected-note{{field of illegal type 'bool' declared here}} +} NestedBool2Inner; + +typedef struct NestedBool2 // expected-note{{within field of type 'NestedBool2' declared here}} +{ + int x; + NestedBool2Inner inner; // expected-note{{within field of type 'NestedBool2Inner' (aka 'struct NestedBool2Inner') declared here}} +} NestedBool2; + +kernel void bool_in_nested_struct_2_arg(NestedBool2 arg) { } // expected-error{{'NestedBool2' (aka 'struct NestedBool2') cannot be used as the type of a kernel parameter}} + + +struct InnerInner +{ + int* foo; + bool x; +}; + +struct Valid +{ + float c; + float d; +}; + +struct Inner +{ + struct Valid v; + struct InnerInner a; + struct Valid g; + struct InnerInner b; +}; + +struct AlsoUser // expected-note{{within field of type 'AlsoUser' declared here}} +{ + float x; + struct Valid valid1; + struct Valid valid2; + struct NestedPointer aaaa; // expected-note{{within field of type 'struct NestedPointer' declared here}} +}; + +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}} |