Debian Codegraph @

clang/test/SemaOpenACC/no-branch-in-out.c

raw
1 // RUN: %clang_cc1 %s -verify -fopenacc
2
3 void BreakContinue() {
4
5 #pragma acc parallel
6 for(int i =0; i < 5; ++i) {
7 switch(i) {
8 case 0:
9 break; // leaves switch, not 'for'.
10 default:
11 i +=2;
12 break;
13 }
14 if (i == 2)
15 continue;
16
17 break; // expected-error{{invalid branch out of OpenACC Compute Construct}}
18 }
19
20 int j;
21 switch(j) {
22 case 0:
23 #pragma acc parallel
24 {
25 break; // expected-error{{invalid branch out of OpenACC Compute Construct}}
26 }
27 case 1:
28 #pragma acc parallel
29 {
30 }
31 break;
32 }
33
34 #pragma acc parallel
35 for(int i = 0; i < 5; ++i) {
36 if (i > 1)
37 break; // expected-error{{invalid branch out of OpenACC Compute Construct}}
38 }
39
40 #pragma acc serial
41 for(int i = 0; i < 5; ++i) {
42 if (i > 1)
43 break; // expected-error{{invalid branch out of OpenACC Compute Construct}}
44 }
45
46 #pragma acc kernels
47 for(int i = 0; i < 5; ++i) {
48 if (i > 1)
49 break; // expected-error{{invalid branch out of OpenACC Compute Construct}}
50 }
51
52 #pragma acc parallel
53 switch(j) {
54 case 1:
55 break;
56 }
57
58 #pragma acc parallel
59 {
60 for(int i = 1; i < 100; i++) {
61 if (i > 4)
62 break;
63 }
64 }
65
66 for (int i =0; i < 5; ++i) {
67 #pragma acc parallel
68 {
69 continue; // expected-error{{invalid branch out of OpenACC Compute Construct}}
70 }
71 }
72
73 #pragma acc parallel
74 for (int i =0; i < 5; ++i) {
75 continue;
76 }
77
78 #pragma acc parallel
79 for (int i =0; i < 5; ++i) {
80 {
81 continue;
82 }
83 }
84
85 for (int i =0; i < 5; ++i) {
86 #pragma acc parallel
87 {
88 break; // expected-error{{invalid branch out of OpenACC Compute Construct}}
89 }
90 }
91
92 #pragma acc parallel
93 while (j) {
94 --j;
95 if (j > 4)
96 break; // expected-error{{invalid branch out of OpenACC Compute Construct}}
97 }
98
99 #pragma acc parallel
100 do {
101 --j;
102 if (j > 4)
103 break; // expected-error{{invalid branch out of OpenACC Compute Construct}}
104 } while (j );
105
106 }
107
108 void Return() {
109 #pragma acc parallel
110 {
111 return;// expected-error{{invalid return out of OpenACC Compute Construct}}
112 }
113
114 #pragma acc serial
115 {
116 return;// expected-error{{invalid return out of OpenACC Compute Construct}}
117 }
118
119 #pragma acc kernels
120 {
121 return;// expected-error{{invalid return out of OpenACC Compute Construct}}
122 }
123
124 #pragma acc parallel
125 {
126 {
127 return;// expected-error{{invalid return out of OpenACC Compute Construct}}
128 }
129 }
130
131 #pragma acc parallel
132 {
133 for (int i = 0; i < 5; ++i) {
134 return;// expected-error{{invalid return out of OpenACC Compute Construct}}
135 }
136 }
137 }
138
139 void Goto() {
140 int j;
141 #pragma acc parallel // expected-note{{invalid branch out of OpenACC Compute Construct}}
142 while(j) {
143 if (j <3)
144 goto LABEL; // expected-error{{cannot jump from this goto statement to its label}}
145 }
146
147 LABEL:
148 {}
149
150 goto LABEL_IN; // expected-error{{cannot jump from this goto statement to its label}}
151
152 #pragma acc parallel // expected-note{{invalid branch into OpenACC Compute Construct}}
153 for(int i = 0; i < 5; ++i) {
154 LABEL_IN:
155 {}
156 }
157
158 #pragma acc parallel
159 for(int i = 0; i < 5; ++i) {
160 LABEL_NOT_CALLED:
161 {}
162 }
163
164 #pragma acc parallel
165 {
166 goto ANOTHER_LOOP; // expected-error{{cannot jump from this goto statement to its label}}
167
168 }
169 #pragma acc parallel// expected-note{{invalid branch into OpenACC Compute Construct}}
170
171 {
172 ANOTHER_LOOP:
173 {}
174 }
175
176 #pragma acc parallel
177 {
178 while (j) {
179 --j;
180 if (j < 3)
181 goto LABEL2;
182
183 if (j > 4)
184 break;
185 }
186 LABEL2:
187 {}
188 }
189
190 #pragma acc parallel
191 do {
192 if (j < 3)
193 goto LABEL3;
194
195 if (j > 4)
196 break; // expected-error{{invalid branch out of OpenACC Compute Construct}}
197
198 LABEL3:
199 {}
200 } while (j);
201
202 LABEL4:
203 {}
204 #pragma acc parallel// expected-note{{invalid branch out of OpenACC Compute Construct}}
205 {
206 goto LABEL4;// expected-error{{cannot jump from this goto statement to its label}}
207 }
208
209 #pragma acc parallel// expected-note{{invalid branch into OpenACC Compute Construct}}
210
211 {
212 LABEL5:
213 {}
214 }
215
216 {
217 goto LABEL5;// expected-error{{cannot jump from this goto statement to its label}}
218 }
219
220 #pragma acc parallel
221 {
222 LABEL6:
223 {}
224 goto LABEL6;
225
226 }
227
228 #pragma acc parallel
229 goto LABEL7; // expected-error{{cannot jump from this goto statement to its label}}
230 #pragma acc parallel// expected-note{{invalid branch into OpenACC Compute Construct}}
231 {
232 LABEL7:{}
233 }
234
235 #pragma acc parallel
236 LABEL8:{}
237 #pragma acc parallel// expected-note{{invalid branch out of OpenACC Compute Construct}}
238 {
239 goto LABEL8;// expected-error{{cannot jump from this goto statement to its label}}
240 }
241
242
243 #pragma acc parallel// expected-note{{invalid branch into OpenACC Compute Construct}}
244 {
245 LABEL9:{}
246 }
247
248 ({goto LABEL9;});// expected-error{{cannot jump from this goto statement to its label}}
249
250 #pragma acc parallel// expected-note{{invalid branch out of OpenACC Compute Construct}}
251 {
252 ({goto LABEL10;});// expected-error{{cannot jump from this goto statement to its label}}
253 }
254
255 LABEL10:{}
256
257 ({goto LABEL11;});// expected-error{{cannot jump from this goto statement to its label}}
258 #pragma acc parallel// expected-note{{invalid branch into OpenACC Compute Construct}}
259 {
260 LABEL11:{}
261 }
262
263 LABEL12:{}
264 #pragma acc parallel// expected-note{{invalid branch out of OpenACC Compute Construct}}
265 {
266 ({goto LABEL12;});// expected-error{{cannot jump from this goto statement to its label}}
267 }
268
269 #pragma acc parallel
270 {
271 ({goto LABEL13;});
272 LABEL13:{}
273 }
274
275 #pragma acc parallel
276 {
277 LABEL14:{}
278 ({goto LABEL14;});
279 }
280
281
282
283 ({goto LABEL15;});// expected-error{{cannot jump from this goto statement to its label}}
284 #pragma acc serial// expected-note{{invalid branch into OpenACC Compute Construct}}
285 {
286 LABEL15:{}
287 }
288
289 LABEL16:{}
290 #pragma acc serial// expected-note{{invalid branch out of OpenACC Compute Construct}}
291 {
292 ({goto LABEL16;});// expected-error{{cannot jump from this goto statement to its label}}
293 }
294
295
296 ({goto LABEL17;});// expected-error{{cannot jump from this goto statement to its label}}
297 #pragma acc kernels// expected-note{{invalid branch into OpenACC Compute Construct}}
298 {
299 LABEL17:{}
300 }
301
302 LABEL18:{}
303 #pragma acc kernels// expected-note{{invalid branch out of OpenACC Compute Construct}}
304 {
305 ({goto LABEL18;});// expected-error{{cannot jump from this goto statement to its label}}
306 }
307
308 }
309
310 void IndirectGoto1() {
311 void* ptr;
312 #pragma acc parallel
313 {
314 LABEL1:{}
315 ptr = &&LABEL1;
316
317 goto *ptr;
318
319 }
320 }
321
322 void IndirectGoto2() {
323 void* ptr;
324 LABEL2:{} // #GOTOLBL2
325 ptr = &&LABEL2;
326 #pragma acc parallel // #GOTOPAR2
327 {
328 // expected-error@+3{{cannot jump from this indirect goto statement to one of its possible targets}}
329 // expected-note@#GOTOLBL2{{possible target of indirect goto statement}}
330 // expected-note@#GOTOPAR2{{invalid branch out of OpenACC Compute Construct}}
331 goto *ptr;
332 }
333 }
334
335 void IndirectGoto3() {
336 void* ptr;
337 #pragma acc parallel // #GOTOPAR3
338 {
339 LABEL3:{} // #GOTOLBL3
340 ptr = &&LABEL3;
341 }
342 // expected-error@+3{{cannot jump from this indirect goto statement to one of its possible targets}}
343 // expected-note@#GOTOLBL3{{possible target of indirect goto statement}}
344 // expected-note@#GOTOPAR3{{invalid branch into OpenACC Compute Construct}}
345 goto *ptr;
346 }
347
348 void IndirectGoto4() {
349 void* ptr;
350 #pragma acc parallel // #GOTOPAR4
351 {
352 LABEL4:{}
353 ptr = &&LABEL4;
354 // expected-error@+3{{cannot jump from this indirect goto statement to one of its possible targets}}
355 // expected-note@#GOTOLBL5{{possible target of indirect goto statement}}
356 // expected-note@#GOTOPAR4{{invalid branch out of OpenACC Compute Construct}}
357 goto *ptr;
358 }
359 LABEL5:// #GOTOLBL5
360
361 ptr=&&LABEL5;
362 }
363
364 void DuffsDevice() {
365 int j;
366 switch (j) {
367 #pragma acc parallel
368 for(int i =0; i < 5; ++i) {
369 case 0: // expected-error{{invalid branch into OpenACC Compute Construct}}
370 {}
371 }
372 }
373
374 switch (j) {
375 #pragma acc parallel
376 for(int i =0; i < 5; ++i) {
377 default: // expected-error{{invalid branch into OpenACC Compute Construct}}
378 {}
379 }
380 }
381
382 switch (j) {
383 #pragma acc kernels
384 for(int i =0; i < 5; ++i) {
385 default: // expected-error{{invalid branch into OpenACC Compute Construct}}
386 {}
387 }
388 }
389
390 switch (j) {
391 #pragma acc parallel
392 for(int i =0; i < 5; ++i) {
393 case 'a' ... 'z': // expected-error{{invalid branch into OpenACC Compute Construct}}
394 {}
395 }
396 }
397
398 switch (j) {
399 #pragma acc serial
400 for(int i =0; i < 5; ++i) {
401 case 'a' ... 'z': // expected-error{{invalid branch into OpenACC Compute Construct}}
402 {}
403 }
404 }
405 }