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