394 lines · cpp
1// RUN: %clang_cc1 %s -fopenacc -verify2 3template<unsigned Val>4void depth_too_high_templ() {5 // expected-error@+2{{'collapse' clause specifies a loop count greater than the number of available loops}}6 // expected-note@+1{{active 'collapse' clause defined here}}7#pragma acc parallel loop collapse(Val)8 for(unsigned i = 0; i < 5; ++i)9 for(unsigned j = 0; j < 5; ++j);10}11constexpr int three() { return 3; }12struct ConvertsThree{13 constexpr ConvertsThree(){};14 15 constexpr operator int(){ return 3; }16};17 18void depth_too_high() {19 depth_too_high_templ<3>(); // expected-note{{in instantiation of function template specialization}}20 21 // expected-error@+2{{'collapse' clause specifies a loop count greater than the number of available loops}}22 // expected-note@+1{{active 'collapse' clause defined here}}23#pragma acc serial loop collapse(3)24 for(unsigned i = 0; i < 5; ++i)25 for(unsigned j = 0; j < 5; ++j);26 27 // expected-error@+2{{'collapse' clause specifies a loop count greater than the number of available loops}}28 // expected-note@+1{{active 'collapse' clause defined here}}29#pragma acc kernels loop collapse(three())30 for(unsigned i = 0; i < 5; ++i)31 for(unsigned j = 0; j < 5; ++j);32 33 // expected-error@+2{{'collapse' clause specifies a loop count greater than the number of available loops}}34 // expected-note@+1{{active 'collapse' clause defined here}}35#pragma acc parallel loop collapse(ConvertsThree{})36 for(unsigned i = 0; i < 5; ++i)37 for(unsigned j = 0; j < 5; ++j);38}39 40template<typename T, unsigned Three>41void not_single_loop_templ() {42 T Arr[5];43 // expected-error@+2{{'collapse' clause specifies a loop count greater than the number of available loops}}44 // expected-note@+1 2{{active 'collapse' clause defined here}}45#pragma acc parallel loop collapse(3)46 for(auto x : Arr) {47 for(auto y : Arr){48 do{}while(true); // expected-error{{do loop cannot appear in intervening code of a 'parallel loop' with a 'collapse' clause}}49 }50 }51 52 // expected-error@+2{{'collapse' clause specifies a loop count greater than the number of available loops}}53 // expected-note@+1 2{{active 'collapse' clause defined here}}54#pragma acc serial loop collapse(Three)55 for(unsigned i = 0; i < 5; ++i) {56 for(unsigned j = 0; j < 5; ++j) {57 do{}while(true); // expected-error{{do loop cannot appear in intervening code of a 'serial loop' with a 'collapse' clause}}58 }59 }60 61#pragma acc kernels loop collapse(Three)62 for(unsigned i = 0; i < 5; ++i) {63 for(unsigned j = 0; j < 5; ++j) {64 for(unsigned k = 0; k < 5;++k) {65 do{}while(true);66 }67 }68 }69 // expected-error@+2{{'collapse' clause specifies a loop count greater than the number of available loops}}70 // expected-note@+1 2{{active 'collapse' clause defined here}}71#pragma acc parallel loop collapse(Three)72 for(auto x : Arr) {73 for(auto y: Arr) {74 do{}while(true); // expected-error{{do loop cannot appear in intervening code of a 'parallel loop' with a 'collapse' clause}}75 }76 }77 78#pragma acc serial loop collapse(Three)79 for(auto x : Arr) {80 for(auto y: Arr) {81 for(auto z: Arr) {82 do{}while(true);83 }84 }85 }86}87 88void not_single_loop() {89 not_single_loop_templ<int, 3>(); // expected-note{{in instantiation of function template}}90 91 // expected-note@+1{{active 'collapse' clause defined here}}92#pragma acc kernels loop collapse(3)93 for(unsigned i = 0; i < 5; ++i) {94 for(unsigned j = 0; j < 5; ++j) {95 for(unsigned k = 0; k < 5;++k);96 }97 while(true); // expected-error{{while loop cannot appear in intervening code of a 'kernels loop' with a 'collapse' clause}}98 }99 100 // expected-note@+1{{active 'collapse' clause defined here}}101#pragma acc parallel loop collapse(3)102 for(unsigned i = 0; i < 5; ++i) {103 for(unsigned j = 0; j < 5; ++j) {104 for(unsigned k = 0; k < 5;++k);105 }106 do{}while(true); // expected-error{{do loop cannot appear in intervening code of a 'parallel loop' with a 'collapse' clause}}107 }108 109 // expected-error@+2{{'collapse' clause specifies a loop count greater than the number of available loops}}110 // expected-note@+1 2{{active 'collapse' clause defined here}}111#pragma acc serial loop collapse(3)112 for(unsigned i = 0; i < 5; ++i) {113 for(unsigned j = 0; j < 5; ++j) {114 while(true); // expected-error{{while loop cannot appear in intervening code of a 'serial loop' with a 'collapse' clause}}115 }116 }117 // expected-error@+2{{'collapse' clause specifies a loop count greater than the number of available loops}}118 // expected-note@+1 2{{active 'collapse' clause defined here}}119#pragma acc kernels loop collapse(3)120 for(unsigned i = 0; i < 5; ++i) {121 for(unsigned j = 0; j < 5; ++j) {122 do{}while(true); // expected-error{{do loop cannot appear in intervening code of a 'kernels loop' with a 'collapse' clause}}123 }124 }125 126#pragma acc parallel loop collapse(2)127 for(unsigned i = 0; i < 5; ++i) {128 for(unsigned j = 0; j < 5; ++j) {129 do{}while(true);130 }131 }132#pragma acc serial loop collapse(2)133 for(unsigned i = 0; i < 5; ++i) {134 for(unsigned j = 0; j < 5; ++j) {135 while(true);136 }137 }138 139 int Arr[5];140 // expected-error@+2{{'collapse' clause specifies a loop count greater than the number of available loops}}141 // expected-note@+1 2{{active 'collapse' clause defined here}}142#pragma acc kernels loop collapse(3)143 for(auto x : Arr) {144 for(auto y : Arr){145 do{}while(true); // expected-error{{do loop cannot appear in intervening code of a 'kernels loop' with a 'collapse' clause}}146 }147 }148 149 // expected-note@+1 {{active 'collapse' clause defined here}}150#pragma acc parallel loop collapse(3)151 for(unsigned i = 0; i < 5; ++i) {152 for(unsigned j = 0; j < 5; ++j) {153 for(unsigned k = 0; k < 5;++k);154 }155 // expected-error@+1{{more than one for-loop in a loop associated with OpenACC 'parallel loop' construct with a 'collapse' clause}}156 for(unsigned k = 0; k < 5;++k);157 }158 159 // expected-note@+1 {{active 'collapse' clause defined here}}160#pragma acc serial loop collapse(3)161 for(unsigned i = 0; i < 5; ++i) {162 for(unsigned j = 0; j < 5; ++j) {163 for(unsigned k = 0; k < 5;++k);164 // expected-error@+1{{more than one for-loop in a loop associated with OpenACC 'serial loop' construct with a 'collapse' clause}}165 for(unsigned k = 0; k < 5;++k);166 }167 }168 169 for(unsigned k = 0; k < 5;++k);170#pragma acc kernels loop collapse(3)171 for(unsigned i = 0; i < 5; ++i) {172 for(unsigned j = 0; j < 5; ++j) {173 for(unsigned k = 0; k < 5;++k);174 }175 }176}177 178template<unsigned Two, unsigned Three>179void no_other_directives() {180#pragma acc parallel loop collapse(Two)181 for(unsigned i = 0; i < 5; ++i) {182 for(unsigned j = 0; j < 5; ++j) {// last loop associated with the top level.183 // expected-error@+1{{'collapse' clause specifies a loop count greater than the number of available loops}}184#pragma acc serial loop collapse(Three) // expected-note 2{{active 'collapse' clause defined here}}185 for(unsigned k = 0; k < 6;++k) {186 for(unsigned l = 0; l < 5; ++l) {187 // expected-error@+1{{OpenACC 'serial' construct cannot appear in intervening code of a 'serial loop' with a 'collapse' clause}}188#pragma acc serial189 ;190 }191 }192 }193 }194#pragma acc kernels loop collapse(Two)// expected-note{{active 'collapse' clause defined here}}195 for(unsigned i = 0; i < 5; ++i) {196 for(unsigned j = 0; j < 5; ++j) {// last loop associated with the top level.197#pragma acc parallel loop collapse(Three)198 for(unsigned k = 0; k < 6;++k) {199 for(unsigned l = 0; l < 5; ++l) {200 for(unsigned m = 0; m < 5; ++m);201 }202 }203 }204 // expected-error@+1{{OpenACC 'serial' construct cannot appear in intervening code of a 'kernels loop' with a 'collapse' clause}}205#pragma acc serial206 ;207 }208}209 210void no_other_directives() {211 no_other_directives<2,3>(); // expected-note{{in instantiation of function template specialization}}212 213 // Ok, not inside the intervening list214#pragma acc serial loop collapse(2)215 for(unsigned i = 0; i < 5; ++i) {216 for(unsigned j = 0; j < 5; ++j) {217 // expected-error@+1{{OpenACC 'data' construct must have at least one 'attach', 'copy', 'copyin', 'copyout', 'create', 'default', 'deviceptr', 'no_create', or 'present' clause}}218#pragma acc data219 ;220 }221 }222 // expected-note@+1{{active 'collapse' clause defined here}}223#pragma acc kernels loop collapse(2)224 for(unsigned i = 0; i < 5; ++i) {225 // expected-error@+2{{OpenACC 'data' construct must have at least one 'attach', 'copy', 'copyin', 'copyout', 'create', 'default', 'deviceptr', 'no_create', or 'present' clause}}226 // expected-error@+1{{OpenACC 'data' construct cannot appear in intervening code of a 'kernels loop' with a 'collapse' clause}}227#pragma acc data228 for(unsigned j = 0; j < 5; ++j) {229 }230 }231}232 233void call();234 235template<unsigned Two>236void intervening_without_force_templ() {237 // expected-note@+1{{active 'collapse' clause defined here}}238#pragma acc parallel loop collapse(2)239 for(unsigned i = 0; i < 5; ++i) {240 // expected-error@+1{{inner loops must be tightly nested inside a 'collapse' clause on a 'parallel loop' construct}}241 call();242 for(unsigned j = 0; j < 5; ++j);243 }244 245 // expected-note@+1{{active 'collapse' clause defined here}}246#pragma acc serial loop collapse(Two)247 for(unsigned i = 0; i < 5; ++i) {248 // expected-error@+1{{inner loops must be tightly nested inside a 'collapse' clause on a 'serial loop' construct}}249 call();250 for(unsigned j = 0; j < 5; ++j);251 }252 253 // expected-note@+1{{active 'collapse' clause defined here}}254#pragma acc kernels loop collapse(2)255 for(unsigned i = 0; i < 5; ++i) {256 for(unsigned j = 0; j < 5; ++j);257 // expected-error@+1{{inner loops must be tightly nested inside a 'collapse' clause on a 'kernels loop' construct}}258 call();259 }260 261#pragma acc parallel loop collapse(force:2)262 for(unsigned i = 0; i < 5; ++i) {263 call();264 for(unsigned j = 0; j < 5; ++j);265 }266 267#pragma acc parallel loop collapse(force:Two)268 for(unsigned i = 0; i < 5; ++i) {269 call();270 for(unsigned j = 0; j < 5; ++j);271 }272 273 274#pragma acc parallel loop collapse(force:2)275 for(unsigned i = 0; i < 5; ++i) {276 for(unsigned j = 0; j < 5; ++j);277 call();278 }279 280#pragma acc parallel loop collapse(force:Two)281 for(unsigned i = 0; i < 5; ++i) {282 for(unsigned j = 0; j < 5; ++j);283 call();284 }285 286#pragma acc parallel loop collapse(Two)287 for(unsigned i = 0; i < 5; ++i) {288 for(unsigned j = 0; j < 5; ++j) {289 call();290 }291 }292 293#pragma acc parallel loop collapse(Two)294 for(unsigned i = 0; i < 5; ++i) {295 {296 {297 for(unsigned j = 0; j < 5; ++j) {298 call();299 }300 }301 }302 }303 304#pragma acc parallel loop collapse(force:Two)305 for(unsigned i = 0; i < 5; ++i) {306 for(unsigned j = 0; j < 5; ++j) {307 call();308 }309 }310 311 // expected-note@+1{{active 'collapse' clause defined here}}312#pragma acc parallel loop collapse(Two)313 for(unsigned i = 0; i < 5; ++i) {314 for(unsigned j = 0; j < 5; ++j);315 // expected-error@+1{{inner loops must be tightly nested inside a 'collapse' clause on a 'parallel loop' construct}}316 call();317 }318 319#pragma acc parallel loop collapse(2)320 // expected-error@+2{{OpenACC 'parallel loop' construct must have a terminating condition}}321 // expected-note@-2{{'parallel loop' construct is here}}322 for(int i = 0;;++i)323 // expected-error@+2{{OpenACC 'parallel loop' construct must have a terminating condition}}324 // expected-note@-5{{'parallel loop' construct is here}}325 for(int j = 0;;++j)326 for(;;);327}328 329void intervening_without_force() {330 intervening_without_force_templ<2>(); // expected-note{{in instantiation of function template specialization}}331 // expected-note@+1{{active 'collapse' clause defined here}}332#pragma acc parallel loop collapse(2)333 for(unsigned i = 0; i < 5; ++i) {334 // expected-error@+1{{inner loops must be tightly nested inside a 'collapse' clause on a 'parallel loop' construct}}335 call();336 for(unsigned j = 0; j < 5; ++j);337 }338 339 // expected-note@+1{{active 'collapse' clause defined here}}340#pragma acc parallel loop collapse(2)341 for(unsigned i = 0; i < 5; ++i) {342 for(unsigned j = 0; j < 5; ++j);343 // expected-error@+1{{inner loops must be tightly nested inside a 'collapse' clause on a 'parallel loop' construct}}344 call();345 }346 347 // The below two are fine, as they use the 'force' tag.348#pragma acc parallel loop collapse(force:2)349 for(unsigned i = 0; i < 5; ++i) {350 call();351 for(unsigned j = 0; j < 5; ++j);352 }353 354#pragma acc parallel loop collapse(force:2)355 for(unsigned i = 0; i < 5; ++i) {356 for(unsigned j = 0; j < 5; ++j);357 call();358 }359 360#pragma acc parallel loop collapse(2)361 for(unsigned i = 0; i < 5; ++i) {362 for(unsigned j = 0; j < 5; ++j) {363 call();364 }365 }366#pragma acc parallel loop collapse(2)367 for(unsigned i = 0; i < 5; ++i) {368 {369 {370 for(unsigned j = 0; j < 5; ++j) {371 call();372 }373 }374 }375 }376 377#pragma acc parallel loop collapse(force:2)378 for(unsigned i = 0; i < 5; ++i) {379 for(unsigned j = 0; j < 5; ++j) {380 call();381 }382 }383 384#pragma acc parallel loop collapse(2)385 // expected-error@+2{{OpenACC 'parallel loop' construct must have a terminating condition}}386 // expected-note@-2{{'parallel loop' construct is here}}387 for(int i = 0;;++i)388 // expected-error@+2{{OpenACC 'parallel loop' construct must have a terminating condition}}389 // expected-note@-5{{'parallel loop' construct is here}}390 for(int j = 0;;++j)391 for(;;);392}393 394