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