brintos

brintos / llvm-project-archived public Read only

0
0
Text · 29.0 KiB · 8bfddbf Raw
722 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 simd29  for (int i = 0; i < 10; i += 1) {30    c[i] = a[i] + b[i];31  }32#pragma omp target33#pragma omp teams distribute simd34  for (char i = 0; i < 10; i++) {35    c[i] = a[i] + b[i];36  }37#pragma omp target38#pragma omp teams distribute simd39  for (char i = 0; i < 10; i += '\1') {40    c[i] = a[i] + b[i];41  }42#pragma omp target43#pragma omp teams distribute simd44  for (long long i = 0; i < 10; i++) {45    c[i] = a[i] + b[i];46  }47#pragma omp target48#pragma omp teams distribute simd49// 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 simd55  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 simd60// 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 simd66// 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 simd72// 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 simd77// 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 simd83// 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 simd89// 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 simd95// 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 simd102// 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 simd108// 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 simd114// 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 simd120// 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 simd127// 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 simd133// 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 simd139// 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 simd146  for (int i = 11; i > 10; i--)147    c[i] = a[i];148 149// Ok.150#pragma omp target151#pragma omp teams distribute simd152  for (int i = 0; i < 10; ++i)153    c[i] = a[i];154 155// Ok.156#pragma omp target157#pragma omp teams distribute simd158  for (ii = 0; ii < 10; ++ii)159    c[ii] = a[ii];160 161#pragma omp target162#pragma omp teams distribute simd163// 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 simd169// 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 simd177  for (ii = 0; ii < 10; ii = ii + ii)178    c[ii] = a[ii];179 180#pragma omp target181#pragma omp teams distribute simd182// 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 simd189  for (ii = 0; ii < 10; ii = ii + (int)1.1f)190    c[ii] = a[ii];191 192#pragma omp target193#pragma omp teams distribute simd194// 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 simd200// 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 simd207// 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 simd213// 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 simd220// 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 simd226// 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 simd232// 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 simd239// 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 simd246// 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 simd253// 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 simd260// 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 simd267// 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 simd274// 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 simd281// 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 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 target293#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 target299#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 target305#pragma omp teams distribute simd306// 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 target312#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 target319#pragma omp teams distribute simd320// 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 target326#pragma omp teams distribute simd327// 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 target335#pragma omp teams distribute simd336  for (int(*p)[4] = lb; p < lb + 8; ++p) {337  }338 339#pragma omp target340#pragma omp teams distribute simd341// 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.349namespace std {350struct random_access_iterator_tag {};351template <class Iter>352struct iterator_traits {353  typedef typename Iter::difference_type difference_type;354  typedef typename Iter::iterator_category iterator_category;355};356template <class Iter>357typename iterator_traits<Iter>::difference_type358distance(Iter first, Iter last) { return first - last; }359}360class Iter0 {361public: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}}370int operator-(Iter0 a, Iter0 b) { return 0; }371class Iter1 {372public: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};380class GoodIter {381public: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}}400int 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}}402GoodIter 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}}405GoodIter 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}}407GoodIter 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}}410GoodIter 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}}412GoodIter operator+(int v, GoodIter a) { return GoodIter(); }413 414int test_with_random_access_iterator() {415  GoodIter begin, end;416  Iter0 begin0, end0;417#pragma omp target418#pragma omp teams distribute simd419  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 target422#pragma omp teams distribute simd423// 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 target427#pragma omp teams distribute simd428  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 target431#pragma omp teams distribute simd432// 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 target436#pragma omp teams distribute simd437// 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 target441#pragma omp teams distribute simd442// 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 target446#pragma omp teams distribute simd447// 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 target451#pragma omp teams distribute simd452  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 target455#pragma omp teams distribute simd456// 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 target461#pragma omp teams distribute simd462// 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 target466#pragma omp teams distribute simd467  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 target470#pragma omp teams distribute simd471// 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 target475#pragma omp teams distribute simd476// 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 target480#pragma omp teams distribute simd481// 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 target485#pragma omp teams distribute simd486// 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 target491#pragma omp teams distribute simd492  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 target495#pragma omp teams distribute simd496// 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 target500#pragma omp teams distribute simd501// 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 target506#pragma omp teams distribute simd507// 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 target511#pragma omp teams distribute simd512// expected-error@+1 {{invalid operands to binary expression ('Iter0' and 'int')}}513  for (Iter0 I = begin0; I < end0; ++I)514    ++I;515#pragma omp target516#pragma omp teams distribute simd517// 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 target524#pragma omp teams distribute simd525// 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 target530#pragma omp teams distribute simd531// 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 target536#pragma omp teams distribute simd537// 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 546template <typename IT, int ST>547class TC {548public:549  int dotest_lt(IT begin, IT end) {550#pragma omp target551#pragma omp teams distribute simd552// 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 target558#pragma omp teams distribute simd559// 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 target565#pragma omp teams distribute simd566    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};575template <typename IT, int ST = 0>576int dotest_gt(IT begin, IT end) {577#pragma omp target578#pragma omp teams distribute simd579// 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 target585#pragma omp teams distribute simd586// 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 target593#pragma omp teams distribute simd594// 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 target601#pragma omp teams distribute simd602  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 607void 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 617void test_loop_break() {618  const int N = 100;619  float a[N], b[N], c[N];620#pragma omp target621#pragma omp teams distribute simd622  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 loop627    }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 target643#pragma omp teams distribute simd644  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; // OK650        }651      }652    }653  }654}655 656void test_loop_eh() {657  const int N = 100;658  float a[N], b[N], c[N];659#pragma omp target660#pragma omp teams distribute simd661  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]; // OK688 689#pragma omp target690#pragma omp teams distribute simd691  for (int i = 0; i < 10; ++i) {692    struct S {693      void g() { throw 0; }694    };695  }696}697 698void 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 target702#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 707void test_ordered() {708#pragma omp target709#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 714void test_nowait() {715#pragma omp target716// 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