| 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s -triple spir-unknown-unknown |
| 2 | |
| 3 | kernel void half_arg(half x) { } // expected-error{{declaring function parameter of type 'half' is not allowed; did you forget * ?}} |
| 4 | |
| 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 | typedef __SIZE_TYPE__ size_t; // expected-note{{'size_t' (aka 'unsigned int') declared here}} |
| 13 | // expected-note@-1{{'size_t' (aka 'unsigned int') declared here}} |
| 14 | typedef __PTRDIFF_TYPE__ ptrdiff_t; // expected-note{{'ptrdiff_t' (aka 'int') declared here}} |
| 15 | typedef __INTPTR_TYPE__ intptr_t; // expected-note{{'intptr_t' (aka 'int') declared here}} |
| 16 | typedef __UINTPTR_TYPE__ uintptr_t; // expected-note{{'uintptr_t' (aka 'unsigned int') declared here}} |
| 17 | |
| 18 | kernel void size_t_arg(size_t x) {} // expected-error{{'size_t' (aka 'unsigned int') cannot be used as the type of a kernel parameter}} |
| 19 | |
| 20 | kernel void ptrdiff_t_arg(ptrdiff_t x) {} // expected-error{{'ptrdiff_t' (aka 'int') cannot be used as the type of a kernel parameter}} |
| 21 | |
| 22 | kernel void intptr_t_arg(intptr_t x) {} // expected-error{{'intptr_t' (aka 'int') cannot be used as the type of a kernel parameter}} |
| 23 | |
| 24 | kernel void uintptr_t_arg(uintptr_t x) {} // expected-error{{'uintptr_t' (aka 'unsigned int') cannot be used as the type of a kernel parameter}} |
| 25 | |
| 26 | typedef size_t size_ty; |
| 27 | struct SizeTStruct { // expected-note{{within field of type 'SizeTStruct' declared here}} |
| 28 | size_ty s; // expected-note{{field of illegal type 'size_ty' (aka 'unsigned int') declared here}} |
| 29 | }; |
| 30 | kernel void size_t_struct_arg(struct SizeTStruct x) {} // expected-error{{'struct SizeTStruct' cannot be used as the type of a kernel parameter}} |
| 31 | |
| 32 | union SizeTUnion { // expected-note{{within field of type 'SizeTUnion' declared here}} |
| 33 | size_t s; // expected-note{{field of illegal type 'size_t' (aka 'unsigned int') declared here}} |
| 34 | float f; |
| 35 | }; |
| 36 | kernel void size_t_union_arg(union SizeTUnion x) {} // expected-error{{'union SizeTUnion' cannot be used as the type of a kernel parameter}} |
| 37 | |
| 38 | typedef size_t s_ty; // expected-note{{'s_ty' (aka 'unsigned int') declared here}} |
| 39 | typedef s_ty ss_ty; // expected-note{{'ss_ty' (aka 'unsigned int') declared here}} |
| 40 | kernel void typedef_to_size_t(ss_ty s) {} // expected-error{{'ss_ty' (aka 'unsigned int') cannot be used as the type of a kernel parameter}} |
| 41 | |
| 42 | kernel void bool_arg(bool x) { } // expected-error{{'bool' cannot be used as the type of a kernel parameter}} |
| 43 | |
| 44 | // half kernel argument is allowed when cl_khr_fp16 is enabled. |
| 45 | kernel void half_arg(half x) { } |
| 46 | |
| 47 | typedef struct ContainsBool // expected-note{{within field of type 'ContainsBool' declared here}} |
| 48 | { |
| 49 | bool x; // expected-note{{field of illegal type 'bool' declared here}} |
| 50 | } ContainsBool; |
| 51 | |
| 52 | kernel void bool_in_struct_arg(ContainsBool x) { } // expected-error{{'ContainsBool' (aka 'struct ContainsBool') cannot be used as the type of a kernel parameter}} |
| 53 | |
| 54 | |
| 55 | |
| 56 | typedef struct FooImage2D // expected-note{{within field of type 'FooImage2D' declared here}} |
| 57 | { |
| 58 | // TODO: Clean up needed - we don't really need to check for image, event, etc |
| 59 | // as a note here any longer. |
| 60 | // They are diagnosed as an error for all struct fields (OpenCL v1.2 s6.9b,r). |
| 61 | 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}} |
| 62 | } FooImage2D; |
| 63 | |
| 64 | kernel void image_in_struct_arg(FooImage2D arg) { } // expected-error{{struct kernel parameters may not contain pointers}} |
| 65 | |
| 66 | typedef struct Foo // expected-note{{within field of type 'Foo' declared here}} |
| 67 | { |
| 68 | int* ptrField; // expected-note{{field of illegal pointer type 'int *' declared here}} |
| 69 | } Foo; |
| 70 | |
| 71 | kernel void pointer_in_struct_arg(Foo arg) { } // expected-error{{struct kernel parameters may not contain pointers}} |
| 72 | |
| 73 | typedef union FooUnion // expected-note{{within field of type 'FooUnion' declared here}} |
| 74 | { |
| 75 | int* ptrField; // expected-note{{field of illegal pointer type 'int *' declared here}} |
| 76 | } FooUnion; |
| 77 | |
| 78 | kernel void pointer_in_union_arg(FooUnion arg) { }// expected-error{{union kernel parameters may not contain pointers}} |
| 79 | |
| 80 | typedef struct NestedPointer // expected-note 2 {{within field of type 'NestedPointer' declared here}} |
| 81 | { |
| 82 | int x; |
| 83 | struct InnerNestedPointer |
| 84 | { |
| 85 | int* ptrField; // expected-note 3 {{field of illegal pointer type 'int *' declared here}} |
| 86 | } inner; // expected-note 3 {{within field of type 'struct InnerNestedPointer' declared here}} |
| 87 | } NestedPointer; |
| 88 | |
| 89 | kernel void pointer_in_nested_struct_arg(NestedPointer arg) { }// expected-error{{struct kernel parameters may not contain pointers}} |
| 90 | |
| 91 | struct NestedPointerComplex // expected-note{{within field of type 'NestedPointerComplex' declared here}} |
| 92 | { |
| 93 | int foo; |
| 94 | float bar; |
| 95 | |
| 96 | struct InnerNestedPointerComplex |
| 97 | { |
| 98 | int innerFoo; |
| 99 | int* innerPtrField; // expected-note{{field of illegal pointer type 'int *' declared here}} |
| 100 | } inner; // expected-note{{within field of type 'struct InnerNestedPointerComplex' declared here}} |
| 101 | |
| 102 | float y; |
| 103 | float z[4]; |
| 104 | }; |
| 105 | |
| 106 | kernel void pointer_in_nested_struct_arg_complex(struct NestedPointerComplex arg) { }// expected-error{{struct kernel parameters may not contain pointers}} |
| 107 | |
| 108 | typedef struct NestedBool // expected-note 2 {{within field of type 'NestedBool' declared here}} |
| 109 | { |
| 110 | int x; |
| 111 | struct InnerNestedBool |
| 112 | { |
| 113 | bool boolField; // expected-note 2 {{field of illegal type 'bool' declared here}} |
| 114 | } inner; // expected-note 2 {{within field of type 'struct InnerNestedBool' declared here}} |
| 115 | } NestedBool; |
| 116 | |
| 117 | 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}} |
| 118 | |
| 119 | // Warning emitted again for argument used in other kernel |
| 120 | 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}} |
| 121 | |
| 122 | |
| 123 | // Check for note with a struct not defined inside the struct |
| 124 | typedef struct NestedBool2Inner |
| 125 | { |
| 126 | bool boolField; // expected-note{{field of illegal type 'bool' declared here}} |
| 127 | } NestedBool2Inner; |
| 128 | |
| 129 | typedef struct NestedBool2 // expected-note{{within field of type 'NestedBool2' declared here}} |
| 130 | { |
| 131 | int x; |
| 132 | NestedBool2Inner inner; // expected-note{{within field of type 'NestedBool2Inner' (aka 'struct NestedBool2Inner') declared here}} |
| 133 | } NestedBool2; |
| 134 | |
| 135 | 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}} |
| 136 | |
| 137 | |
| 138 | struct InnerInner |
| 139 | { |
| 140 | int* foo; |
| 141 | bool x; |
| 142 | }; |
| 143 | |
| 144 | struct Valid |
| 145 | { |
| 146 | float c; |
| 147 | float d; |
| 148 | }; |
| 149 | |
| 150 | struct Inner |
| 151 | { |
| 152 | struct Valid v; |
| 153 | struct InnerInner a; |
| 154 | struct Valid g; |
| 155 | struct InnerInner b; |
| 156 | }; |
| 157 | |
| 158 | struct AlsoUser // expected-note{{within field of type 'AlsoUser' declared here}} |
| 159 | { |
| 160 | float x; |
| 161 | struct Valid valid1; |
| 162 | struct Valid valid2; |
| 163 | struct NestedPointer aaaa; // expected-note{{within field of type 'struct NestedPointer' declared here}} |
| 164 | }; |
| 165 | |
| 166 | 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}} |
| 167 | |
| 168 | struct ArrayOfPtr // expected-note{{within field of type 'ArrayOfPtr' declared here}} |
| 169 | { |
| 170 | float *arr[3]; // expected-note{{field of illegal type 'float *[3]' declared here}} |
| 171 | // expected-note@-1{{field of illegal type 'float *[3]' declared here}} |
| 172 | }; |
| 173 | kernel void array_of_ptr(struct ArrayOfPtr arr) {} // expected-error{{struct kernel parameters may not contain pointers}} |
| 174 | |
| 175 | struct ArrayOfStruct // expected-note{{within field of type 'ArrayOfStruct' declared here}} |
| 176 | { |
| 177 | struct ArrayOfPtr arr[3]; // expected-note{{within field of type 'struct ArrayOfPtr [3]' declared here}} |
| 178 | }; |
| 179 | kernel void array_of_struct(struct ArrayOfStruct arr) {} // expected-error{{struct kernel parameters may not contain pointers}} |
| 180 | |