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