713 lines · c
1// RUN: %clang_cc1 %s -verify -fopenacc -fnamed-loops2 3void BreakContinue() {4 5#pragma acc parallel6 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/Combined Construct}}18 }19 20#pragma acc parallel loop21 for(int i =0; i < 5; ++i) {22 switch(i) {23 case 0:24 break; // leaves switch, not 'for'.25 default:26 i +=2;27 break;28 }29 if (i == 2)30 continue;31 32 break; // expected-error{{invalid branch out of OpenACC Compute/Combined Construct}}33 }34 35 int j;36 switch(j) {37 case 0:38#pragma acc parallel39 {40 break; // expected-error{{invalid branch out of OpenACC Compute/Combined Construct}}41 }42 case 1:43#pragma acc parallel44 {45 }46 break;47 }48 49#pragma acc parallel50 for(int i = 0; i < 5; ++i) {51 if (i > 1)52 break; // expected-error{{invalid branch out of OpenACC Compute/Combined Construct}}53 }54 55#pragma acc parallel loop56 for(int i = 0; i < 5; ++i) {57 if (i > 1)58 break; // expected-error{{invalid branch out of OpenACC Compute/Combined Construct}}59 }60 61#pragma acc serial62 for(int i = 0; i < 5; ++i) {63 if (i > 1)64 break; // expected-error{{invalid branch out of OpenACC Compute/Combined Construct}}65 }66 67#pragma acc serial loop68 for(int i = 0; i < 5; ++i) {69 if (i > 1)70 break; // expected-error{{invalid branch out of OpenACC Compute/Combined Construct}}71 }72 73#pragma acc kernels74 for(int i = 0; i < 5; ++i) {75 if (i > 1)76 break; // expected-error{{invalid branch out of OpenACC Compute/Combined Construct}}77 }78 79#pragma acc kernels loop80 for(int i = 0; i < 5; ++i) {81 if (i > 1)82 break; // expected-error{{invalid branch out of OpenACC Compute/Combined Construct}}83 }84 85#pragma acc parallel86 switch(j) {87 case 1:88 break;89 }90 91#pragma acc parallel92 {93 for(int i = 1; i < 100; i++) {94 if (i > 4)95 break;96 }97 }98 99 for (int i =0; i < 5; ++i) {100#pragma acc parallel101 {102 continue; // expected-error{{invalid branch out of OpenACC Compute/Combined Construct}}103 }104 }105 106#pragma acc parallel107 for (int i =0; i < 5; ++i) {108 continue;109 }110 111#pragma acc parallel loop112 for (int i =0; i < 5; ++i) {113 continue;114 }115 116#pragma acc parallel117 for (int i =0; i < 5; ++i) {118 {119 continue;120 }121 }122 123#pragma acc parallel loop124 for (int i =0; i < 5; ++i) {125 {126 continue;127 }128 }129 130 for (int i =0; i < 5; ++i) {131#pragma acc parallel132 {133 break; // expected-error{{invalid branch out of OpenACC Compute/Combined Construct}}134 }135 }136 137#pragma acc parallel138 while (j) {139 --j;140 if (j > 4)141 break; // expected-error{{invalid branch out of OpenACC Compute/Combined Construct}}142 }143#pragma acc parallel144 do {145 --j;146 if (j > 4)147 break; // expected-error{{invalid branch out of OpenACC Compute/Combined Construct}}148 } while (j );149}150 151void Return() {152#pragma acc parallel153 {154 return;// expected-error{{invalid return out of OpenACC Compute/Combined Construct}}155 }156 157#pragma acc parallel loop158 for (unsigned i = 0; i < 5; ++i) {159 return;// expected-error{{invalid return out of OpenACC Compute/Combined Construct}}160 }161 162#pragma acc serial163 {164 return;// expected-error{{invalid return out of OpenACC Compute/Combined Construct}}165 }166 167#pragma acc serial loop168 for (unsigned i = 0; i < 5; ++i) {169 return;// expected-error{{invalid return out of OpenACC Compute/Combined Construct}}170 }171 172#pragma acc kernels173 {174 return;// expected-error{{invalid return out of OpenACC Compute/Combined Construct}}175 }176 177#pragma acc kernels loop178 for (unsigned i = 0; i < 5; ++i) {179 return;// expected-error{{invalid return out of OpenACC Compute/Combined Construct}}180 }181 182#pragma acc parallel183 {184 {185 return;// expected-error{{invalid return out of OpenACC Compute/Combined Construct}}186 }187 }188 189#pragma acc parallel loop190 for (unsigned i = 0; i < 5; ++i) {191 {192 return;// expected-error{{invalid return out of OpenACC Compute/Combined Construct}}193 }194 }195 196#pragma acc parallel197 {198 for (int i = 0; i < 5; ++i) {199 return;// expected-error{{invalid return out of OpenACC Compute/Combined Construct}}200 }201 }202 203#pragma acc parallel loop204 for (unsigned i = 0; i < 5; ++i) {205 for (int i = 0; i < 5; ++i) {206 return;// expected-error{{invalid return out of OpenACC Compute/Combined Construct}}207 }208 }209}210 211void Goto() {212 int j;213#pragma acc parallel // expected-note{{invalid branch out of OpenACC Compute/Combined Construct}}214 while(j) {215 if (j <3)216 goto LABEL; // expected-error{{cannot jump from this goto statement to its label}}217 }218 219LABEL:220 {}221 222 goto LABEL_IN; // expected-error{{cannot jump from this goto statement to its label}}223#pragma acc parallel // expected-note{{invalid branch into OpenACC Compute/Combined Construct}}224 for(int i = 0; i < 5; ++i) {225LABEL_IN:226 {}227 }228 229 int i;230 goto LABEL_IN2; // expected-error{{cannot jump from this goto statement to its label}}231#pragma acc parallel loop // expected-note{{invalid branch into OpenACC Compute/Combined Construct}}232 for(i = 0; i < 5; ++i) {233LABEL_IN2:234 {}235 }236 237#pragma acc parallel238 for(int i = 0; i < 5; ++i) {239LABEL_NOT_CALLED:240 {}241 }242 243#pragma acc parallel loop244 for(int i = 0; i < 5; ++i) {245LABEL_NOT_CALLED2:246 {}247 }248 249#pragma acc parallel250 {251 goto ANOTHER_LOOP; // expected-error{{cannot jump from this goto statement to its label}}252 253 }254 255#pragma acc parallel loop256 for (unsigned i = 0; i < 5; ++i) {257 goto ANOTHER_LOOP2; // expected-error{{cannot jump from this goto statement to its label}}258 259 }260 261#pragma acc parallel// expected-note{{invalid branch into OpenACC Compute/Combined Construct}}262 {263ANOTHER_LOOP:264 {}265 }266 267#pragma acc parallel loop// expected-note{{invalid branch into OpenACC Compute/Combined Construct}}268 for (unsigned i = 0; i < 5; ++i) {269ANOTHER_LOOP2:270 {}271 }272 273#pragma acc parallel274 {275 while (j) {276 --j;277 if (j < 3)278 goto LABEL2;279 280 if (j > 4)281 break;282 }283LABEL2:284 {}285 }286 287#pragma acc parallel loop288 for (unsigned i = 0; i < 5; ++i) {289 while (j) {290 --j;291 if (j < 3)292 goto LABEL2_2;293 294 if (j > 4)295 break;296 }297LABEL2_2:298 {}299 }300 301 302#pragma acc parallel303 do {304 if (j < 3)305 goto LABEL3;306 307 if (j > 4)308 break; // expected-error{{invalid branch out of OpenACC Compute/Combined Construct}}309 310LABEL3:311 {}312 } while (j);313 314 315LABEL4:316 {}317 318#pragma acc parallel// expected-note{{invalid branch out of OpenACC Compute/Combined Construct}}319 {320 goto LABEL4;// expected-error{{cannot jump from this goto statement to its label}}321 }322 323#pragma acc parallel loop// expected-note{{invalid branch out of OpenACC Compute/Combined Construct}}324 for (unsigned i = 0; i < 5; ++i) {325 goto LABEL4;// expected-error{{cannot jump from this goto statement to its label}}326 }327 328 329#pragma acc parallel// expected-note{{invalid branch into OpenACC Compute/Combined Construct}}330 {331LABEL5:332 {}333 }334 335#pragma acc parallel loop// expected-note{{invalid branch into OpenACC Compute/Combined Construct}}336 for (unsigned i = 0; i < 5; ++i) {337LABEL5_2:338 {}339 }340 341 {342 goto LABEL5;// expected-error{{cannot jump from this goto statement to its label}}343 goto LABEL5_2;// expected-error{{cannot jump from this goto statement to its label}}344 }345 346#pragma acc parallel347 {348LABEL6:349 {}350 goto LABEL6;351 352 }353 354#pragma acc parallel loop355 for (unsigned i = 0; i < 5; ++i) {356LABEL6_2:357 {}358 goto LABEL6_2;359 360 }361 362#pragma acc parallel363 goto LABEL7; // expected-error{{cannot jump from this goto statement to its label}}364#pragma acc parallel// expected-note{{invalid branch into OpenACC Compute/Combined Construct}}365 {366LABEL7:{}367 }368 369#pragma acc parallel370 LABEL8:{}371#pragma acc parallel// expected-note{{invalid branch out of OpenACC Compute/Combined Construct}}372 {373 goto LABEL8;// expected-error{{cannot jump from this goto statement to its label}}374 }375 376#pragma acc parallel// expected-note{{invalid branch into OpenACC Compute/Combined Construct}}377 {378LABEL9:{}379 }380 381 ({goto LABEL9;});// expected-error{{cannot jump from this goto statement to its label}}382 383#pragma acc parallel loop// expected-note{{invalid branch into OpenACC Compute/Combined Construct}}384 for (unsigned i = 0; i < 5; ++i) {385LABEL9_2:{}386 }387 388 ({goto LABEL9_2;});// expected-error{{cannot jump from this goto statement to its label}}389 390 391#pragma acc parallel// expected-note{{invalid branch out of OpenACC Compute/Combined Construct}}392 for (unsigned i = 0; i < 5; ++i) {393 ({goto LABEL10;});// expected-error{{cannot jump from this goto statement to its label}}394 }395 396LABEL10:{}397 398#pragma acc parallel loop// expected-note{{invalid branch out of OpenACC Compute/Combined Construct}}399 for (unsigned i = 0; i < 5; ++i) {400 ({goto LABEL10_2;});// expected-error{{cannot jump from this goto statement to its label}}401 }402 403LABEL10_2:{}404 405 ({goto LABEL11;});// expected-error{{cannot jump from this goto statement to its label}}406#pragma acc parallel// expected-note{{invalid branch into OpenACC Compute/Combined Construct}}407 {408LABEL11:{}409 }410 411 ({goto LABEL11_2;});// expected-error{{cannot jump from this goto statement to its label}}412#pragma acc parallel loop// expected-note{{invalid branch into OpenACC Compute/Combined Construct}}413 for (unsigned i = 0; i < 5; ++i) {414LABEL11_2:{}415 }416 417LABEL12:{}418#pragma acc parallel// expected-note{{invalid branch out of OpenACC Compute/Combined Construct}}419 {420 ({goto LABEL12;});// expected-error{{cannot jump from this goto statement to its label}}421 }422 423LABEL12_2:{}424#pragma acc parallel loop// expected-note{{invalid branch out of OpenACC Compute/Combined Construct}}425 for (unsigned i = 0; i < 5; ++i) {426 ({goto LABEL12_2;});// expected-error{{cannot jump from this goto statement to its label}}427 }428 429#pragma acc parallel430 {431 ({goto LABEL13;});432LABEL13:{}433 }434 435#pragma acc parallel loop436 for (unsigned i = 0; i < 5; ++i) {437 ({goto LABEL13_2;});438LABEL13_2:{}439 }440 441#pragma acc parallel442 {443 LABEL14:{}444 ({goto LABEL14;});445 }446 447#pragma acc parallel loop448 for (unsigned i = 0; i < 5; ++i) {449 LABEL14_2:{}450 ({goto LABEL14_2;});451 }452 453 454 455 ({goto LABEL15;});// expected-error{{cannot jump from this goto statement to its label}}456#pragma acc serial// expected-note{{invalid branch into OpenACC Compute/Combined Construct}}457 {458LABEL15:{}459 }460 ({goto LABEL15_2;});// expected-error{{cannot jump from this goto statement to its label}}461#pragma acc serial loop// expected-note{{invalid branch into OpenACC Compute/Combined Construct}}462 for (unsigned i = 0; i < 5; ++i) {463LABEL15_2:{}464 }465 466LABEL16:{}467#pragma acc serial// expected-note{{invalid branch out of OpenACC Compute/Combined Construct}}468 {469 ({goto LABEL16;});// expected-error{{cannot jump from this goto statement to its label}}470 }471 472LABEL16_2:{}473#pragma acc serial loop// expected-note{{invalid branch out of OpenACC Compute/Combined Construct}}474 for (unsigned i = 0; i < 5; ++i) {475 ({goto LABEL16_2;});// expected-error{{cannot jump from this goto statement to its label}}476 }477 478 ({goto LABEL17;});// expected-error{{cannot jump from this goto statement to its label}}479#pragma acc kernels// expected-note{{invalid branch into OpenACC Compute/Combined Construct}}480 {481LABEL17:{}482 }483 484 ({goto LABEL17_2;});// expected-error{{cannot jump from this goto statement to its label}}485#pragma acc kernels loop// expected-note{{invalid branch into OpenACC Compute/Combined Construct}}486 for (unsigned i = 0; i < 5; ++i) {487LABEL17_2:{}488 }489 490LABEL18:{}491#pragma acc kernels// expected-note{{invalid branch out of OpenACC Compute/Combined Construct}}492 {493 ({goto LABEL18;});// expected-error{{cannot jump from this goto statement to its label}}494 }495 496LABEL18_2:{}497#pragma acc kernels loop// expected-note{{invalid branch out of OpenACC Compute/Combined Construct}}498 for (unsigned i = 0; i < 5; ++i) {499 ({goto LABEL18_2;});// expected-error{{cannot jump from this goto statement to its label}}500 }501}502 503void IndirectGoto1() {504 void* ptr;505#pragma acc parallel506 {507LABEL1:{}508 ptr = &&LABEL1;509 goto *ptr;510 511 }512}513 514void IndirectGoto1_Loop() {515 void *ptr;516#pragma acc parallel loop517 for (unsigned i = 0; i < 5; ++i) {518LABEL1:{}519 ptr = &&LABEL1;520 521 goto *ptr;522 523 }524}525 526void IndirectGoto2() {527 void* ptr;528LABEL2:{} // #GOTOLBL2529 ptr = &&LABEL2;530#pragma acc parallel // #GOTOPAR2531 {532// expected-error@+3{{cannot jump from this indirect goto statement to one of its possible targets}}533// expected-note@#GOTOLBL2{{possible target of indirect goto statement}}534// expected-note@#GOTOPAR2{{invalid branch out of OpenACC Compute/Combined Construct}}535 goto *ptr;536 }537 538#pragma acc parallel loop // #GOTOPAR_LOOP2539 for (unsigned i = 0; i < 5; ++i) {540// expected-error@+3{{cannot jump from this indirect goto statement to one of its possible targets}}541// expected-note@#GOTOLBL2{{possible target of indirect goto statement}}542// expected-note@#GOTOPAR_LOOP2{{invalid branch out of OpenACC Compute/Combined Construct}}543 goto *ptr;544 }545}546 547void IndirectGoto3() {548 void* ptr;549#pragma acc parallel // #GOTOPAR3550 {551LABEL3:{} // #GOTOLBL3552 ptr = &&LABEL3;553 }554// expected-error@+3{{cannot jump from this indirect goto statement to one of its possible targets}}555// expected-note@#GOTOLBL3{{possible target of indirect goto statement}}556// expected-note@#GOTOPAR3{{invalid branch into OpenACC Compute/Combined Construct}}557 goto *ptr;558}559 560void IndirectGoto3_Loop() {561 void* ptr;562#pragma acc parallel loop// #GOTOPAR_LOOP3563 for (unsigned i = 0; i < 5; ++i) {564LABEL3:{} // #GOTOLBL3_2565 ptr = &&LABEL3;566 }567// expected-error@+3{{cannot jump from this indirect goto statement to one of its possible targets}}568// expected-note@#GOTOLBL3_2{{possible target of indirect goto statement}}569// expected-note@#GOTOPAR_LOOP3{{invalid branch into OpenACC Compute/Combined Construct}}570 goto *ptr;571}572 573void IndirectGoto4() {574 void* ptr;575#pragma acc parallel // #GOTOPAR4576 {577LABEL4:{}578 ptr = &&LABEL4;579// expected-error@+3{{cannot jump from this indirect goto statement to one of its possible targets}}580// expected-note@#GOTOLBL5{{possible target of indirect goto statement}}581// expected-note@#GOTOPAR4{{invalid branch out of OpenACC Compute/Combined Construct}}582 goto *ptr;583 }584LABEL5:// #GOTOLBL5585 586 ptr=&&LABEL5;587}588 589void IndirectGoto4_2() {590 void* ptr;591#pragma acc parallel loop // #GOTOPAR_LOOP4592 for (unsigned i = 0; i < 5; ++i) {593LABEL4:{}594 ptr = &&LABEL4;595// expected-error@+3{{cannot jump from this indirect goto statement to one of its possible targets}}596// expected-note@#GOTOLBL_LOOP5{{possible target of indirect goto statement}}597// expected-note@#GOTOPAR_LOOP4{{invalid branch out of OpenACC Compute/Combined Construct}}598 goto *ptr;599 }600LABEL5:// #GOTOLBL_LOOP5601 602 ptr=&&LABEL5;603}604 605void DuffsDevice() {606 int j;607 switch (j) {608#pragma acc parallel609 for(int i =0; i < 5; ++i) {610 case 0: // expected-error{{invalid branch into OpenACC Compute/Combined Construct}}611 {}612 }613 }614 615 switch (j) {616#pragma acc parallel617 for(int i =0; i < 5; ++i) {618 default: // expected-error{{invalid branch into OpenACC Compute/Combined Construct}}619 {}620 }621 }622 623 switch (j) {624#pragma acc kernels625 for(int i =0; i < 5; ++i) {626 default: // expected-error{{invalid branch into OpenACC Compute/Combined Construct}}627 {}628 }629 }630 631 switch (j) {632#pragma acc parallel633 for(int i =0; i < 5; ++i) {634 case 'a' ... 'z': // expected-error{{invalid branch into OpenACC Compute/Combined Construct}}635 {}636 }637 }638 639 switch (j) {640#pragma acc serial641 for(int i =0; i < 5; ++i) {642 case 'a' ... 'z': // expected-error{{invalid branch into OpenACC Compute/Combined Construct}}643 {}644 }645 }646}647 648void DuffsDeviceLoop() {649 int j;650 switch (j) {651#pragma acc parallel loop652 for(int i =0; i < 5; ++i) {653 case 0: // expected-error{{invalid branch into OpenACC Compute/Combined Construct}}654 {}655 }656 }657 658 switch (j) {659#pragma acc parallel loop660 for(int i =0; i < 5; ++i) {661 default: // expected-error{{invalid branch into OpenACC Compute/Combined Construct}}662 {}663 }664 }665 666 switch (j) {667#pragma acc kernels loop668 for(int i =0; i < 5; ++i) {669 default: // expected-error{{invalid branch into OpenACC Compute/Combined Construct}}670 {}671 }672 }673 674 switch (j) {675#pragma acc parallel loop676 for(int i =0; i < 5; ++i) {677 case 'a' ... 'z': // expected-error{{invalid branch into OpenACC Compute/Combined Construct}}678 {}679 }680 }681 682 switch (j) {683#pragma acc serial loop684 for(int i =0; i < 5; ++i) {685 case 'a' ... 'z': // expected-error{{invalid branch into OpenACC Compute/Combined Construct}}686 {}687 }688 }689}690 691void LabeledBreakContinue() {692 a: for (int i =0; i < 5; ++i) {693#pragma acc parallel694 {695 continue a; // expected-error{{invalid branch out of OpenACC Compute/Combined Construct}}696 break a; // expected-error{{invalid branch out of OpenACC Compute/Combined Construct}}697 }698 }699 700#pragma acc parallel701 b: c: for (int i =0; i < 5; ++i) {702 switch(i) {703 case 0: break; // leaves switch, not 'for'.704 }705 706 break b; // expected-error{{invalid branch out of OpenACC Compute/Combined Construct}}707 break c; // expected-error{{invalid branch out of OpenACC Compute/Combined Construct}}708 while (1) break b; // expected-error{{invalid branch out of OpenACC Compute/Combined Construct}}709 while (1) break c; // expected-error{{invalid branch out of OpenACC Compute/Combined Construct}}710 d: while (1) break d;711 }712}713