442 lines · cpp
1// RUN: %clang_cc1 %s -fopenacc -verify -Wno-empty-body -Wno-unused-value2namespace std {3 struct random_access_iterator_tag{};4}5 6struct SomeStruct{7 void operator++();8 void operator++(int);9};10 11struct SomeIterator {12 bool operator!=(SomeIterator&);13 void operator++();14 void operator++(int);15 int operator*();16};17 18struct SomeRAIterator {19 using iterator_category = std::random_access_iterator_tag;20 SomeRAIterator();21 SomeRAIterator(int i);22 23 void operator=(int i);24 SomeRAIterator &operator=(SomeRAIterator&);25 26 void operator++(int);27 void operator++();28 int operator*();29 void operator+=(int);30 bool operator!=(SomeRAIterator&);31};32 33SomeRAIterator &operator+(const SomeRAIterator&, int);34SomeRAIterator &operator+(int,const SomeRAIterator&);35SomeRAIterator &operator-(const SomeRAIterator&, int);36SomeRAIterator &operator-(int,const SomeRAIterator&);37 38struct HasIteratorCollection {39 SomeIterator &begin();40 SomeIterator &end();41};42 43struct HasRAIteratorCollection {44 SomeRAIterator &begin();45 SomeRAIterator &end();46};47 48void func_call();49 50template<typename Int, typename IntPtr, typename Float, typename Struct, typename Iterator, typename RandAccessIterator>51void SeqLoopRules() {52 53 // No rules in this section!54#pragma acc loop seq55 for(;;);56 57#pragma acc loop seq58 for(float f;;);59 60#pragma acc loop seq61 for(int f;;);62 63#pragma acc loop seq64 for(int f,g;;);65 66#pragma acc loop seq67 for(Int f;;);68 69#pragma acc loop seq70 for(Int *f;;);71 72#pragma acc loop seq73 for(IntPtr f;;);74 75#pragma acc loop seq76 for(Float *f;;);77 78#pragma acc loop seq79 for(SomeStruct f;;);80 81#pragma acc loop seq82 for(Struct f;;);83 84#pragma acc loop seq85 for(SomeIterator f;;);86 87#pragma acc loop seq88 for(Iterator f;;);89 90#pragma acc loop seq91 for(SomeRAIterator f;;);92 93#pragma acc loop seq94 for(RandAccessIterator f;;);95 96#pragma acc loop seq97 for(Int f;;);98 99#pragma acc loop seq100 for(Int f;;++f);101 102#pragma acc loop seq103 for(Int f;;f+=1);104 105 int i;106#pragma acc loop seq107 for(Int f;;i+=1);108 109#pragma acc loop seq110 for(Int f;;i++);111 112#pragma acc loop seq113 for(RandAccessIterator f;;i++);114 115#pragma acc loop seq116 for(RandAccessIterator f;;func_call());117 118 Int Array[5];119#pragma acc loop seq120 for(auto X : Array);121 122#pragma acc loop seq123 for(auto X : HasIteratorCollection{});124 125#pragma acc loop seq126 for(auto X : HasRAIteratorCollection{});127 128 RandAccessIterator f;129#pragma acc loop seq130 for(f;;f++);131 132#pragma acc loop seq133 for(f = 0;;++f);134 135#pragma acc loop seq136 for(f = 0;;f++);137 138#pragma acc loop seq139 for(f = 0;;f+=1);140}141 142 143template<typename Int, typename IntPtr, typename Float, typename Struct, typename Iterator, typename RandAccessIterator>144void LoopRules() {145 146 // Loop variable must be integer, pointer, or random_access_iterator147#pragma acc loop148 // expected-error@+6{{OpenACC 'loop' construct must have initialization clause in canonical form ('var = init' or 'T var = init'}}149 // expected-note@-2{{'loop' construct is here}}150 // expected-error@+4{{OpenACC 'loop' construct must have a terminating condition}}151 // expected-note@-4{{'loop' construct is here}}152 // expected-error@+2{{OpenACC 'loop' variable must monotonically increase or decrease ('++', '--', or compound assignment)}}153 // expected-note@-6{{'loop' construct is here}}154 for(;;);155 156#pragma acc loop157 // expected-error@+6{{loop variable of loop associated with an OpenACC 'loop' construct must be of integer, pointer, or random-access-iterator type (is 'float')}}158 // expected-note@-2{{'loop' construct is here}}159 // expected-error@+4{{OpenACC 'loop' construct must have a terminating condition}}160 // expected-note@-4{{'loop' construct is here}}161 // expected-error@+2{{OpenACC 'loop' variable must monotonically increase or decrease ('++', '--', or compound assignment)}}162 // expected-note@-6{{'loop' construct is here}}163 for(float f = 0;;);164 165#pragma acc loop166 // expected-error@+6{{OpenACC 'loop' construct must have initialization clause in canonical form ('var = init' or 'T var = init'}}167 // expected-note@-2{{'loop' construct is here}}168 // expected-error@+4{{OpenACC 'loop' construct must have a terminating condition}}169 // expected-note@-4{{'loop' construct is here}}170 // expected-error@+2{{OpenACC 'loop' variable must monotonically increase or decrease ('++', '--', or compound assignment)}}171 // expected-note@-6{{'loop' construct is here}}172 for(int f;;);173 174#pragma acc loop175 // expected-error@+6{{OpenACC 'loop' construct must have initialization clause in canonical form ('var = init' or 'T var = init'}}176 // expected-note@-2{{'loop' construct is here}}177 // expected-error@+4{{OpenACC 'loop' construct must have a terminating condition}}178 // expected-note@-4{{'loop' construct is here}}179 // expected-error@+2{{OpenACC 'loop' variable must monotonically increase or decrease ('++', '--', or compound assignment)}}180 // expected-note@-6{{'loop' construct is here}}181 for(int f,g;;);182 183#pragma acc loop184 // expected-error@+4{{OpenACC 'loop' construct must have initialization clause in canonical form ('var = init' or 'T var = init'}}185 // expected-note@-2{{'loop' construct is here}}186 // expected-error@+2{{OpenACC 'loop' construct must have a terminating condition}}187 // expected-note@-4{{'loop' construct is here}}188 for(Int f;;++f);189 190#pragma acc loop191 // expected-error@+2{{OpenACC 'loop' construct must have a terminating condition}}192 // expected-note@-2{{'loop' construct is here}}193 for(Int *f = nullptr;;++f);194 195#pragma acc loop196 // expected-error@+2{{OpenACC 'loop' construct must have a terminating condition}}197 // expected-note@-2{{'loop' construct is here}}198 for(IntPtr f = nullptr;;++f);199 200#pragma acc loop201 // expected-error@+2{{OpenACC 'loop' construct must have a terminating condition}}202 // expected-note@-2{{'loop' construct is here}}203 for(Float *f = nullptr;;++f);204 205#pragma acc loop206 // expected-error@+6{{loop variable of loop associated with an OpenACC 'loop' construct must be of integer, pointer, or random-access-iterator type (is 'SomeStruct')}}207 // expected-note@-2{{'loop' construct is here}}208 // expected-error@+4{{OpenACC 'loop' construct must have a terminating condition}}209 // expected-note@-4{{'loop' construct is here}}210 // expected-error@+2{{OpenACC 'loop' variable must monotonically increase or decrease ('++', '--', or compound assignment)}}211 // expected-note@-6{{'loop' construct is here}}212 for(SomeStruct f;;);213 214#pragma acc loop215 // expected-error@+4{{loop variable of loop associated with an OpenACC 'loop' construct must be of integer, pointer, or random-access-iterator type (is 'SomeStruct')}}216 // expected-note@-2{{'loop' construct is here}}217 // expected-error@+2{{OpenACC 'loop' construct must have a terminating condition}}218 // expected-note@-4{{'loop' construct is here}}219 for(Struct f;;++f);220 221#pragma acc loop222 // expected-error@+4{{loop variable of loop associated with an OpenACC 'loop' construct must be of integer, pointer, or random-access-iterator type (is 'SomeIterator')}}223 // expected-note@-2{{'loop' construct is here}}224 // expected-error@+2{{OpenACC 'loop' construct must have a terminating condition}}225 // expected-note@-4{{'loop' construct is here}}226 for(SomeIterator f;;++f);227 228#pragma acc loop229 // expected-error@+4{{loop variable of loop associated with an OpenACC 'loop' construct must be of integer, pointer, or random-access-iterator type (is 'SomeIterator')}}230 // expected-note@-2{{'loop' construct is here}}231 // expected-error@+2{{OpenACC 'loop' construct must have a terminating condition}}232 // expected-note@-4{{'loop' construct is here}}233 for(Iterator f;;++f);234 235#pragma acc loop236 // expected-error@+2{{OpenACC 'loop' construct must have a terminating condition}}237 // expected-note@-2{{'loop' construct is here}}238 for(SomeRAIterator f;;++f);239 240#pragma acc loop241 // expected-error@+2{{OpenACC 'loop' construct must have a terminating condition}}242 // expected-note@-2{{'loop' construct is here}}243 for(RandAccessIterator f;;++f);244 245 Int i;246#pragma acc loop247 // expected-error@+4{{OpenACC 'loop' construct must have a terminating condition}}248 // expected-note@-2{{'loop' construct is here}}249 // expected-error@+2{{OpenACC 'loop' variable must monotonically increase or decrease ('++', '--', or compound assignment)}}250 // expected-note@-4{{'loop' construct is here}}251 for( i = 0;;);252 253#pragma acc loop254 // expected-error@+6{{OpenACC 'loop' construct must have initialization clause in canonical form ('var = init' or 'T var = init'}}255 // expected-note@-2{{'loop' construct is here}}256 // expected-error@+4{{OpenACC 'loop' construct must have a terminating condition}}257 // expected-note@-4{{'loop' construct is here}}258 // expected-error@+2{{OpenACC 'loop' variable must monotonically increase or decrease ('++', '--', or compound assignment)}}259 // expected-note@-6{{'loop' construct is here}}260 for( i;;);261 262#pragma acc loop263 // expected-error@+6{{OpenACC 'loop' construct must have initialization clause in canonical form ('var = init' or 'T var = init'}}264 // expected-note@-2{{'loop' construct is here}}265 // expected-error@+4{{OpenACC 'loop' construct must have a terminating condition}}266 // expected-note@-4{{'loop' construct is here}}267 // expected-error@+2{{OpenACC 'loop' variable must monotonically increase or decrease ('++', '--', or compound assignment)}}268 // expected-note@-6{{'loop' construct is here}}269 for( int j ;;);270 271#pragma acc loop272 // expected-error@+6{{OpenACC 'loop' construct must have initialization clause in canonical form ('var = init' or 'T var = init'}}273 // expected-note@-2{{'loop' construct is here}}274 // expected-error@+4{{OpenACC 'loop' construct must have a terminating condition}}275 // expected-note@-4{{'loop' construct is here}}276 // expected-error@+2{{OpenACC 'loop' variable must monotonically increase or decrease ('++', '--', or compound assignment)}}277 // expected-note@-6{{'loop' construct is here}}278 for( int j, k = 0;;);279 280#pragma acc loop281 // expected-error@+6{{OpenACC 'loop' construct must have initialization clause in canonical form ('var = init' or 'T var = init'}}282 // expected-note@-2{{'loop' construct is here}}283 // expected-error@+4{{OpenACC 'loop' construct must have a terminating condition}}284 // expected-note@-4{{'loop' construct is here}}285 // expected-error@+2{{OpenACC 'loop' variable must monotonically increase or decrease ('++', '--', or compound assignment)}}286 // expected-note@-6{{'loop' construct is here}}287 for(Int f;;);288 289#pragma acc loop290 // expected-error@+4{{OpenACC 'loop' construct must have initialization clause in canonical form ('var = init' or 'T var = init'}}291 // expected-note@-2{{'loop' construct is here}}292 // expected-error@+2{{OpenACC 'loop' construct must have a terminating condition}}293 // expected-note@-4{{'loop' construct is here}}294 for(Int f;;++f);295 296#pragma acc loop297 // expected-error@+4{{OpenACC 'loop' construct must have initialization clause in canonical form ('var = init' or 'T var = init'}}298 // expected-note@-2{{'loop' construct is here}}299 // expected-error@+2{{OpenACC 'loop' construct must have a terminating condition}}300 // expected-note@-4{{'loop' construct is here}}301 for(Int f;;f+=1);302 303#pragma acc loop304 // expected-error@+6{{OpenACC 'loop' construct must have initialization clause in canonical form ('var = init' or 'T var = init'}}305 // expected-note@-2{{'loop' construct is here}}306 // expected-error@+4{{OpenACC 'loop' construct must have a terminating condition}}307 // expected-note@-4{{'loop' construct is here}}308 // expected-error@+2{{OpenACC 'loop' variable must monotonically increase or decrease ('++', '--', or compound assignment)}}309 // expected-note@-6{{'loop' construct is here}}310 for(Int f;;i+=1);311 312#pragma acc loop313 // expected-error@+6{{OpenACC 'loop' construct must have initialization clause in canonical form ('var = init' or 'T var = init'}}314 // expected-note@-2{{'loop' construct is here}}315 // expected-error@+4{{OpenACC 'loop' construct must have a terminating condition}}316 // expected-note@-4{{'loop' construct is here}}317 // expected-error@+2{{OpenACC 'loop' variable must monotonically increase or decrease ('++', '--', or compound assignment)}}318 // expected-note@-6{{'loop' construct is here}}319 for(Int f;;i++);320 321#pragma acc loop322 // expected-error@+4{{OpenACC 'loop' construct must have a terminating condition}}323 // expected-note@-2{{'loop' construct is here}}324 // expected-error@+2{{OpenACC 'loop' variable must monotonically increase or decrease ('++', '--', or compound assignment)}}325 // expected-note@-4{{'loop' construct is here}}326 for(RandAccessIterator f;;i++);327 328#pragma acc loop329 // expected-error@+4{{OpenACC 'loop' construct must have a terminating condition}}330 // expected-note@-2{{'loop' construct is here}}331 // expected-error@+2{{OpenACC 'loop' variable must monotonically increase or decrease ('++', '--', or compound assignment)}}332 // expected-note@-4{{'loop' construct is here}}333 for(RandAccessIterator f;;func_call());334 335 // Not much we can do here other than check for random access iterator.336 Int Array[5];337#pragma acc loop338 for(auto X : Array);339 340#pragma acc loop341 // expected-error@+2{{loop variable of loop associated with an OpenACC 'loop' construct must be of integer, pointer, or random-access-iterator type (is 'SomeIterator')}}342 // expected-note@-2{{'loop' construct is here}}343 for(auto X : HasIteratorCollection{});344 345#pragma acc loop346 for(auto X : HasRAIteratorCollection{});347 348 RandAccessIterator end;349#pragma acc loop350 for(RandAccessIterator f = 0; f != end; ++f);351 352 RandAccessIterator f;353#pragma acc loop354 // expected-error@+2{{OpenACC 'loop' construct must have initialization clause in canonical form ('var = init' or 'T var = init'}}355 // expected-note@-2{{'loop' construct is here}}356 for(f;f != end;f++);357 358#pragma acc loop359 // expected-error@+2{{OpenACC 'loop' construct must have a terminating condition}}360 // expected-note@-2{{'loop' construct is here}}361 for(f = 0;;++f);362 363#pragma acc loop364 // expected-error@+2{{OpenACC 'loop' construct must have a terminating condition}}365 // expected-note@-2{{'loop' construct is here}}366 for(f = 0;;f++);367 368#pragma acc loop369 // expected-error@+2{{OpenACC 'loop' construct must have a terminating condition}}370 // expected-note@-2{{'loop' construct is here}}371 for(f = 0;;f+=1);372 373#pragma acc loop374 for(f = 0;f != end;++f);375 376#pragma acc loop377 for(f = 0;f != end;f++);378 379#pragma acc loop380 for(f = 0;f != end;f+=1);381 382#pragma acc loop383 for (int i = 0; 5 >= i; ++i);384 385 int otherI;386 // expected-error@+3{{OpenACC 'loop' construct must have a terminating condition}}387 // expected-note@+1{{'loop' construct is here}}388#pragma acc loop389 for (int i = 0; otherI != 5; ++i);390 391 // expected-error@+3{{OpenACC 'loop' construct must have a terminating condition}}392 // expected-note@+1{{'loop' construct is here}}393#pragma acc loop394 for (int i = 0; i != 5 && i < 3; ++i);395 396 // expected-error@+3{{OpenACC 'loop' variable must monotonically increase or decrease}}397 // expected-note@+1{{'loop' construct is here}}398#pragma acc loop399 for (int i = 0; i != 5; ++f);400}401 402void inst() {403 SeqLoopRules<int, int*, float, SomeStruct, SomeIterator, SomeRAIterator>();404 // expected-note@+1{{in instantiation of function template specialization}}405 LoopRules<int, int*, float, SomeStruct, SomeIterator, SomeRAIterator>();406}407 408void allowTrivialAssignStep(int N) {409#pragma acc loop410 for(int i = 0; i !=5; i = i + N);411#pragma acc loop412 for(int i = 0; i !=5; i = i - N);413#pragma acc loop414 for(int i = 0; i !=5; i = N + i);415 416 // expected-error@+3{{OpenACC 'loop' variable must monotonically increase or decrease}}417 // expected-note@+1{{'loop' construct is here}}418#pragma acc loop419 for(int i = 0; i !=5; i = N - i);420 // expected-error@+3{{OpenACC 'loop' variable must monotonically increase or decrease}}421 // expected-note@+1{{'loop' construct is here}}422#pragma acc loop423 for(int i = 0; i !=5; i = N + N);424 425 HasRAIteratorCollection Col;426 427#pragma acc loop428 for (auto Itr = Col.begin(); Itr != Col.end(); Itr = Itr + N);429 430#pragma acc loop431 for (auto Itr = Col.begin(); Itr != Col.end(); Itr = Itr - N);432 433#pragma acc loop434 for (auto Itr = Col.begin(); Itr != Col.end(); Itr = N + Itr);435 436 // expected-error@+3{{OpenACC 'loop' variable must monotonically increase or decrease}}437 // expected-note@+1{{'loop' construct is here}}438#pragma acc loop439 for (auto Itr = Col.begin(); Itr != Col.end(); Itr = N - Itr);440}441 442