Yaxun Liu | 39cf40f | 2016-05-16 17:06:34 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s -triple spir-unknown-unknown |
Matt Arsenault | efb3819 | 2013-07-23 01:23:36 +0000 | [diff] [blame] | 2 | |
Yaxun Liu | 042acb2 | 2016-09-19 17:11:22 +0000 | [diff] [blame] | 3 | kernel void half_arg(half x) { } // expected-error{{declaring function parameter of type 'half' is not allowed; did you forget * ?}} |
| 4 | |
Matt Arsenault | efb3819 | 2013-07-23 01:23:36 +0000 | [diff] [blame] | 5 | #pragma OPENCL EXTENSION cl_khr_fp16 : enable |
| 6 | |
| 7 | |
| 8 | // Disallowed: parameters with type |
| 9 | // bool, half, size_t, ptrdiff_t, intptr_t, and uintptr_t |
| 10 | // or a struct / union with any of these types in them |
| 11 | |
| 12 | // TODO: Ban int types, size_t, ptrdiff_t ... |
| 13 | |
| 14 | kernel void bool_arg(bool x) { } // expected-error{{'bool' cannot be used as the type of a kernel parameter}} |
| 15 | |
Yaxun Liu | 042acb2 | 2016-09-19 17:11:22 +0000 | [diff] [blame] | 16 | // half kernel argument is allowed when cl_khr_fp16 is enabled. |
| 17 | kernel void half_arg(half x) { } |
Matt Arsenault | efb3819 | 2013-07-23 01:23:36 +0000 | [diff] [blame] | 18 | |
| 19 | typedef struct ContainsBool // expected-note{{within field of type 'ContainsBool' declared here}} |
| 20 | { |
| 21 | bool x; // expected-note{{field of illegal type 'bool' declared here}} |
| 22 | } ContainsBool; |
| 23 | |
| 24 | kernel void bool_in_struct_arg(ContainsBool x) { } // expected-error{{'ContainsBool' (aka 'struct ContainsBool') cannot be used as the type of a kernel parameter}} |
| 25 | |
| 26 | |
| 27 | |
| 28 | typedef struct FooImage2D // expected-note{{within field of type 'FooImage2D' declared here}} |
| 29 | { |
Anastasia Stulova | 1f95cc0 | 2016-03-03 13:33:19 +0000 | [diff] [blame] | 30 | // TODO: Clean up needed - we don't really need to check for image, event, etc |
| 31 | // as a note here any longer. |
| 32 | // They are diagnosed as an error for all struct fields (OpenCL v1.2 s6.9b,r). |
Alexey Bader | 954ba21 | 2016-04-08 13:40:33 +0000 | [diff] [blame] | 33 | 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}} |
Matt Arsenault | efb3819 | 2013-07-23 01:23:36 +0000 | [diff] [blame] | 34 | } FooImage2D; |
| 35 | |
| 36 | kernel void image_in_struct_arg(FooImage2D arg) { } // expected-error{{struct kernel parameters may not contain pointers}} |
| 37 | |
| 38 | typedef struct Foo // expected-note{{within field of type 'Foo' declared here}} |
| 39 | { |
| 40 | int* ptrField; // expected-note{{field of illegal pointer type 'int *' declared here}} |
| 41 | } Foo; |
| 42 | |
| 43 | kernel void pointer_in_struct_arg(Foo arg) { } // expected-error{{struct kernel parameters may not contain pointers}} |
| 44 | |
| 45 | typedef union FooUnion // expected-note{{within field of type 'FooUnion' declared here}} |
| 46 | { |
| 47 | int* ptrField; // expected-note{{field of illegal pointer type 'int *' declared here}} |
| 48 | } FooUnion; |
| 49 | |
| 50 | kernel void pointer_in_union_arg(FooUnion arg) { }// expected-error{{union kernel parameters may not contain pointers}} |
| 51 | |
| 52 | typedef struct NestedPointer // expected-note 2 {{within field of type 'NestedPointer' declared here}} |
| 53 | { |
| 54 | int x; |
| 55 | struct InnerNestedPointer |
| 56 | { |
| 57 | int* ptrField; // expected-note 3 {{field of illegal pointer type 'int *' declared here}} |
| 58 | } inner; // expected-note 3 {{within field of type 'struct InnerNestedPointer' declared here}} |
| 59 | } NestedPointer; |
| 60 | |
| 61 | kernel void pointer_in_nested_struct_arg(NestedPointer arg) { }// expected-error{{struct kernel parameters may not contain pointers}} |
| 62 | |
| 63 | struct NestedPointerComplex // expected-note{{within field of type 'NestedPointerComplex' declared here}} |
| 64 | { |
| 65 | int foo; |
| 66 | float bar; |
| 67 | |
| 68 | struct InnerNestedPointerComplex |
| 69 | { |
| 70 | int innerFoo; |
| 71 | int* innerPtrField; // expected-note{{field of illegal pointer type 'int *' declared here}} |
| 72 | } inner; // expected-note{{within field of type 'struct InnerNestedPointerComplex' declared here}} |
| 73 | |
| 74 | float y; |
| 75 | float z[4]; |
| 76 | }; |
| 77 | |
| 78 | kernel void pointer_in_nested_struct_arg_complex(struct NestedPointerComplex arg) { }// expected-error{{struct kernel parameters may not contain pointers}} |
| 79 | |
| 80 | typedef struct NestedBool // expected-note 2 {{within field of type 'NestedBool' declared here}} |
| 81 | { |
| 82 | int x; |
| 83 | struct InnerNestedBool |
| 84 | { |
| 85 | bool boolField; // expected-note 2 {{field of illegal type 'bool' declared here}} |
| 86 | } inner; // expected-note 2 {{within field of type 'struct InnerNestedBool' declared here}} |
| 87 | } NestedBool; |
| 88 | |
| 89 | 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}} |
| 90 | |
| 91 | // Warning emitted again for argument used in other kernel |
| 92 | 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}} |
| 93 | |
| 94 | |
| 95 | // Check for note with a struct not defined inside the struct |
| 96 | typedef struct NestedBool2Inner |
| 97 | { |
| 98 | bool boolField; // expected-note{{field of illegal type 'bool' declared here}} |
| 99 | } NestedBool2Inner; |
| 100 | |
| 101 | typedef struct NestedBool2 // expected-note{{within field of type 'NestedBool2' declared here}} |
| 102 | { |
| 103 | int x; |
| 104 | NestedBool2Inner inner; // expected-note{{within field of type 'NestedBool2Inner' (aka 'struct NestedBool2Inner') declared here}} |
| 105 | } NestedBool2; |
| 106 | |
| 107 | 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}} |
| 108 | |
| 109 | |
| 110 | struct InnerInner |
| 111 | { |
| 112 | int* foo; |
| 113 | bool x; |
| 114 | }; |
| 115 | |
| 116 | struct Valid |
| 117 | { |
| 118 | float c; |
| 119 | float d; |
| 120 | }; |
| 121 | |
| 122 | struct Inner |
| 123 | { |
| 124 | struct Valid v; |
| 125 | struct InnerInner a; |
| 126 | struct Valid g; |
| 127 | struct InnerInner b; |
| 128 | }; |
| 129 | |
| 130 | struct AlsoUser // expected-note{{within field of type 'AlsoUser' declared here}} |
| 131 | { |
| 132 | float x; |
| 133 | struct Valid valid1; |
| 134 | struct Valid valid2; |
| 135 | struct NestedPointer aaaa; // expected-note{{within field of type 'struct NestedPointer' declared here}} |
| 136 | }; |
| 137 | |
| 138 | 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}} |