1 // RUN: %clang_cc1 -fsyntax-only -fopenmp -x c++ -std=c++11 -fexceptions -fcxx-exceptions -verify %s 2 3 class S { 4 int a; 5 S() : a(0) {} 6 7 public: 8 S(int v) : a(v) {} 9 S(const S &s) : a(s.a) {} 10 }; 11 12 static int sii; 13 // expected-note@+1 {{defined as threadprivate or thread local}} 14 #pragma omp threadprivate(sii) 15 static int globalii; 16 17 // Currently, we cannot use "0" for global register variables. 18 // register int reg0 __asm__("0"); 19 int reg0; 20 21 int test_iteration_spaces() { 22 const int N = 100; 23 float a[N], b[N], c[N]; 24 int ii, jj, kk; 25 float fii; 26 double dii; 27 register int reg; // expected-warning {{'register' storage class specifier is deprecated}} 28 #pragma omp parallel 29 #pragma omp for 30 for (int i = 0; i < 10; i += 1) { 31 c[i] = a[i] + b[i]; 32 } 33 #pragma omp parallel 34 #pragma omp for 35 for (char i = 0; i < 10; i++) { 36 c[i] = a[i] + b[i]; 37 } 38 #pragma omp parallel 39 #pragma omp for 40 for (char i = 0; i < 10; i += '\1') { 41 c[i] = a[i] + b[i]; 42 } 43 #pragma omp parallel 44 #pragma omp for 45 for (long long i = 0; i < 10; i++) { 46 c[i] = a[i] + b[i]; 47 } 48 #pragma omp parallel 49 // expected-error@+2 {{expression must have integral or unscoped enumeration type, not 'double'}} 50 #pragma omp for 51 for (long long i = 0; i < 10; i += 1.5) { 52 c[i] = a[i] + b[i]; 53 } 54 #pragma omp parallel 55 #pragma omp for 56 for (long long i = 0; i < 'z'; i += 1u) { 57 c[i] = a[i] + b[i]; 58 } 59 #pragma omp parallel 60 // expected-error@+2 {{variable must be of integer or random access iterator type}} 61 #pragma omp for 62 for (float fi = 0; fi < 10.0; fi++) { 63 c[(int)fi] = a[(int)fi] + b[(int)fi]; 64 } 65 #pragma omp parallel 66 // expected-error@+2 {{variable must be of integer or random access iterator type}} 67 #pragma omp for 68 for (double fi = 0; fi < 10.0; fi++) { 69 c[(int)fi] = a[(int)fi] + b[(int)fi]; 70 } 71 #pragma omp parallel 72 // expected-error@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}} 73 #pragma omp for 74 for (int &ref = ii; ref < 10; ref++) { 75 } 76 #pragma omp parallel 77 // expected-error@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}} 78 #pragma omp for 79 for (int i; i < 10; i++) 80 c[i] = a[i]; 81 82 #pragma omp parallel 83 // expected-error@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}} 84 #pragma omp for 85 for (int i = 0, j = 0; i < 10; ++i) 86 c[i] = a[i]; 87 88 #pragma omp parallel 89 // expected-error@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}} 90 #pragma omp for 91 for (; ii < 10; ++ii) 92 c[ii] = a[ii]; 93 94 #pragma omp parallel 95 // expected-warning@+3 {{expression result unused}} 96 // expected-error@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}} 97 #pragma omp for 98 for (ii + 1; ii < 10; ++ii) 99 c[ii] = a[ii]; 100 101 #pragma omp parallel 102 // expected-error@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}} 103 #pragma omp for 104 for (c[ii] = 0; ii < 10; ++ii) 105 c[ii] = a[ii]; 106 107 #pragma omp parallel 108 // Ok to skip parenthesises. 109 #pragma omp for 110 for (((ii)) = 0; ii < 10; ++ii) 111 c[ii] = a[ii]; 112 113 #pragma omp parallel 114 // expected-error@+2 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', or '>=') of loop variable 'i'}} 115 #pragma omp for 116 for (int i = 0; i; i++) 117 c[i] = a[i]; 118 119 #pragma omp parallel 120 // expected-error@+3 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', or '>=') of loop variable 'i'}} 121 // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'i'}} 122 #pragma omp for 123 for (int i = 0; jj < kk; ii++) 124 c[i] = a[i]; 125 126 #pragma omp parallel 127 // expected-error@+2 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', or '>=') of loop variable 'i'}} 128 #pragma omp for 129 for (int i = 0; !!i; i++) 130 c[i] = a[i]; 131 132 #pragma omp parallel 133 // expected-error@+2 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', or '>=') of loop variable 'i'}} 134 #pragma omp for 135 for (int i = 0; i != 1; i++) 136 c[i] = a[i]; 137 138 #pragma omp parallel 139 // expected-error@+2 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', or '>=') of loop variable 'i'}} 140 #pragma omp for 141 for (int i = 0;; i++) 142 c[i] = a[i]; 143 144 #pragma omp parallel 145 // Ok. 146 #pragma omp for 147 for (int i = 11; i > 10; i--) 148 c[i] = a[i]; 149 150 #pragma omp parallel 151 // Ok. 152 #pragma omp for 153 for (int i = 0; i < 10; ++i) 154 c[i] = a[i]; 155 156 #pragma omp parallel 157 // Ok. 158 #pragma omp for 159 for (ii = 0; ii < 10; ++ii) 160 c[ii] = a[ii]; 161 162 #pragma omp parallel 163 // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'ii'}} 164 #pragma omp for 165 for (ii = 0; ii < 10; ++jj) 166 c[ii] = a[jj]; 167 168 #pragma omp parallel 169 // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'ii'}} 170 #pragma omp for 171 for (ii = 0; ii < 10; ++++ii) 172 c[ii] = a[ii]; 173 174 #pragma omp parallel 175 // Ok but undefined behavior (in general, cannot check that incr 176 // is really loop-invariant). 177 #pragma omp for 178 for (ii = 0; ii < 10; ii = ii + ii) 179 c[ii] = a[ii]; 180 181 #pragma omp parallel 182 // expected-error@+2 {{expression must have integral or unscoped enumeration type, not 'float'}} 183 #pragma omp for 184 for (ii = 0; ii < 10; ii = ii + 1.0f) 185 c[ii] = a[ii]; 186 187 #pragma omp parallel 188 // Ok - step was converted to integer type. 189 #pragma omp for 190 for (ii = 0; ii < 10; ii = ii + (int)1.1f) 191 c[ii] = a[ii]; 192 193 #pragma omp parallel 194 // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'ii'}} 195 #pragma omp for 196 for (ii = 0; ii < 10; jj = ii + 2) 197 c[ii] = a[ii]; 198 199 #pragma omp parallel 200 // expected-warning@+3 {{relational comparison result unused}} 201 // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'ii'}} 202 #pragma omp for 203 for (ii = 0; ii<10; jj> kk + 2) 204 c[ii] = a[ii]; 205 206 #pragma omp parallel 207 // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'ii'}} 208 #pragma omp for 209 for (ii = 0; ii < 10;) 210 c[ii] = a[ii]; 211 212 #pragma omp parallel 213 // expected-warning@+3 {{expression result unused}} 214 // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'ii'}} 215 #pragma omp for 216 for (ii = 0; ii < 10; !ii) 217 c[ii] = a[ii]; 218 219 #pragma omp parallel 220 // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'ii'}} 221 #pragma omp for 222 for (ii = 0; ii < 10; ii ? ++ii : ++jj) 223 c[ii] = a[ii]; 224 225 #pragma omp parallel 226 // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'ii'}} 227 #pragma omp for 228 for (ii = 0; ii < 10; ii = ii < 10) 229 c[ii] = a[ii]; 230 231 #pragma omp parallel 232 // expected-note@+3 {{loop step is expected to be positive due to this condition}} 233 // expected-error@+2 {{increment expression must cause 'ii' to increase on each iteration of OpenMP for loop}} 234 #pragma omp for 235 for (ii = 0; ii < 10; ii = ii + 0) 236 c[ii] = a[ii]; 237 238 #pragma omp parallel 239 // expected-note@+3 {{loop step is expected to be positive due to this condition}} 240 // expected-error@+2 {{increment expression must cause 'ii' to increase on each iteration of OpenMP for loop}} 241 #pragma omp for 242 for (ii = 0; ii < 10; ii = ii + (int)(0.8 - 0.45)) 243 c[ii] = a[ii]; 244 245 #pragma omp parallel 246 // expected-note@+3 {{loop step is expected to be positive due to this condition}} 247 // expected-error@+2 {{increment expression must cause 'ii' to increase on each iteration of OpenMP for loop}} 248 #pragma omp for 249 for (ii = 0; (ii) < 10; ii -= 25) 250 c[ii] = a[ii]; 251 252 #pragma omp parallel 253 // expected-note@+3 {{loop step is expected to be positive due to this condition}} 254 // expected-error@+2 {{increment expression must cause 'ii' to increase on each iteration of OpenMP for loop}} 255 #pragma omp for 256 for (ii = 0; (ii < 10); ii -= 0) 257 c[ii] = a[ii]; 258 259 #pragma omp parallel 260 // expected-note@+3 {{loop step is expected to be negative due to this condition}} 261 // expected-error@+2 {{increment expression must cause 'ii' to decrease on each iteration of OpenMP for loop}} 262 #pragma omp for 263 for (ii = 0; ii > 10; (ii += 0)) 264 c[ii] = a[ii]; 265 266 #pragma omp parallel 267 // expected-note@+3 {{loop step is expected to be positive due to this condition}} 268 // expected-error@+2 {{increment expression must cause 'ii' to increase on each iteration of OpenMP for loop}} 269 #pragma omp for 270 for (ii = 0; ii < 10; (ii) = (1 - 1) + (ii)) 271 c[ii] = a[ii]; 272 273 #pragma omp parallel 274 // expected-note@+3 {{loop step is expected to be negative due to this condition}} 275 // expected-error@+2 {{increment expression must cause 'ii' to decrease on each iteration of OpenMP for loop}} 276 #pragma omp for 277 for ((ii = 0); ii > 10; (ii -= 0)) 278 c[ii] = a[ii]; 279 280 #pragma omp parallel 281 // expected-note@+3 {{loop step is expected to be positive due to this condition}} 282 // expected-error@+2 {{increment expression must cause 'ii' to increase on each iteration of OpenMP for loop}} 283 #pragma omp for 284 for (ii = 0; (ii < 10); (ii -= 0)) 285 c[ii] = a[ii]; 286 287 #pragma omp parallel 288 // expected-note@+2 {{defined as firstprivate}} 289 // expected-error@+2 {{loop iteration variable in the associated loop of 'omp for' directive may not be firstprivate, predetermined as private}} 290 #pragma omp for firstprivate(ii) 291 for (ii = 0; ii < 10; ii++) 292 c[ii] = a[ii]; 293 294 #pragma omp parallel 295 // expected-note@+2 {{defined as linear}} 296 // expected-error@+2 {{loop iteration variable in the associated loop of 'omp for' directive may not be linear, predetermined as private}} 297 #pragma omp for linear(ii) 298 for (ii = 0; ii < 10; ii++) 299 c[ii] = a[ii]; 300 301 #pragma omp parallel 302 #pragma omp for private(ii) 303 for (ii = 0; ii < 10; ii++) 304 c[ii] = a[ii]; 305 306 #pragma omp parallel 307 #pragma omp for lastprivate(ii) 308 for (ii = 0; ii < 10; ii++) 309 c[ii] = a[ii]; 310 311 #pragma omp parallel 312 { 313 // expected-error@+2 {{loop iteration variable in the associated loop of 'omp for' directive may not be threadprivate or thread local, predetermined as private}} 314 #pragma omp for 315 for (sii = 0; sii < 10; sii += 1) 316 c[sii] = a[sii]; 317 } 318 319 #pragma omp parallel 320 { 321 #pragma omp for 322 for (reg0 = 0; reg0 < 10; reg0 += 1) 323 c[reg0] = a[reg0]; 324 } 325 326 #pragma omp parallel 327 { 328 #pragma omp for 329 for (reg = 0; reg < 10; reg += 1) 330 c[reg] = a[reg]; 331 } 332 333 #pragma omp parallel 334 { 335 #pragma omp for 336 for (globalii = 0; globalii < 10; globalii += 1) 337 c[globalii] = a[globalii]; 338 } 339 340 #pragma omp parallel 341 { 342 #pragma omp for collapse(2) 343 for (ii = 0; ii < 10; ii += 1) 344 for (globalii = 0; globalii < 10; globalii += 1) 345 c[globalii] += a[globalii] + ii; 346 } 347 348 #pragma omp parallel 349 // expected-error@+2 {{statement after '#pragma omp for' must be a for loop}} 350 #pragma omp for 351 for (auto &item : a) { 352 item = item + 1; 353 } 354 355 #pragma omp parallel 356 // expected-note@+3 {{loop step is expected to be positive due to this condition}} 357 // expected-error@+2 {{increment expression must cause 'i' to increase on each iteration of OpenMP for loop}} 358 #pragma omp for 359 for (unsigned i = 9; i < 10; i--) { 360 c[i] = a[i] + b[i]; 361 } 362 363 int(*lb)[4] = nullptr; 364 #pragma omp parallel 365 #pragma omp for 366 for (int(*p)[4] = lb; p < lb + 8; ++p) { 367 } 368 369 #pragma omp parallel 370 // expected-warning@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}} 371 #pragma omp for 372 for (int a{0}; a < 10; ++a) { 373 } 374 375 return 0; 376 } 377 378 // Iterators allowed in openmp for-loops. 379 namespace std { 380 struct random_access_iterator_tag {}; 381 template <class Iter> 382 struct iterator_traits { 383 typedef typename Iter::difference_type difference_type; 384 typedef typename Iter::iterator_category iterator_category; 385 }; 386 template <class Iter> 387 typename iterator_traits<Iter>::difference_type 388 distance(Iter first, Iter last) { return first - last; } 389 } 390 class Iter0 { 391 public: 392 Iter0() {} 393 Iter0(const Iter0 &) {} 394 Iter0 operator++() { return *this; } 395 Iter0 operator--() { return *this; } 396 bool operator<(Iter0 a) { return true; } 397 }; 398 // expected-note@+2 {{candidate function not viable: no known conversion from 'GoodIter' to 'Iter0' for 1st argument}} 399 // expected-note@+1 2 {{candidate function not viable: no known conversion from 'Iter1' to 'Iter0' for 1st argument}} 400 int operator-(Iter0 a, Iter0 b) { return 0; } 401 class Iter1 { 402 public: 403 Iter1(float f = 0.0f, double d = 0.0) {} 404 Iter1(const Iter1 &) {} 405 Iter1 operator++() { return *this; } 406 Iter1 operator--() { return *this; } 407 bool operator<(Iter1 a) { return true; } 408 bool operator>=(Iter1 a) { return false; } 409 }; 410 class GoodIter { 411 public: 412 GoodIter() {} 413 GoodIter(const GoodIter &) {} 414 GoodIter(int fst, int snd) {} 415 GoodIter &operator=(const GoodIter &that) { return *this; } 416 GoodIter &operator=(const Iter0 &that) { return *this; } 417 GoodIter &operator+=(int x) { return *this; } 418 GoodIter &operator-=(int x) { return *this; } 419 explicit GoodIter(void *) {} 420 GoodIter operator++() { return *this; } 421 GoodIter operator--() { return *this; } 422 bool operator!() { return true; } 423 bool operator<(GoodIter a) { return true; } 424 bool operator<=(GoodIter a) { return true; } 425 bool operator>=(GoodIter a) { return false; } 426 typedef int difference_type; 427 typedef std::random_access_iterator_tag iterator_category; 428 }; 429 class GoodIter1 { 430 public: 431 GoodIter1() {} 432 GoodIter1(const GoodIter1 &) {} 433 GoodIter1 &operator++(int) { return *this; } 434 GoodIter1 &operator=(const GoodIter1 &that) { return *this; } 435 GoodIter1 &operator+=(int x) { return *this; } 436 friend long operator-(const GoodIter1 &, const GoodIter1 &); 437 GoodIter1 &operator-(int) { return *this; } 438 bool operator<(GoodIter1 a) { return true; } 439 typedef int difference_type; 440 typedef std::random_access_iterator_tag iterator_category; 441 }; 442 // expected-note@+2 {{candidate function not viable: no known conversion from 'const Iter0' to 'GoodIter' for 2nd argument}} 443 // expected-note@+1 2 {{candidate function not viable: no known conversion from 'Iter1' to 'GoodIter' for 1st argument}} 444 int operator-(GoodIter a, GoodIter b) { return 0; } 445 // expected-note@+1 3 {{candidate function not viable: requires single argument 'a', but 2 arguments were provided}} 446 GoodIter operator-(GoodIter a) { return a; } 447 // expected-note@+2 {{candidate function not viable: no known conversion from 'const Iter0' to 'int' for 2nd argument}} 448 // expected-note@+1 2 {{candidate function not viable: no known conversion from 'Iter1' to 'GoodIter' for 1st argument}} 449 GoodIter operator-(GoodIter a, int v) { return GoodIter(); } 450 // expected-note@+1 2 {{candidate function not viable: no known conversion from 'Iter0' to 'GoodIter' for 1st argument}} 451 GoodIter operator+(GoodIter a, int v) { return GoodIter(); } 452 // expected-note@+2 {{candidate function not viable: no known conversion from 'GoodIter' to 'int' for 1st argument}} 453 // expected-note@+1 2 {{candidate function not viable: no known conversion from 'Iter1' to 'int' for 1st argument}} 454 GoodIter operator-(int v, GoodIter a) { return GoodIter(); } 455 // expected-note@+1 2 {{candidate function not viable: no known conversion from 'Iter0' to 'int' for 1st argument}} 456 GoodIter operator+(int v, GoodIter a) { return GoodIter(); } 457 458 int test_with_random_access_iterator() { 459 GoodIter begin, end; 460 Iter0 begin0, end0; 461 #pragma omp parallel 462 #pragma omp for 463 for (GoodIter I = begin; I < end; ++I) 464 ++I; 465 #pragma omp parallel 466 // expected-error@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}} 467 #pragma omp for 468 for (GoodIter &I = begin; I < end; ++I) 469 ++I; 470 #pragma omp parallel 471 #pragma omp for 472 for (GoodIter I = begin; I >= end; --I) 473 ++I; 474 #pragma omp parallel 475 // expected-warning@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}} 476 #pragma omp for 477 for (GoodIter I(begin); I < end; ++I) 478 ++I; 479 #pragma omp parallel 480 // expected-warning@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}} 481 #pragma omp for 482 for (GoodIter I(nullptr); I < end; ++I) 483 ++I; 484 #pragma omp parallel 485 // expected-warning@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}} 486 #pragma omp for 487 for (GoodIter I(0); I < end; ++I) 488 ++I; 489 #pragma omp parallel 490 // expected-warning@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}} 491 #pragma omp for 492 for (GoodIter I(1, 2); I < end; ++I) 493 ++I; 494 #pragma omp parallel 495 #pragma omp for 496 for (begin = GoodIter(0); begin < end; ++begin) 497 ++begin; 498 // expected-error@+4 {{invalid operands to binary expression ('GoodIter' and 'const Iter0')}} 499 // expected-error@+3 {{could not calculate number of iterations calling 'operator-' with upper and lower loop bounds}} 500 #pragma omp parallel 501 #pragma omp for 502 for (begin = begin0; begin < end; ++begin) 503 ++begin; 504 #pragma omp parallel 505 // expected-error@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}} 506 #pragma omp for 507 for (++begin; begin < end; ++begin) 508 ++begin; 509 #pragma omp parallel 510 #pragma omp for 511 for (begin = end; begin < end; ++begin) 512 ++begin; 513 #pragma omp parallel 514 // expected-error@+2 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', or '>=') of loop variable 'I'}} 515 #pragma omp for 516 for (GoodIter I = begin; I - I; ++I) 517 ++I; 518 #pragma omp parallel 519 // expected-error@+2 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', or '>=') of loop variable 'I'}} 520 #pragma omp for 521 for (GoodIter I = begin; begin < end; ++I) 522 ++I; 523 #pragma omp parallel 524 // expected-error@+2 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', or '>=') of loop variable 'I'}} 525 #pragma omp for 526 for (GoodIter I = begin; !I; ++I) 527 ++I; 528 #pragma omp parallel 529 // expected-note@+3 {{loop step is expected to be negative due to this condition}} 530 // expected-error@+2 {{increment expression must cause 'I' to decrease on each iteration of OpenMP for loop}} 531 #pragma omp for 532 for (GoodIter I = begin; I >= end; I = I + 1) 533 ++I; 534 #pragma omp parallel 535 #pragma omp for 536 for (GoodIter I = begin; I >= end; I = I - 1) 537 ++I; 538 #pragma omp parallel 539 // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'I'}} 540 #pragma omp for 541 for (GoodIter I = begin; I >= end; I = -I) 542 ++I; 543 #pragma omp parallel 544 // expected-note@+3 {{loop step is expected to be negative due to this condition}} 545 // expected-error@+2 {{increment expression must cause 'I' to decrease on each iteration of OpenMP for loop}} 546 #pragma omp for 547 for (GoodIter I = begin; I >= end; I = 2 + I) 548 ++I; 549 #pragma omp parallel 550 // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'I'}} 551 #pragma omp for 552 for (GoodIter I = begin; I >= end; I = 2 - I) 553 ++I; 554 // In the following example, we cannot update the loop variable using '+=' 555 // expected-error@+3 {{invalid operands to binary expression ('Iter0' and 'int')}} 556 #pragma omp parallel 557 #pragma omp for 558 for (Iter0 I = begin0; I < end0; ++I) 559 ++I; 560 #pragma omp parallel 561 // Initializer is constructor without params. 562 // expected-error@+3 {{invalid operands to binary expression ('Iter0' and 'int')}} 563 // expected-warning@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}} 564 #pragma omp for 565 for (Iter0 I; I < end0; ++I) 566 ++I; 567 Iter1 begin1, end1; 568 // expected-error@+4 {{invalid operands to binary expression ('Iter1' and 'Iter1')}} 569 // expected-error@+3 {{could not calculate number of iterations calling 'operator-' with upper and lower loop bounds}} 570 #pragma omp parallel 571 #pragma omp for 572 for (Iter1 I = begin1; I < end1; ++I) 573 ++I; 574 #pragma omp parallel 575 // expected-note@+3 {{loop step is expected to be negative due to this condition}} 576 // expected-error@+2 {{increment expression must cause 'I' to decrease on each iteration of OpenMP for loop}} 577 #pragma omp for 578 for (Iter1 I = begin1; I >= end1; ++I) 579 ++I; 580 #pragma omp parallel 581 // expected-error@+5 {{invalid operands to binary expression ('Iter1' and 'float')}} 582 // expected-error@+4 {{could not calculate number of iterations calling 'operator-' with upper and lower loop bounds}} 583 // Initializer is constructor with all default params. 584 // expected-warning@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}} 585 #pragma omp for 586 for (Iter1 I; I < end1; ++I) { 587 } 588 GoodIter1 I1, E1; 589 #pragma omp for 590 for (GoodIter1 I = I1; I < E1; I++) 591 ; 592 return 0; 593 } 594 595 template <typename IT, int ST> 596 class TC { 597 public: 598 int dotest_lt(IT begin, IT end) { 599 #pragma omp parallel 600 // expected-note@+3 {{loop step is expected to be positive due to this condition}} 601 // expected-error@+2 {{increment expression must cause 'I' to increase on each iteration of OpenMP for loop}} 602 #pragma omp for 603 for (IT I = begin; I < end; I = I + ST) { 604 ++I; 605 } 606 #pragma omp parallel 607 // expected-note@+3 {{loop step is expected to be positive due to this condition}} 608 // expected-error@+2 {{increment expression must cause 'I' to increase on each iteration of OpenMP for loop}} 609 #pragma omp for 610 for (IT I = begin; I <= end; I += ST) { 611 ++I; 612 } 613 #pragma omp parallel 614 #pragma omp for 615 for (IT I = begin; I < end; ++I) { 616 ++I; 617 } 618 } 619 620 static IT step() { 621 return IT(ST); 622 } 623 }; 624 template <typename IT, int ST = 0> 625 int dotest_gt(IT begin, IT end) { 626 #pragma omp parallel 627 // expected-note@+3 2 {{loop step is expected to be negative due to this condition}} 628 // expected-error@+2 2 {{increment expression must cause 'I' to decrease on each iteration of OpenMP for loop}} 629 #pragma omp for 630 for (IT I = begin; I >= end; I = I + ST) { 631 ++I; 632 } 633 #pragma omp parallel 634 // expected-note@+3 2 {{loop step is expected to be negative due to this condition}} 635 // expected-error@+2 2 {{increment expression must cause 'I' to decrease on each iteration of OpenMP for loop}} 636 #pragma omp for 637 for (IT I = begin; I >= end; I += ST) { 638 ++I; 639 } 640 641 #pragma omp parallel 642 // expected-note@+3 {{loop step is expected to be negative due to this condition}} 643 // expected-error@+2 {{increment expression must cause 'I' to decrease on each iteration of OpenMP for loop}} 644 #pragma omp for 645 for (IT I = begin; I >= end; ++I) { 646 ++I; 647 } 648 649 #pragma omp parallel 650 #pragma omp for 651 for (IT I = begin; I < end; I += TC<int, ST>::step()) { 652 ++I; 653 } 654 } 655 656 void test_with_template() { 657 GoodIter begin, end; 658 TC<GoodIter, 100> t1; 659 TC<GoodIter, -100> t2; 660 t1.dotest_lt(begin, end); 661 t2.dotest_lt(begin, end); // expected-note {{in instantiation of member function 'TC<GoodIter, -100>::dotest_lt' requested here}} 662 dotest_gt(begin, end); // expected-note {{in instantiation of function template specialization 'dotest_gt<GoodIter, 0>' requested here}} 663 dotest_gt<unsigned, -10>(0, 100); // expected-note {{in instantiation of function template specialization 'dotest_gt<unsigned int, -10>' requested here}} 664 } 665 666 void test_loop_break() { 667 const int N = 100; 668 float a[N], b[N], c[N]; 669 #pragma omp parallel 670 #pragma omp for 671 for (int i = 0; i < 10; i++) { 672 c[i] = a[i] + b[i]; 673 for (int j = 0; j < 10; ++j) { 674 if (a[i] > b[j]) 675 break; // OK in nested loop 676 } 677 switch (i) { 678 case 1: 679 b[i]++; 680 break; 681 default: 682 break; 683 } 684 if (c[i] > 10) 685 break; // expected-error {{'break' statement cannot be used in OpenMP for loop}} 686 687 if (c[i] > 11) 688 break; // expected-error {{'break' statement cannot be used in OpenMP for loop}} 689 } 690 691 #pragma omp parallel 692 #pragma omp for 693 for (int i = 0; i < 10; i++) { 694 for (int j = 0; j < 10; j++) { 695 c[i] = a[i] + b[i]; 696 if (c[i] > 10) { 697 if (c[i] < 20) { 698 break; // OK 699 } 700 } 701 } 702 } 703 } 704 705 void test_loop_eh() { 706 const int N = 100; 707 float a[N], b[N], c[N]; 708 #pragma omp parallel 709 #pragma omp for 710 for (int i = 0; i < 10; i++) { 711 c[i] = a[i] + b[i]; 712 try { 713 for (int j = 0; j < 10; ++j) { 714 if (a[i] > b[j]) 715 throw a[i]; 716 } 717 throw a[i]; 718 } catch (float f) { 719 if (f > 0.1) 720 throw a[i]; 721 return; // expected-error {{cannot return from OpenMP region}} 722 } 723 switch (i) { 724 case 1: 725 b[i]++; 726 break; 727 default: 728 break; 729 } 730 for (int j = 0; j < 10; j++) { 731 if (c[i] > 10) 732 throw c[i]; 733 } 734 } 735 if (c[9] > 10) 736 throw c[9]; // OK 737 738 #pragma omp parallel 739 #pragma omp for 740 for (int i = 0; i < 10; ++i) { 741 struct S { 742 void g() { throw 0; } 743 }; 744 } 745 } 746 747 void test_loop_firstprivate_lastprivate() { 748 S s(4); 749 #pragma omp parallel 750 #pragma omp for lastprivate(s) firstprivate(s) 751 for (int i = 0; i < 16; ++i) 752 ; 753 } 754 755 void test_ordered() { 756 #pragma omp parallel 757 #pragma omp for ordered ordered // expected-error {{directive '#pragma omp for' cannot contain more than one 'ordered' clause}} 758 for (int i = 0; i < 16; ++i) 759 ; 760 } 761 762 void test_nowait() { 763 #pragma omp parallel 764 #pragma omp for nowait nowait // expected-error {{directive '#pragma omp for' cannot contain more than one 'nowait' clause}} 765 for (int i = 0; i < 16; ++i) 766 ; 767 } 768