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