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