213 lines · cpp
1// RUN: %clang_cc1 %s -verify -fopenacc2 3struct Incomplete; // #INCOMPLETE4struct NotConvertible{} NC;5 6struct CorrectConvert {7 operator int();8} Convert;9 10constexpr int returns_3() { return 3; }11 12using FuncPtrTy = void (*)();13FuncPtrTy FuncPtrTyArray[2];14 15void Func(int i, int j) {16 int array[5];17 int VLA[i];18 int *ptr;19 void *void_ptr;20 21 // Follows int-expr rules, so only convertible to int.22 // expected-error@+1{{OpenACC sub-array bound requires expression of integer type ('struct NotConvertible' invalid}}23#pragma acc parallel private(array[NC:])24 while (true);25 26 // expected-error@+1{{OpenACC sub-array bound requires expression of integer type ('struct NotConvertible' invalid}}27#pragma acc parallel private(array[:NC])28 while (true);29 30 // expected-error@+2{{OpenACC sub-array bound requires expression of integer type ('struct NotConvertible' invalid}}31 // expected-error@+1{{OpenACC sub-array bound requires expression of integer type ('struct NotConvertible' invalid}}32#pragma acc parallel private(array[NC:NC])33 while (true);34 35 // expected-error@+2{{OpenACC sub-array bound requires expression of integer type ('struct NotConvertible' invalid}}36 // expected-error@+1{{OpenACC sub-array length is unspecified and cannot be inferred because the subscripted value is not an array}}37#pragma acc parallel private(ptr[NC:])38 while (true);39 40 // expected-error@+1{{OpenACC sub-array bound requires expression of integer type ('struct NotConvertible' invalid}}41#pragma acc parallel private(ptr[:NC])42 while (true);43 44 // expected-error@+2{{OpenACC sub-array bound requires expression of integer type ('struct NotConvertible' invalid}}45 // expected-error@+1{{OpenACC sub-array bound requires expression of integer type ('struct NotConvertible' invalid}}46#pragma acc parallel private(ptr[NC:NC])47 while (true);48 49 // These are convertible, so they work.50#pragma acc parallel private(array[Convert:Convert])51 while (true);52 53#pragma acc parallel private(ptr[Convert:Convert])54 while (true);55 56 57 // The length for "dynamically" allocated dimensions of an array must be58 // explicitly specified.59 60 // expected-error@+1{{OpenACC sub-array length is unspecified and cannot be inferred because the subscripted value is not an array}}61#pragma acc parallel private(ptr[3:])62 while (true);63 64 // expected-error@+2{{OpenACC sub-array length is unspecified and cannot be inferred because the subscripted value is an array of unknown bound}}65 // expected-warning@+1{{variable of array type 'int[i]' referenced in OpenACC 'private' clause does not have constant bounds; initialization will happen after decay to pointer}}66#pragma acc parallel private(VLA[3:])67 while (true);68 69#pragma acc parallel private(ptr[:3])70 while (true);71 72 // expected-warning@+1{{variable of array type 'int[i]' referenced in OpenACC 'private' clause does not have constant bounds; initialization will happen after decay to pointer}}73#pragma acc parallel private(VLA[:3])74 while (true);75 76 // Error if the length of the array + the initializer is bigger the the array77 // with known bounds.78 79 // expected-error@+1{{OpenACC sub-array length evaluated to a value (6) that would be out of the range of the subscripted array size of 5}}80#pragma acc parallel private(array[i:returns_3() + 3])81 while (true);82 83 // expected-error@+1{{OpenACC sub-array length evaluated to a value (6) that would be out of the range of the subscripted array size of 5}}84#pragma acc parallel private(array[:returns_3() + 3])85 while (true);86 87#pragma acc parallel private(array[:returns_3()])88 while (true);89 90 // expected-error@+1{{OpenACC sub-array specified range [3:3] would be out of the range of the subscripted array size of 5}}91#pragma acc parallel private(array[returns_3():returns_3()])92 while (true);93 94 // expected-error@+1{{OpenACC sub-array lower bound evaluated to a value (6) that would be out of the range of the subscripted array size of 5}}95#pragma acc parallel private(array[returns_3() + 3:])96 while (true);97 98 // expected-error@+1{{OpenACC sub-array lower bound evaluated to a value (6) that would be out of the range of the subscripted array size of 5}}99#pragma acc parallel private(array[returns_3() + 3:1])100 while (true);101 102 // Standard doesn't specify this, but negative values are likely not103 // permitted, so disallow them here until we come up with a good reason to do104 // otherwise.105 106 // expected-error@+1{{OpenACC sub-array lower bound evaluated to negative value -1}}107#pragma acc parallel private(array[returns_3() - 4 : ])108 while (true);109 110 // expected-error@+1{{OpenACC sub-array length evaluated to negative value -1}}111#pragma acc parallel private(array[: -1])112 while (true);113 114 Incomplete *IncompletePtr;115 // expected-error@+2{{OpenACC sub-array base is of incomplete type 'Incomplete'}}116 // expected-note@#INCOMPLETE{{forward declaration of 'Incomplete'}}117#pragma acc parallel private(IncompletePtr[0 :1])118 while (true);119 120 // expected-error@+1{{OpenACC sub-array base is of incomplete type 'void'}}121#pragma acc parallel private(void_ptr[0:1])122 while (true);123 124 // OK: these are function pointers.125#pragma acc parallel private(FuncPtrTyArray[0 :1])126 while (true);127 128 // expected-error@+1{{OpenACC sub-array cannot be of function type 'void ()'}}129#pragma acc parallel private(FuncPtrTyArray[0][0 :1])130 while (true);131 132 133 // expected-error@+1{{OpenACC sub-array subscripted value is not an array or pointer}}134#pragma acc parallel private(i[0:1])135 while (true);136}137 138template<typename T, typename U, typename V, unsigned I, auto &CEArray>139void Templ(int i){140 T array[I];141 T VLA[i];142 T *ptr;143 U NC;144 V Conv;145 146 // Convertible:147 // expected-error@+2{{OpenACC sub-array bound requires expression of integer type ('NotConvertible' invalid}}148 // expected-note@#INST{{in instantiation of function template specialization}}149#pragma acc parallel private(array[NC:])150 while (true);151 // expected-error@+1{{OpenACC sub-array bound requires expression of integer type ('NotConvertible' invalid}}152#pragma acc parallel private(array[:NC])153 while (true);154 155#pragma acc parallel private(array[Conv:])156 while (true);157#pragma acc parallel private(array[:Conv])158 while (true);159 160 // Need a length for unknown size.161 // expected-error@+1{{OpenACC sub-array length is unspecified and cannot be inferred because the subscripted value is not an array}}162#pragma acc parallel private(ptr[Conv:])163 while (true);164 // expected-error@+2{{OpenACC sub-array length is unspecified and cannot be inferred because the subscripted value is an array of unknown bound}}165 // expected-warning@+1{{variable of array type 'int[i]' referenced in OpenACC 'private' clause does not have constant bounds; initialization will happen after decay to pointer}}166#pragma acc parallel private(VLA[Conv:])167 while (true);168#pragma acc parallel private(ptr[:Conv])169 while (true);170 // expected-warning@+1{{variable of array type 'int[i]' referenced in OpenACC 'private' clause does not have constant bounds; initialization will happen after decay to pointer}}171#pragma acc parallel private(VLA[:Conv])172 while (true);173 174 // Out of bounds.175 // expected-error@+1{{OpenACC sub-array lower bound evaluated to a value (2) that would be out of the range of the subscripted array size of 2}}176#pragma acc parallel private(array[I:])177 while (true);178 179 // OK, don't know the value.180#pragma acc parallel private(array[i:])181 while (true);182 183 // expected-error@+1{{OpenACC sub-array length evaluated to a value (3) that would be out of the range of the subscripted array size of 2}}184#pragma acc parallel private(array[:I + 1])185 while (true);186 187 // expected-error@+1{{OpenACC sub-array lower bound evaluated to a value (5) that would be out of the range of the subscripted array size of 5}}188#pragma acc parallel private(CEArray[5:])189 while (true);190 191 // expected-error@+1{{OpenACC sub-array length evaluated to a value (6) that would be out of the range of the subscripted array size of 5}}192#pragma acc parallel private(CEArray[:2 + I + I])193 while (true);194 195 // expected-error@+1{{OpenACC sub-array length evaluated to a value (4294967295) that would be out of the range of the subscripted array size of 5}}196#pragma acc parallel private(CEArray[:1 - I])197 while (true);198 199 // expected-error@+1{{OpenACC sub-array lower bound evaluated to a value (4294967295) that would be out of the range of the subscripted array size of 5}}200#pragma acc parallel private(CEArray[1 - I:])201 while (true);202 203 T not_ptr;204 // expected-error@+1{{OpenACC sub-array subscripted value is not an array or pointer}}205#pragma acc parallel private(not_ptr[0:1])206 while (true);207}208 209void inst() {210 static constexpr int CEArray[5]={1,2,3,4,5};211 Templ<int, NotConvertible, CorrectConvert, 2, CEArray>(5); // #INST212}213