Debian Codegraph @

clang/test/SemaOpenACC/compute-construct-reduction-clause.cpp

raw
1 // RUN: %clang_cc1 %s -fopenacc -verify
2
3 struct CompositeOfScalars {
4 int I;
5 float F; // #COS_FLOAT
6 short J;
7 char C;
8 double D;
9 };
10
11 struct CompositeHasComposite {
12 int I;
13 float F;
14 short J;
15 char C;
16 double D;
17 struct CompositeOfScalars COS; // #COS_FIELD
18 };
19
20 void uses(unsigned Parm) {
21 float Var;
22 int IVar;
23
24 #pragma acc parallel reduction(+:Parm)
25 while (1);
26 #pragma acc serial reduction(+:Parm)
27 while (1);
28 // expected-error@+1{{OpenACC 'reduction' clause is not valid on 'kernels' directive}}
29 #pragma acc kernels reduction(+:Parm)
30 while (1);
31
32 // On a 'parallel', 'num_gangs' cannot have >1 args. num_gangs not valid on
33 // 'serial', but 'reduction' not valid on 'kernels', other combos cannot be
34 // tested.
35 #pragma acc parallel reduction(+:Parm) num_gangs(IVar)
36 while (1);
37 #pragma acc parallel num_gangs(IVar) reduction(+:Var)
38 while (1);
39
40 // expected-error@+2{{OpenACC 'num_gangs' clause with more than 1 argument may not appear on a 'parallel' construct with a 'reduction' clause}}
41 // expected-note@+1{{previous 'reduction' clause is here}}
42 #pragma acc parallel reduction(+:Parm) num_gangs(Parm, IVar)
43 while (1);
44
45 // expected-error@+2{{OpenACC 'reduction' clause may not appear on a 'parallel' construct with a 'num_gangs' clause with more than 1 argument}}
46 // expected-note@+1{{previous 'num_gangs' clause is here}}
47 #pragma acc parallel num_gangs(Parm, IVar) reduction(+:Var)
48 while (1);
49
50 #pragma acc parallel reduction(+:Parm) reduction(+:Parm)
51 while (1);
52
53 struct CompositeOfScalars CoS;
54 struct CompositeOfScalars *CoSPtr;
55 struct CompositeHasComposite ChC;
56 struct CompositeHasComposite *ChCPtr;
57
58 int I;
59 float F;
60 int Array[5];
61
62 // Vars in a reduction must be a scalar or a composite of scalars.
63 #pragma acc parallel reduction(&: CoS, I, F)
64 // expected-error@-1{{variable of type 'float' referenced in OpenACC 'reduction' clause does not have a valid operation available}}
65 // expected-note@-2{{while forming binary operator '&='}}
66 // expected-error@-3{{invalid operands to binary expression ('float' and 'float')}}
67 // expected-error@-4{{variable of type 'float' referenced in OpenACC 'reduction' clause does not have a valid operation available}}
68 // expected-note@#COS_FLOAT{{while forming combiner for compound type 'CompositeOfScalars'}}
69 // expected-note@-6{{while forming binary operator '&='}}
70 // expected-error@-7{{invalid operands to binary expression ('float' and 'float')}}
71 while (1);
72 // expected-error@+3{{invalid type 'struct CompositeOfScalars' used in OpenACC 'reduction' variable reference; type is not a scalar value}}
73 // expected-note@#COS_FIELD{{used as field 'COS' of composite 'CompositeHasComposite'}}
74 // expected-note@+1{{OpenACC 'reduction' variable reference must be a scalar variable or a composite of scalars, or an array, sub-array, or element of scalar types}}
75 #pragma acc parallel reduction(&: ChC)
76 while (1);
77 #pragma acc parallel reduction(&: Array)
78 while (1);
79
80 #pragma acc parallel reduction(&: CoS, Array[I], Array[0:I])
81 // expected-error@-1{{variable of type 'float' referenced in OpenACC 'reduction' clause does not have a valid operation available}}
82 // expected-note@#COS_FLOAT{{while forming combiner for compound type 'CompositeOfScalars'}}
83 // expected-note@-3{{while forming binary operator '&='}}
84 // expected-error@-4{{invalid operands to binary expression ('float' and 'float')}}
85 while (1);
86
87 // expected-error@+1{{OpenACC variable is not a valid variable name, sub-array, array element, or composite variable member}}
88 #pragma acc parallel reduction(&: CoS.I)
89 while (1);
90
91 // expected-error@+1{{OpenACC variable is not a valid variable name, sub-array, array element, or composite variable member}}
92 #pragma acc parallel reduction(&: CoSPtr->I)
93
94 while (1);
95 // expected-error@+1{{OpenACC variable is not a valid variable name, sub-array, array element, or composite variable member}}
96 #pragma acc parallel reduction(&: ChC.COS)
97 while (1);
98
99 // expected-error@+1{{OpenACC variable is not a valid variable name, sub-array, array element, or composite variable member}}
100 #pragma acc parallel reduction(&: ChCPtr->COS)
101 while (1);
102
103 CompositeHasComposite CoCArr[5];
104 // expected-error@+4{{invalid type 'struct CompositeOfScalars' used in OpenACC 'reduction' variable reference; type is not a scalar value}}
105 // expected-note@+3{{used as element type of array type 'CompositeHasComposite[5]'}}
106 // expected-note@#COS_FIELD{{used as field 'COS' of composite 'CompositeHasComposite'}}
107 // expected-note@+1{{OpenACC 'reduction' variable reference must be a scalar variable or a composite of scalars, or an array, sub-array, or element of scalar types}}
108 #pragma acc parallel reduction(+:CoCArr)
109 while (1);
110 // expected-error@+3{{invalid type 'struct CompositeOfScalars' used in OpenACC 'reduction' variable reference; type is not a scalar value}}
111 // expected-note@#COS_FIELD{{used as field 'COS' of composite 'CompositeHasComposite'}}
112 // expected-note@+1{{OpenACC 'reduction' variable reference must be a scalar variable or a composite of scalars, or an array, sub-array, or element of scalar types}}
113 #pragma acc parallel reduction(+:CoCArr[3])
114 while (1);
115 // expected-error@+3{{invalid type 'struct CompositeOfScalars' used in OpenACC 'reduction' variable reference; type is not a scalar value}}
116 // expected-note@#COS_FIELD{{used as field 'COS' of composite 'CompositeHasComposite'}}
117 // expected-note@+1{{OpenACC 'reduction' variable reference must be a scalar variable or a composite of scalars, or an array, sub-array, or element of scalar types}}
118 #pragma acc parallel reduction(+:CoCArr[1:1])
119 while (1);
120
121 int *IPtr;
122 // expected-error@+2{{invalid type 'int *' used in OpenACC 'reduction' variable reference; type is not a scalar value, or array of scalars, or composite of scalars}}
123 // expected-note@+1{{OpenACC 'reduction' variable reference must be a scalar variable or a composite of scalars, or an array, sub-array, or element of scalar types}}
124 #pragma acc parallel reduction(+:IPtr)
125 while (1);
126 #pragma acc parallel reduction(+:IPtr[1])
127 while (1);
128 #pragma acc parallel reduction(+:IPtr[1:1])
129 while (1);
130
131 int *IPtrArr[5];
132 // expected-error@+3{{invalid type 'int *' used in OpenACC 'reduction' variable reference; type is not a scalar value, or array of scalars, or composite of scalars}}
133 // expected-note@+2{{used as element type of array type 'int *[5]'}}
134 // expected-note@+1{{OpenACC 'reduction' variable reference must be a scalar variable or a composite of scalars, or an array, sub-array, or element of scalar types}}
135 #pragma acc parallel reduction(+:IPtrArr)
136 while (1);
137
138 struct HasPtr { int *I; }; // #HASPTR
139 HasPtr HP;
140 // expected-error@+3{{invalid type 'int *' used in OpenACC 'reduction' variable reference; type is not a scalar value}}
141 // expected-note@#HASPTR{{used as field 'I' of composite 'HasPtr'}}
142 // expected-note@+1{{OpenACC 'reduction' variable reference must be a scalar variable or a composite of scalars, or an array, sub-array, or element of scalar types}}
143 #pragma acc parallel reduction(+:HP)
144 while (1);
145
146 HasPtr HPArr[5];
147 // expected-error@+4{{invalid type 'int *' used in OpenACC 'reduction' variable reference; type is not a scalar value}}
148 // expected-note@+3{{used as element type of array type 'HasPtr[5]'}}
149 // expected-note@#HASPTR{{used as field 'I' of composite 'HasPtr'}}
150 // expected-note@+1{{OpenACC 'reduction' variable reference must be a scalar variable or a composite of scalars, or an array, sub-array, or element of scalar types}}
151 #pragma acc parallel reduction(+:HPArr)
152 while (1);
153
154 _Complex int CplxI;
155 _Complex int CplxIArr[5];
156 _Complex float CplxF;
157 _Complex float CplxFArr[5];
158 struct HasCplx { _Complex int I; } HC; //#HASCPLX
159 // expected-error@+2{{invalid type '_Complex int' used in OpenACC 'reduction' variable reference; type is not a scalar value}}
160 // expected-note@+1{{OpenACC 'reduction' variable reference must be a scalar variable or a composite of scalars, or an array, sub-array, or element of scalar types}}
161 #pragma acc parallel reduction(+:CplxI)
162 while (1);
163 // expected-error@+3{{invalid type '_Complex int' used in OpenACC 'reduction' variable reference; type is not a scalar value}}
164 // expected-note@+2{{used as element type of array type '_Complex int[5]'}}
165 // expected-note@+1{{OpenACC 'reduction' variable reference must be a scalar variable or a composite of scalars, or an array, sub-array, or element of scalar types}}
166 #pragma acc parallel reduction(+:CplxIArr)
167 while (1);
168 // expected-error@+2{{invalid type '_Complex float' used in OpenACC 'reduction' variable reference; type is not a scalar value}}
169 // expected-note@+1{{OpenACC 'reduction' variable reference must be a scalar variable or a composite of scalars, or an array, sub-array, or element of scalar types}}
170 #pragma acc parallel reduction(+:CplxF)
171 while (1);
172 // expected-error@+3{{invalid type '_Complex float' used in OpenACC 'reduction' variable reference; type is not a scalar value}}
173 // expected-note@+2{{used as element type of array type '_Complex float[5]'}}
174 // expected-note@+1{{OpenACC 'reduction' variable reference must be a scalar variable or a composite of scalars, or an array, sub-array, or element of scalar types}}
175 #pragma acc parallel reduction(+:CplxFArr)
176 while (1);
177 // expected-error@+3{{invalid type '_Complex int' used in OpenACC 'reduction' variable reference; type is not a scalar value}}
178 // expected-note@#HASCPLX{{used as field 'I' of composite 'HasCplx'}}
179 // expected-note@+1{{OpenACC 'reduction' variable reference must be a scalar variable or a composite of scalars, or an array, sub-array, or element of scalar types}}
180 #pragma acc parallel reduction(+:HC)
181 while (1);
182 }
183
184 template<typename T, typename U, typename V>
185 void TemplUses(T Parm, U CoS, V ChC) {
186 T Var;
187 U *CoSPtr;
188 V *ChCPtr;
189
190 #pragma acc parallel reduction(+:Parm)
191 while (1);
192 #pragma acc serial reduction(+:Parm)
193 while (1);
194 // expected-error@+1{{OpenACC 'reduction' clause is not valid on 'kernels' directive}}
195 #pragma acc kernels reduction(+:Parm)
196 while (1);
197
198 // On a 'parallel', 'num_gangs' cannot have >1 args. num_gangs not valid on
199 // 'serial', but 'reduction' not valid on 'kernels', other combos cannot be
200 // tested.
201 #pragma acc parallel reduction(+:Parm) num_gangs(Var)
202 while (1);
203 #pragma acc parallel num_gangs(Var) reduction(+:Var)
204 while (1);
205
206 // expected-error@+2{{OpenACC 'num_gangs' clause with more than 1 argument may not appear on a 'parallel' construct with a 'reduction' clause}}
207 // expected-note@+1{{previous 'reduction' clause is here}}
208 #pragma acc parallel reduction(+:Parm) num_gangs(Parm, Var)
209 while (1);
210
211 // expected-error@+2{{OpenACC 'reduction' clause may not appear on a 'parallel' construct with a 'num_gangs' clause with more than 1 argument}}
212 // expected-note@+1{{previous 'num_gangs' clause is here}}
213 #pragma acc parallel num_gangs(Parm, Var) reduction(+:Var)
214 while (1);
215
216 #pragma acc parallel reduction(+:Parm) reduction(+:Parm)
217 while (1);
218
219 int NonDep;
220 int NonDepArray[5];
221 T Array[5];
222
223 // Vars in a reduction must be a scalar or a composite of scalars.
224 #pragma acc parallel reduction(&: CoS, Var, Parm)
225 // expected-error@-1{{variable of type 'float' referenced in OpenACC 'reduction' clause does not have a valid operation available}}
226 // expected-note@#COS_FLOAT{{while forming combiner for compound type 'CompositeOfScalars'}}
227 // expected-note@-3{{while forming binary operator '&='}}
228 // expected-error@-4{{invalid operands to binary expression ('float' and 'float')}}
229 while (1);
230 // expected-error@+3{{invalid type 'struct CompositeOfScalars' used in OpenACC 'reduction' variable reference; type is not a scalar value}}
231 // expected-note@#COS_FIELD{{used as field 'COS' of composite 'CompositeHasComposite'}}
232 // expected-note@+1{{OpenACC 'reduction' variable reference must be a scalar variable or a composite of scalars, or an array, sub-array, or element of scalar types}}
233 #pragma acc parallel reduction(&: ChC)
234 while (1);
235 #pragma acc parallel reduction(&: Array)
236 while (1);
237 #pragma acc parallel reduction(&: NonDepArray)
238 while (1);
239
240 #pragma acc parallel reduction(&: CoS, Array[Var], Array[0:Var])
241 // expected-error@-1{{variable of type 'float' referenced in OpenACC 'reduction' clause does not have a valid operation available}}
242 // expected-note@#COS_FLOAT{{while forming combiner for compound type 'CompositeOfScalars'}}
243 // expected-note@-3{{while forming binary operator '&='}}
244 // expected-error@-4{{invalid operands to binary expression ('float' and 'float')}}
245 while (1);
246
247 // expected-error@+1{{OpenACC variable is not a valid variable name, sub-array, array element, or composite variable member}}
248 #pragma acc parallel reduction(&: CoS.I)
249 while (1);
250
251 // expected-error@+1{{OpenACC variable is not a valid variable name, sub-array, array element, or composite variable member}}
252 #pragma acc parallel reduction(&: CoSPtr->I)
253
254 while (1);
255 // expected-error@+1{{OpenACC variable is not a valid variable name, sub-array, array element, or composite variable member}}
256 #pragma acc parallel reduction(&: ChC.COS)
257 while (1);
258
259 // expected-error@+1{{OpenACC variable is not a valid variable name, sub-array, array element, or composite variable member}}
260 #pragma acc parallel reduction(&: ChCPtr->COS)
261 while (1);
262
263 T ThreeDArray[3][4][5];
264
265 // expected-error@+3{{invalid type 'int[4][5]' used in OpenACC 'reduction' variable reference; type is not a scalar value}}
266 // expected-note@+2{{used as element type of array type 'int[3][4][5]'}}
267 // expected-note@+1{{OpenACC 'reduction' variable reference must be a scalar variable or a composite of scalars, or an array, sub-array, or element of scalar types}}
268 #pragma acc parallel reduction(+:ThreeDArray)
269 while (1);
270 // expected-error@+3{{invalid type 'int[5]' used in OpenACC 'reduction' variable reference; type is not a scalar value}}
271 // expected-note@+2{{used as element type of array type 'int[4][5]'}}
272 // expected-note@+1{{OpenACC 'reduction' variable reference must be a scalar variable or a composite of scalars, or an array, sub-array, or element of scalar types}}
273 #pragma acc parallel reduction(+:ThreeDArray[1:1])
274 while (1);
275 // expected-error@+3{{invalid type 'int[5]' used in OpenACC 'reduction' variable reference; type is not a scalar value}}
276 // expected-note@+2{{used as element type of array type 'int[4][5]'}}
277 // expected-note@+1{{OpenACC 'reduction' variable reference must be a scalar variable or a composite of scalars, or an array, sub-array, or element of scalar types}}
278 #pragma acc parallel reduction(+:ThreeDArray[1])
279 while (1);
280
281 #pragma acc parallel reduction(+:ThreeDArray[1:1][1])
282 while (1);
283 #pragma acc parallel reduction(+:ThreeDArray[1:1][1:1])
284 while (1);
285 #pragma acc parallel reduction(+:ThreeDArray[1][1])
286 while (1);
287 #pragma acc parallel reduction(+:ThreeDArray[1][1:1])
288 while (1);
289
290 #pragma acc parallel reduction(+:ThreeDArray[1:1][1][1:1])
291 while (1);
292 #pragma acc parallel reduction(+:ThreeDArray[1:1][1][1])
293 while (1);
294 #pragma acc parallel reduction(+:ThreeDArray[1:1][1:1][1:1])
295 while (1);
296 #pragma acc parallel reduction(+:ThreeDArray[1:1][1:1][1])
297 while (1);
298 #pragma acc parallel reduction(+:ThreeDArray[1][1][1:1])
299 while (1);
300 #pragma acc parallel reduction(+:ThreeDArray[1][1][1])
301 while (1);
302 #pragma acc parallel reduction(+:ThreeDArray[1][1:1][1:1])
303 while (1);
304 #pragma acc parallel reduction(+:ThreeDArray[1][1:1][1])
305 while (1);
306 }
307
308 void inst() {
309 CompositeOfScalars CoS;
310 CompositeHasComposite ChC;
311 // expected-note@+1{{in instantiation of function template specialization}}
312 TemplUses(5, CoS, ChC);
313 }