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