720 lines · cpp
1// RUN: %clang_cc1 -fsyntax-only -fopenmp -fopenmp-version=45 -x c++ -std=c++11 -fexceptions -fcxx-exceptions -verify=expected,omp4 %s -Wuninitialized2// RUN: %clang_cc1 -fsyntax-only -fopenmp -x c++ -std=c++11 -fexceptions -fcxx-exceptions -verify=expected,omp5 %s -Wuninitialized3 4// RUN: %clang_cc1 -fsyntax-only -fopenmp-simd -fopenmp-version=45 -x c++ -std=c++11 -fexceptions -fcxx-exceptions -verify=expected,omp4 %s -Wuninitialized5// RUN: %clang_cc1 -fsyntax-only -fopenmp-simd -x c++ -std=c++11 -fexceptions -fcxx-exceptions -verify=expected,omp5 %s -Wuninitialized6 7class S {8 int a;9 S() : a(0) {} // expected-note {{implicitly declared private here}}10 11public:12 S(int v) : a(v) {}13 S(const S &s) : a(s.a) {}14};15 16static int sii;17// expected-note@+1 {{defined as threadprivate or thread local}}18#pragma omp threadprivate(sii)19static int globalii;20 21int 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 target28#pragma omp teams distribute parallel for29 for (int i = 0; i < 10; i += 1) {30 c[i] = a[i] + b[i];31 }32#pragma omp target33#pragma omp teams distribute parallel for34 for (char i = 0; i < 10; i++) {35 c[i] = a[i] + b[i];36 }37#pragma omp target38#pragma omp teams distribute parallel for39 for (char i = 0; i < 10; i += '\1') {40 c[i] = a[i] + b[i];41 }42#pragma omp target43#pragma omp teams distribute parallel for44 for (long long i = 0; i < 10; i++) {45 c[i] = a[i] + b[i];46 }47#pragma omp target48#pragma omp teams distribute parallel for49// 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 target54#pragma omp teams distribute parallel for55 for (long long i = 0; i < 'z'; i += 1u) {56 c[i] = a[i] + b[i];57 }58#pragma omp target59#pragma omp teams distribute parallel for60// 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 target65#pragma omp teams distribute parallel for66// 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 target71#pragma omp teams distribute parallel for72// 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 target76#pragma omp teams distribute parallel for77// 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 target82#pragma omp teams distribute parallel for83// 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 target88#pragma omp teams distribute parallel for89// 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 target94#pragma omp teams distribute parallel for95// 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 target101#pragma omp teams distribute parallel for102// 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 target107#pragma omp teams distribute parallel for108// Ok to skip parenthesises.109 for (((ii)) = 0; ii < 10; ++ii)110 c[ii] = a[ii];111 112#pragma omp target113#pragma omp teams distribute parallel for114// 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 target119#pragma omp teams distribute parallel for120// 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 target126#pragma omp teams distribute parallel for127// 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 target132#pragma omp teams distribute parallel for133// 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 target138#pragma omp teams distribute parallel for139// 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 target145#pragma omp teams distribute parallel for146 for (int i = 11; i > 10; i--)147 c[i] = a[i];148 149// Ok.150#pragma omp target151#pragma omp teams distribute parallel for152 for (int i = 0; i < 10; ++i)153 c[i] = a[i];154 155// Ok.156#pragma omp target157#pragma omp teams distribute parallel for158 for (ii = 0; ii < 10; ++ii)159 c[ii] = a[ii];160 161#pragma omp target162#pragma omp teams distribute parallel for163// 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 target168#pragma omp teams distribute parallel for169// 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 incr174// is really loop-invariant).175#pragma omp target176#pragma omp teams distribute parallel for177 for (ii = 0; ii < 10; ii = ii + ii)178 c[ii] = a[ii];179 180#pragma omp target181#pragma omp teams distribute parallel for182// 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 target188#pragma omp teams distribute parallel for189 for (ii = 0; ii < 10; ii = ii + (int)1.1f)190 c[ii] = a[ii];191 192#pragma omp target193#pragma omp teams distribute parallel for194// 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 target199#pragma omp teams distribute parallel for200// 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 target206#pragma omp teams distribute parallel for207// 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 target212#pragma omp teams distribute parallel for213// 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 target219#pragma omp teams distribute parallel for220// 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 target225#pragma omp teams distribute parallel for226// 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 target231#pragma omp teams distribute parallel for232// 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 target238#pragma omp teams distribute parallel for239// 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 target245#pragma omp teams distribute parallel for246// 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 target252#pragma omp teams distribute parallel for253// 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 target259#pragma omp teams distribute parallel for260// 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 target266#pragma omp teams distribute parallel for267// 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 target273#pragma omp teams distribute parallel for274// 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 target280#pragma omp teams distribute parallel for281// 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 target287#pragma omp teams distribute parallel for firstprivate(ii) // expected-note {{defined as firstprivate}}288// expected-error@+1 {{loop iteration variable in the associated loop of 'omp teams distribute parallel for' directive may not be firstprivate, predetermined as private}}289 for (ii = 0; ii < 10; ii++)290 c[ii] = a[ii];291 292#pragma omp target293#pragma omp teams distribute parallel for private(ii) // OK294 for (ii = 0; ii < 10; ii++)295 c[ii] = a[ii];296 297#pragma omp target298#pragma omp teams distribute parallel for lastprivate(ii) // OK299 for (ii = 0; ii < 10; ii++)300 c[ii] = a[ii];301 302#pragma omp target303#pragma omp teams distribute parallel for304// expected-error@+1 {{loop iteration variable in the associated loop of 'omp teams distribute parallel for' directive may not be threadprivate or thread local, predetermined as private}}305 for (sii = 0; sii < 10; sii++)306 c[sii] = a[sii];307 308 {309#pragma omp target310#pragma omp teams distribute parallel for collapse(2)311 for (ii = 0; ii < 10; ii += 1)312 for (globalii = 0; globalii < 10; globalii += 1)313 c[globalii] += a[globalii] + ii;314 }315 316#pragma omp target317#pragma omp teams distribute parallel for318// omp4-error@+1 {{statement after '#pragma omp teams distribute parallel for' must be a for loop}}319 for (auto &item : a) {320 item = item + 1;321 }322 323#pragma omp target324#pragma omp teams distribute parallel for325// expected-note@+2 {{loop step is expected to be positive due to this condition}}326// expected-error@+1 {{increment expression must cause 'i' to increase on each iteration of OpenMP for loop}}327 for (unsigned i = 9; i < 10; i--) {328 c[i] = a[i] + b[i];329 }330 331 int(*lb)[4] = nullptr;332#pragma omp target333#pragma omp teams distribute parallel for334 for (int(*p)[4] = lb; p < lb + 8; ++p) {335 }336 337#pragma omp target338#pragma omp teams distribute parallel for339// expected-warning@+1 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}340 for (int a{0}; a < 10; ++a) {341 }342 343 return 0;344}345 346// Iterators allowed in openmp for-loops.347namespace std {348struct random_access_iterator_tag {};349template <class Iter>350struct iterator_traits {351 typedef typename Iter::difference_type difference_type;352 typedef typename Iter::iterator_category iterator_category;353};354template <class Iter>355typename iterator_traits<Iter>::difference_type356distance(Iter first, Iter last) { return first - last; }357}358class Iter0 {359public:360 Iter0() {}361 Iter0(const Iter0 &) {}362 Iter0 operator++() { return *this; }363 Iter0 operator--() { return *this; }364 bool operator<(Iter0 a) { return true; }365};366// expected-note@+2 {{candidate function not viable: no known conversion from 'GoodIter' to 'Iter0' for 1st argument}}367// expected-note@+1 2 {{candidate function not viable: no known conversion from 'Iter1' to 'Iter0' for 1st argument}}368int operator-(Iter0 a, Iter0 b) { return 0; }369class Iter1 {370public:371 Iter1(float f = 0.0f, double d = 0.0) {}372 Iter1(const Iter1 &) {}373 Iter1 operator++() { return *this; }374 Iter1 operator--() { return *this; }375 bool operator<(Iter1 a) { return true; }376 bool operator>=(Iter1 a) { return false; }377};378class GoodIter {379public:380 GoodIter() {}381 GoodIter(const GoodIter &) {}382 GoodIter(int fst, int snd) {}383 GoodIter &operator=(const GoodIter &that) { return *this; }384 GoodIter &operator=(const Iter0 &that) { return *this; }385 GoodIter &operator+=(int x) { return *this; }386 explicit GoodIter(void *) {}387 GoodIter operator++() { return *this; }388 GoodIter operator--() { return *this; }389 bool operator!() { return true; }390 bool operator<(GoodIter a) { return true; }391 bool operator<=(GoodIter a) { return true; }392 bool operator>=(GoodIter a) { return false; }393 typedef int difference_type;394 typedef std::random_access_iterator_tag iterator_category;395};396// expected-note@+2 {{candidate function not viable: no known conversion from 'const Iter0' to 'GoodIter' for 2nd argument}}397// expected-note@+1 2 {{candidate function not viable: no known conversion from 'Iter1' to 'GoodIter' for 1st argument}}398int operator-(GoodIter a, GoodIter b) { return 0; }399// expected-note@+1 3 {{candidate function not viable: requires single argument 'a', but 2 arguments were provided}}400GoodIter operator-(GoodIter a) { return a; }401// expected-note@+2 {{candidate function not viable: no known conversion from 'const Iter0' to 'int' for 2nd argument}}402// expected-note@+1 2 {{candidate function not viable: no known conversion from 'Iter1' to 'GoodIter' for 1st argument}}403GoodIter operator-(GoodIter a, int v) { return GoodIter(); }404// expected-note@+1 2 {{candidate function not viable: no known conversion from 'Iter0' to 'GoodIter' for 1st argument}}405GoodIter operator+(GoodIter a, int v) { return GoodIter(); }406// expected-note@+2 {{candidate function not viable: no known conversion from 'GoodIter' to 'int' for 1st argument}}407// expected-note@+1 2 {{candidate function not viable: no known conversion from 'Iter1' to 'int' for 1st argument}}408GoodIter operator-(int v, GoodIter a) { return GoodIter(); }409// expected-note@+1 2 {{candidate function not viable: no known conversion from 'Iter0' to 'int' for 1st argument}}410GoodIter operator+(int v, GoodIter a) { return GoodIter(); }411 412int test_with_random_access_iterator() {413 GoodIter begin, end;414 Iter0 begin0, end0;415#pragma omp target416#pragma omp teams distribute parallel for417 for (GoodIter I = begin; I < end; ++I) // expected-warning 2 {{type 'GoodIter' is not trivially copyable and not guaranteed to be mapped correctly}}418 ++I;419#pragma omp target420#pragma omp teams distribute parallel for421// expected-error@+1 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}422 for (GoodIter &I = begin; I < end; ++I)423 ++I;424#pragma omp target425#pragma omp teams distribute parallel for426 for (GoodIter I = begin; I >= end; --I) // expected-warning 2 {{type 'GoodIter' is not trivially copyable and not guaranteed to be mapped correctly}}427 ++I;428#pragma omp target429#pragma omp teams distribute parallel for430// expected-warning@+1 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}431 for (GoodIter I(begin); I < end; ++I) // expected-warning 2 {{type 'GoodIter' is not trivially copyable and not guaranteed to be mapped correctly}}432 ++I;433#pragma omp target434#pragma omp teams distribute parallel for435// expected-warning@+1 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}436 for (GoodIter I(nullptr); I < end; ++I) // expected-warning {{type 'GoodIter' is not trivially copyable and not guaranteed to be mapped correctly}}437 ++I;438#pragma omp target439#pragma omp teams distribute parallel for440// expected-warning@+1 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}441 for (GoodIter I(0); I < end; ++I) // expected-warning {{type 'GoodIter' is not trivially copyable and not guaranteed to be mapped correctly}}442 ++I;443#pragma omp target444#pragma omp teams distribute parallel for445// expected-warning@+1 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}446 for (GoodIter I(1, 2); I < end; ++I) // expected-warning {{type 'GoodIter' is not trivially copyable and not guaranteed to be mapped correctly}}447 ++I;448#pragma omp target449#pragma omp teams distribute parallel for450 for (begin = GoodIter(0); begin < end; ++begin) // expected-warning {{type 'GoodIter' is not trivially copyable and not guaranteed to be mapped correctly}}451 ++begin;452#pragma omp target453#pragma omp teams distribute parallel for454// expected-error@+2 {{invalid operands to binary expression ('GoodIter' and 'const Iter0')}}455// expected-error@+1 {{could not calculate number of iterations calling 'operator-' with upper and lower loop bounds}}456 for (begin = begin0; begin < end; ++begin)457 ++begin;458#pragma omp target459#pragma omp teams distribute parallel for460// expected-error@+1 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}461 for (++begin; begin < end; ++begin)462 ++begin;463#pragma omp target464#pragma omp teams distribute parallel for465 for (begin = end; begin < end; ++begin) // expected-warning {{type 'GoodIter' is not trivially copyable and not guaranteed to be mapped correctly}}466 ++begin;467#pragma omp target468#pragma omp teams distribute parallel for469// 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'}}470 for (GoodIter I = begin; I - I; ++I)471 ++I;472#pragma omp target473#pragma omp teams distribute parallel for474// 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'}}475 for (GoodIter I = begin; begin < end; ++I)476 ++I;477#pragma omp target478#pragma omp teams distribute parallel for479// 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'}}480 for (GoodIter I = begin; !I; ++I)481 ++I;482#pragma omp target483#pragma omp teams distribute parallel for484// expected-note@+2 {{loop step is expected to be negative due to this condition}}485// expected-error@+1 {{increment expression must cause 'I' to decrease on each iteration of OpenMP for loop}}486 for (GoodIter I = begin; I >= end; I = I + 1)487 ++I;488#pragma omp target489#pragma omp teams distribute parallel for490 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}}491 ++I;492#pragma omp target493#pragma omp teams distribute parallel for494// expected-error@+1 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'I'}}495 for (GoodIter I = begin; I >= end; I = -I)496 ++I;497#pragma omp target498#pragma omp teams distribute parallel for499// expected-note@+2 {{loop step is expected to be negative due to this condition}}500// expected-error@+1 {{increment expression must cause 'I' to decrease on each iteration of OpenMP for loop}}501 for (GoodIter I = begin; I >= end; I = 2 + I)502 ++I;503#pragma omp target504#pragma omp teams distribute parallel for505// expected-error@+1 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'I'}}506 for (GoodIter I = begin; I >= end; I = 2 - I)507 ++I;508#pragma omp target509#pragma omp teams distribute parallel for510// expected-error@+1 {{invalid operands to binary expression ('Iter0' and 'int')}}511 for (Iter0 I = begin0; I < end0; ++I)512 ++I;513#pragma omp target514#pragma omp teams distribute parallel for515// Initializer is constructor without params.516// expected-error@+2 {{invalid operands to binary expression ('Iter0' and 'int')}}517// expected-warning@+1 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}518 for (Iter0 I; I < end0; ++I)519 ++I;520 Iter1 begin1, end1;521#pragma omp target522#pragma omp teams distribute parallel for523// expected-error@+2 {{invalid operands to binary expression ('Iter1' and 'Iter1')}}524// expected-error@+1 {{could not calculate number of iterations calling 'operator-' with upper and lower loop bounds}}525 for (Iter1 I = begin1; I < end1; ++I)526 ++I;527#pragma omp target528#pragma omp teams distribute parallel for529// expected-note@+2 {{loop step is expected to be negative due to this condition}}530// expected-error@+1 {{increment expression must cause 'I' to decrease on each iteration of OpenMP for loop}}531 for (Iter1 I = begin1; I >= end1; ++I)532 ++I;533#pragma omp target534#pragma omp teams distribute parallel for535// expected-error@+4 {{invalid operands to binary expression ('Iter1' and 'float')}}536// expected-error@+3 {{could not calculate number of iterations calling 'operator-' with upper and lower loop bounds}}537// Initializer is constructor with all default params.538// expected-warning@+1 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}539 for (Iter1 I; I < end1; ++I) {540 }541 return 0;542}543 544template <typename IT, int ST>545class TC {546public:547 int dotest_lt(IT begin, IT end) {548#pragma omp target549#pragma omp teams distribute parallel for550// expected-note@+2 {{loop step is expected to be positive due to this condition}}551// expected-error@+1 {{increment expression must cause 'I' to increase on each iteration of OpenMP for loop}}552 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}}553 ++I;554 }555#pragma omp target556#pragma omp teams distribute parallel for557// expected-note@+2 {{loop step is expected to be positive due to this condition}}558// expected-error@+1 {{increment expression must cause 'I' to increase on each iteration of OpenMP for loop}}559 for (IT I = begin; I <= end; I += ST) { // expected-warning 2 {{type 'GoodIter' is not trivially copyable and not guaranteed to be mapped correctly}}560 ++I;561 }562#pragma omp target563#pragma omp teams distribute parallel for564 for (IT I = begin; I < end; ++I) { // expected-warning 4 {{type 'GoodIter' is not trivially copyable and not guaranteed to be mapped correctly}}565 ++I;566 }567 }568 569 static IT step() {570 return IT(ST);571 }572};573template <typename IT, int ST = 0>574int dotest_gt(IT begin, IT end) {575#pragma omp target576#pragma omp teams distribute parallel for577// expected-note@+2 2 {{loop step is expected to be negative due to this condition}}578// expected-error@+1 2 {{increment expression must cause 'I' to decrease on each iteration of OpenMP for loop}}579 for (IT I = begin; I >= end; I = I + ST) {580 ++I;581 }582#pragma omp target583#pragma omp teams distribute parallel for584// expected-note@+2 2 {{loop step is expected to be negative due to this condition}}585// expected-error@+1 2 {{increment expression must cause 'I' to decrease on each iteration of OpenMP for loop}}586 for (IT I = begin; I >= end; I += ST) {587 ++I;588 }589 590#pragma omp target591#pragma omp teams distribute parallel for592// expected-note@+2 {{loop step is expected to be negative due to this condition}}593// expected-error@+1 {{increment expression must cause 'I' to decrease on each iteration of OpenMP for loop}}594 for (IT I = begin; I >= end; ++I) {595 ++I;596 }597 598#pragma omp target599#pragma omp teams distribute parallel for600 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}}601 ++I;602 }603}604 605void test_with_template() {606 GoodIter begin, end;607 TC<GoodIter, 100> t1;608 TC<GoodIter, -100> t2;609 t1.dotest_lt(begin, end); // expected-note {{in instantiation of member function 'TC<GoodIter, 100>::dotest_lt' requested here}}610 t2.dotest_lt(begin, end); // expected-note {{in instantiation of member function 'TC<GoodIter, -100>::dotest_lt' requested here}}611 dotest_gt(begin, end); // expected-note {{in instantiation of function template specialization 'dotest_gt<GoodIter, 0>' requested here}}612 dotest_gt<unsigned, 10>(0, 100); // expected-note {{in instantiation of function template specialization 'dotest_gt<unsigned int, 10>' requested here}}613}614 615void test_loop_break() {616 const int N = 100;617 float a[N], b[N], c[N];618#pragma omp target619#pragma omp teams distribute parallel for620 for (int i = 0; i < 10; i++) {621 c[i] = a[i] + b[i];622 for (int j = 0; j < 10; ++j) {623 if (a[i] > b[j])624 break; // OK in nested loop625 }626 switch (i) {627 case 1:628 b[i]++;629 break;630 default:631 break;632 }633 if (c[i] > 10)634 break; // expected-error {{'break' statement cannot be used in OpenMP for loop}}635 636 if (c[i] > 11)637 break; // expected-error {{'break' statement cannot be used in OpenMP for loop}}638 }639 640#pragma omp target641#pragma omp teams distribute parallel for642 for (int i = 0; i < 10; i++) {643 for (int j = 0; j < 10; j++) {644 c[i] = a[i] + b[i];645 if (c[i] > 10) {646 if (c[i] < 20) {647 break; // OK648 }649 }650 }651 }652}653 654void test_loop_eh() {655 const int N = 100;656 float a[N], b[N], c[N];657#pragma omp target658#pragma omp teams distribute parallel for659 for (int i = 0; i < 10; i++) {660 c[i] = a[i] + b[i];661 try { // OK662 for (int j = 0; j < 10; ++j) {663 if (a[i] > b[j])664 throw a[i]; // OK665 }666 throw a[i]; // OK667 } catch (float f) {668 if (f > 0.1)669 throw a[i]; // OK670 return; // expected-error {{cannot return from OpenMP region}}671 }672 switch (i) {673 case 1:674 b[i]++;675 break;676 default:677 break;678 }679 for (int j = 0; j < 10; j++) {680 if (c[i] > 10)681 throw c[i]; // OK682 }683 }684 if (c[9] > 10)685 throw c[9]; // OK686 687#pragma omp target688#pragma omp teams distribute parallel for689 for (int i = 0; i < 10; ++i) {690 struct S {691 void g() { throw 0; }692 };693 }694}695 696void test_loop_firstprivate_lastprivate() {697 S s(4);698// expected-error@+2 {{lastprivate variable cannot be firstprivate}} expected-note@+2 {{defined as lastprivate}}699#pragma omp target700#pragma omp teams distribute parallel for 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}}701 for (int i = 0; i < 16; ++i)702 ;703}704 705void test_ordered() {706#pragma omp target707#pragma omp teams distribute parallel for ordered // expected-error {{unexpected OpenMP clause 'ordered' in directive '#pragma omp teams distribute parallel for'}}708 for (int i = 0; i < 16; ++i)709 ;710}711 712void test_nowait() {713#pragma omp target714// expected-error@+1 2 {{unexpected OpenMP clause 'nowait' in directive '#pragma omp teams distribute parallel for'}}715#pragma omp teams distribute parallel for nowait nowait // expected-error {{directive '#pragma omp teams distribute parallel for' cannot contain more than one 'nowait' clause}}716 for (int i = 0; i < 16; ++i)717 ;718}719 720