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