|
| 1 | +// RUN: %clang_cc1 -fsycl-is-device -triple spir64 -fsyntax-only -verify %s |
| 2 | +// |
| 3 | +// This test checks if compiler reports compilation error on an attempt to use |
| 4 | +// a zero-length array inside device code. |
| 5 | + |
| 6 | +template <typename Name, typename Func> |
| 7 | +__attribute__((sycl_kernel)) void kernel(const Func &kernelFunc) { |
| 8 | + // expected-note@+1 5{{called by 'kernel}} |
| 9 | + kernelFunc(); // #KernelObjCall |
| 10 | +} |
| 11 | + |
| 12 | +typedef float ZEROARR[0]; |
| 13 | + |
| 14 | +struct Wrapper { |
| 15 | + int A; |
| 16 | + int BadArray[0]; // expected-note 3{{field of illegal type 'int[0]' declared here}} |
| 17 | +}; |
| 18 | + |
| 19 | +struct WrapperOfWrapper { // expected-error 2{{zero-length arrays are not permitted in SYCL device code}} |
| 20 | + Wrapper F; // expected-note 2{{within field of type 'Wrapper' declared here}} |
| 21 | + ZEROARR *Ptr; //expected-note 5{{field of illegal pointer type 'ZEROARR *' (aka 'float (*)[0]') declared here}} |
| 22 | +}; |
| 23 | + |
| 24 | +template <unsigned Size> struct InnerTemplated { |
| 25 | + double Array[Size]; // expected-note 8{{field of illegal type 'double[0]' declared here}} |
| 26 | +}; |
| 27 | + |
| 28 | +template <unsigned Size, typename Ty> struct Templated { |
| 29 | + unsigned A; |
| 30 | + Ty Arr[Size]; |
| 31 | + InnerTemplated<Size> Array[Size + 1]; // expected-note 8{{within field of type 'InnerTemplated<0U>[1]' declared here}} |
| 32 | +}; |
| 33 | + |
| 34 | +struct KernelSt { |
| 35 | + int A; |
| 36 | + int BadArray[0]; // expected-note {{field of illegal type 'int[0]' declared here}} |
| 37 | + void operator()() const {} |
| 38 | +}; |
| 39 | + |
| 40 | +WrapperOfWrapper offendingFoo() { |
| 41 | + // expected-note@+1 {{called by 'offendingFoo'}} |
| 42 | + return WrapperOfWrapper{}; |
| 43 | +} |
| 44 | + |
| 45 | +template <unsigned Size> |
| 46 | +void templatedContext() { |
| 47 | + Templated<Size, float> Var; |
| 48 | + // expected-error@#KernelObjCall 2{{zero-length arrays are not permitted in SYCL device code}} |
| 49 | + // expected-note@#KernelObjCall {{called by 'kernel<TempContext, (lambda at}} |
| 50 | + // expected-note@+1 {{in instantiation of function template specialization}} |
| 51 | + kernel<class TempContext>([=] { |
| 52 | + // expected-note@+1 {{within field of type 'Templated<0U, float>' declared here}} |
| 53 | + (void)Var; // expected-error 2{{zero-length arrays are not permitted in SYCL device code}} |
| 54 | + }); |
| 55 | + // expected-error@#KernelObjCall {{zero-length arrays are not permitted in SYCL device code}} |
| 56 | + // expected-note@+2 {{in instantiation of function template specialization}} |
| 57 | + // expected-note@+1 {{within field of type 'Templated<0U, float>' declared here}} |
| 58 | + kernel<class TempContext1>([Var] { |
| 59 | + }); |
| 60 | +} |
| 61 | + |
| 62 | +void foo(const unsigned X) { |
| 63 | + int Arr[0]; // expected-note 2{{declared here}} |
| 64 | + ZEROARR TypeDef; // expected-note {{declared here}} |
| 65 | + ZEROARR *Ptr; // expected-note {{declared here}} |
| 66 | + // expected-error@#KernelObjCall 3{{zero-length arrays are not permitted in SYCL device code}} |
| 67 | + // expected-note@+1 {{in instantiation of function template specialization}} |
| 68 | + kernel<class Simple>([=]() { |
| 69 | + (void)Arr; // expected-error {{zero-length arrays are not permitted in SYCL device code}} |
| 70 | + (void)TypeDef; // expected-error {{zero-length arrays are not permitted in SYCL device code}} |
| 71 | + // expected-note@+1 {{field of illegal pointer type 'ZEROARR *' (aka 'float (*)[0]') declared here}} |
| 72 | + (void)Ptr; // expected-error {{zero-length arrays are not permitted in SYCL device code}} |
| 73 | + }); |
| 74 | + // expected-error@#KernelObjCall {{zero-length arrays are not permitted in SYCL device code}} |
| 75 | + // expected-note@+2 {{in instantiation of function template specialization}} |
| 76 | + // expected-note@+1 {{field of illegal type 'int[0]' declared here}} |
| 77 | + kernel<class Simple1>([Arr] { // expected-error {{zero-length arrays are not permitted in SYCL device code}} |
| 78 | + }); |
| 79 | + WrapperOfWrapper St; |
| 80 | + // expected-error@#KernelObjCall 2{{zero-length arrays are not permitted in SYCL device code}} |
| 81 | + // expected-note@+1 {{in instantiation of function template specialization}} |
| 82 | + kernel<class SimpleStruct>([=] { |
| 83 | + // expected-note@+1 {{within field of type 'WrapperOfWrapper' declared here}} |
| 84 | + (void)St.F.BadArray; // expected-error 4{{zero-length arrays are not permitted in SYCL device code}} |
| 85 | + }); |
| 86 | + // expected-error@#KernelObjCall 2{{zero-length arrays are not permitted in SYCL device code}} |
| 87 | + // expected-note@+2 {{in instantiation of function template specialization}} |
| 88 | + // expected-note@+1 {{within field of type 'WrapperOfWrapper' declared here}} |
| 89 | + kernel<class SimpleStruct1>([St] { // expected-error 2{{zero-length arrays are not permitted in SYCL device code}} |
| 90 | + }); |
| 91 | + |
| 92 | + Templated<1, int> OK; |
| 93 | + Templated<1 - 1, double> Weirdo; |
| 94 | + Templated<0, float> Zero; |
| 95 | + // expected-error@#KernelObjCall 4{{zero-length arrays are not permitted in SYCL device code}} |
| 96 | + // expected-note@+1 {{in instantiation of function template specialization}} |
| 97 | + kernel<class UseTemplated>([=] { |
| 98 | + (void)OK; // No errors expected |
| 99 | + (void)Zero; // expected-error 2{{zero-length arrays are not permitted in SYCL device code}} |
| 100 | + // expected-note@+1 {{within field of type 'Templated<1 - 1, double>' declared here}} |
| 101 | + int A = Weirdo.A; // expected-error 2{{zero-length arrays are not permitted in SYCL device code}} |
| 102 | + }); |
| 103 | + |
| 104 | + // expected-note@#KernelObjCall {{called by 'kernel<UseTemplated1, (lambda at}} |
| 105 | + // expected-error@#KernelObjCall 2{{zero-length arrays are not permitted in SYCL device code}} |
| 106 | + // expected-note@+2 {{in instantiation of function template specialization}} |
| 107 | + // expected-note@+1 {{within field of type 'Templated<0, float>' declared here}} |
| 108 | + kernel<class UseTemplated1>([Zero] { // expected-error 2{{zero-length arrays are not permitted in SYCL device code}} |
| 109 | + }); |
| 110 | + |
| 111 | + templatedContext<10>(); |
| 112 | + // expected-note@+1 2{{in instantiation of function template specialization}} |
| 113 | + templatedContext<0>(); |
| 114 | + |
| 115 | + KernelSt K; |
| 116 | + // expected-error@#KernelObjCall {{zero-length arrays are not permitted in SYCL device code}} |
| 117 | + // expected-note@+1 {{in instantiation of function template specialization}} |
| 118 | + kernel<class UseFunctor>(K); |
| 119 | + |
| 120 | + // expected-note@#KernelObjCall {{called by 'kernel<ReturnFromFunc, (lambda at}} |
| 121 | + kernel<class ReturnFromFunc>([=] { |
| 122 | + // expected-note@+1 {{called by 'operator()'}} |
| 123 | + offendingFoo(); |
| 124 | + }); |
| 125 | +} |
0 commit comments