brintos

brintos / llvm-project-archived public Read only

0
0
Text · 29.3 KiB · e56c7df Raw
801 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 S5 {8  int a;9  S5() : a(0) {}10 11public:12  S5(int v) : a(v) {}13  S5 &operator=(S5 &s) {14#pragma omp target15#pragma omp teams16#pragma omp distribute simd17    for (int k = 0; k < s.a; ++k) // expected-warning {{type 'S5' is not trivially copyable and not guaranteed to be mapped correctly}}18      ++s.a;19    return *this;20  }21};22 23static int sii;24// expected-note@+1 {{defined as threadprivate or thread local}}25#pragma omp threadprivate(sii)26static int globalii;27 28int test_iteration_spaces() {29  const int N = 100;30  float a[N], b[N], c[N];31  int ii, jj, kk;32  float fii;33  double dii;34  #pragma omp target35  #pragma omp teams36  #pragma omp distribute simd37  for (int i = 0; i < 10; i+=1) {38    c[i] = a[i] + b[i];39  }40  #pragma omp target41  #pragma omp teams42  #pragma omp distribute simd43  for (char i = 0; i < 10; i++) {44    c[i] = a[i] + b[i];45  }46  #pragma omp target47  #pragma omp teams48  #pragma omp distribute simd49  for (char i = 0; i < 10; i+='\1') {50    c[i] = a[i] + b[i];51  }52  #pragma omp target53  #pragma omp teams54  #pragma omp distribute simd55  for (long long i = 0; i < 10; i++) {56    c[i] = a[i] + b[i];57  }58  #pragma omp target59  #pragma omp teams60  // expected-error@+2 {{expression must have integral or unscoped enumeration type, not 'double'}}61  #pragma omp distribute simd62  for (long long i = 0; i < 10; i+=1.5) {63    c[i] = a[i] + b[i];64  }65  #pragma omp target66  #pragma omp teams67  #pragma omp distribute simd68  for (long long i = 0; i < 'z'; i+=1u) {69    c[i] = a[i] + b[i];70  }71  #pragma omp target72  #pragma omp teams73  // expected-error@+2 {{variable must be of integer or random access iterator type}}74  #pragma omp distribute simd75  for (float fi = 0; fi < 10.0; fi++) {76    c[(int)fi] = a[(int)fi] + b[(int)fi];77  }78  #pragma omp target79  #pragma omp teams80  // expected-error@+2 {{variable must be of integer or random access iterator type}}81  #pragma omp distribute simd82  for (double fi = 0; fi < 10.0; fi++) {83    c[(int)fi] = a[(int)fi] + b[(int)fi];84  }85  #pragma omp target86  #pragma omp teams87  // expected-error@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}88  #pragma omp distribute simd89  for (int &ref = ii; ref < 10; ref++) {90  }91  #pragma omp target92  #pragma omp teams93  // expected-error@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}94  #pragma omp distribute simd95  for (int i; i < 10; i++)96    c[i] = a[i];97 98  #pragma omp target99  #pragma omp teams100  // expected-error@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}101  #pragma omp distribute simd102  for (int i = 0, j = 0; i < 10; ++i)103    c[i] = a[i];104 105  #pragma omp target106  #pragma omp teams107  // expected-error@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}108  #pragma omp distribute simd109  for (;ii < 10; ++ii)110    c[ii] = a[ii];111 112  #pragma omp target113  #pragma omp teams114  // expected-warning@+3 {{expression result unused}}115  // expected-error@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}116  #pragma omp distribute simd117  for (ii + 1;ii < 10; ++ii)118    c[ii] = a[ii];119 120  #pragma omp target121  #pragma omp teams122  // expected-error@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}123  #pragma omp distribute simd124  for (c[ii] = 0;ii < 10; ++ii)125    c[ii] = a[ii];126 127  // Ok to skip parenthesises.128  #pragma omp target129  #pragma omp teams130  #pragma omp distribute simd131  for (((ii)) = 0;ii < 10; ++ii)132    c[ii] = a[ii];133 134  #pragma omp target135  #pragma omp teams136  // 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'}}137  #pragma omp distribute simd138  for (int i = 0; i; i++)139    c[i] = a[i];140 141  #pragma omp target142  #pragma omp teams143  // omp4-error@+3 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', or '>=') of loop variable 'i'}} omp5-error@+3 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', '>=', or '!=') of loop variable 'i'}}144  // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'i'}}145  #pragma omp distribute simd146  for (int i = 0; jj < kk; ii++)147    c[i] = a[i];148 149  #pragma omp target150  #pragma omp teams151  // 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'}}152  #pragma omp distribute simd153  for (int i = 0; !!i; i++)154    c[i] = a[i];155 156  #pragma omp target157  #pragma omp teams158  // omp4-error@+2 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', or '>=') of loop variable 'i'}}159  #pragma omp distribute simd160  for (int i = 0; i != 1; i++)161    c[i] = a[i];162 163  #pragma omp target164  #pragma omp teams165  // 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'}}166  #pragma omp distribute simd167  for (int i = 0; ; i++)168    c[i] = a[i];169 170  // Ok.171  #pragma omp target172  #pragma omp teams173  #pragma omp distribute simd174  for (int i = 11; i > 10; i--)175    c[i] = a[i];176 177  // Ok.178  #pragma omp target179  #pragma omp teams180  #pragma omp distribute simd181  for (int i = 0; i < 10; ++i)182    c[i] = a[i];183 184    // Ok.185  #pragma omp target186  #pragma omp teams187  #pragma omp distribute simd188  for (ii = 0; ii < 10; ++ii)189    c[ii] = a[ii];190 191  #pragma omp target192  #pragma omp teams193  // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'ii'}}194  #pragma omp distribute simd195  for (ii = 0; ii < 10; ++jj)196    c[ii] = a[jj];197 198  #pragma omp target199  #pragma omp teams200  // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'ii'}}201  #pragma omp distribute simd202  for (ii = 0; ii < 10; ++ ++ ii)203    c[ii] = a[ii];204 205  // Ok but undefined behavior (in general, cannot check that incr206  // is really loop-invariant).207  #pragma omp target208  #pragma omp teams209  #pragma omp distribute simd210  for (ii = 0; ii < 10; ii = ii + ii)211    c[ii] = a[ii];212 213  #pragma omp target214  #pragma omp teams215  // expected-error@+2 {{expression must have integral or unscoped enumeration type, not 'float'}}216  #pragma omp distribute simd217  for (ii = 0; ii < 10; ii = ii + 1.0f)218    c[ii] = a[ii];219 220  // Ok - step was converted to integer type.221  #pragma omp target222  #pragma omp teams223  #pragma omp distribute simd224  for (ii = 0; ii < 10; ii = ii + (int)1.1f)225    c[ii] = a[ii];226 227  #pragma omp target228  #pragma omp teams229  // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'ii'}}230  #pragma omp distribute simd231  for (ii = 0; ii < 10; jj = ii + 2)232    c[ii] = a[ii];233 234  #pragma omp target235  #pragma omp teams236  // expected-warning@+3 {{relational comparison result unused}}237  // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'ii'}}238  #pragma omp distribute simd239  for (ii = 0; ii < 10; jj > kk + 2)240    c[ii] = a[ii];241 242  #pragma omp target243  #pragma omp teams244  // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'ii'}}245  #pragma omp distribute simd246  for (ii = 0; ii < 10;)247    c[ii] = a[ii];248 249  #pragma omp target250  #pragma omp teams251  // expected-warning@+3 {{expression result unused}}252  // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'ii'}}253  #pragma omp distribute simd254  for (ii = 0; ii < 10; !ii)255    c[ii] = a[ii];256 257  #pragma omp target258  #pragma omp teams259  // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'ii'}}260  #pragma omp distribute simd261  for (ii = 0; ii < 10; ii ? ++ii : ++jj)262    c[ii] = a[ii];263 264  #pragma omp target265  #pragma omp teams266  // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'ii'}}267  #pragma omp distribute simd268  for (ii = 0; ii < 10; ii = ii < 10)269    c[ii] = a[ii];270 271  #pragma omp target272  #pragma omp teams273  // expected-note@+3 {{loop step is expected to be positive due to this condition}}274  // expected-error@+2 {{increment expression must cause 'ii' to increase on each iteration of OpenMP for loop}}275  #pragma omp distribute simd276  for (ii = 0; ii < 10; ii = ii + 0)277    c[ii] = a[ii];278 279  #pragma omp target280  #pragma omp teams281  // expected-note@+3 {{loop step is expected to be positive due to this condition}}282  // expected-error@+2 {{increment expression must cause 'ii' to increase on each iteration of OpenMP for loop}}283  #pragma omp distribute simd284  for (ii = 0; ii < 10; ii = ii + (int)(0.8 - 0.45))285    c[ii] = a[ii];286 287  #pragma omp target288  #pragma omp teams289  // expected-note@+3 {{loop step is expected to be positive due to this condition}}290  // expected-error@+2 {{increment expression must cause 'ii' to increase on each iteration of OpenMP for loop}}291  #pragma omp distribute simd292  for (ii = 0; (ii) < 10; ii-=25)293    c[ii] = a[ii];294 295  #pragma omp target296  #pragma omp teams297  // expected-note@+3 {{loop step is expected to be positive due to this condition}}298  // expected-error@+2 {{increment expression must cause 'ii' to increase on each iteration of OpenMP for loop}}299  #pragma omp distribute simd300  for (ii = 0; (ii < 10); ii-=0)301    c[ii] = a[ii];302 303  #pragma omp target304  #pragma omp teams305  // expected-note@+3 {{loop step is expected to be negative due to this condition}}306  // expected-error@+2 {{increment expression must cause 'ii' to decrease on each iteration of OpenMP for loop}}307  #pragma omp distribute simd308  for (ii = 0; ii > 10; (ii+=0))309    c[ii] = a[ii];310 311  #pragma omp target312  #pragma omp teams313  // expected-note@+3 {{loop step is expected to be positive due to this condition}}314  // expected-error@+2 {{increment expression must cause 'ii' to increase on each iteration of OpenMP for loop}}315  #pragma omp distribute simd316  for (ii = 0; ii < 10; (ii) = (1-1)+(ii))317    c[ii] = a[ii];318 319  #pragma omp target320  #pragma omp teams321  // expected-note@+3 {{loop step is expected to be negative due to this condition}}322  // expected-error@+2 {{increment expression must cause 'ii' to decrease on each iteration of OpenMP for loop}}323  #pragma omp distribute simd324  for ((ii = 0); ii > 10; (ii-=0))325    c[ii] = a[ii];326 327  #pragma omp target328  #pragma omp teams329  // expected-note@+3 {{loop step is expected to be positive due to this condition}}330  // expected-error@+2 {{increment expression must cause 'ii' to increase on each iteration of OpenMP for loop}}331  #pragma omp distribute simd332  for (ii = 0; (ii < 10); (ii-=0))333    c[ii] = a[ii];334 335  #pragma omp target336  #pragma omp teams337  // omp4-note@+2  {{defined as private}}338  // omp4-error@+2 {{loop iteration variable in the associated loop of 'omp distribute simd' directive may not be private, predetermined as linear}}339  #pragma omp distribute simd private(ii)340  for (ii = 0; ii < 10; ii++)341    c[ii] = a[ii];342 343  #pragma omp target344  #pragma omp teams345  // expected-error@+1 {{unexpected OpenMP clause 'shared' in directive '#pragma omp distribute simd'}}346  #pragma omp distribute simd shared(ii)347  for (ii = 0; ii < 10; ii++)348    c[ii] = a[ii];349 350  #pragma omp target351  #pragma omp teams352  #pragma omp distribute simd linear(ii)353  for (ii = 0; ii < 10; ii++)354    c[ii] = a[ii];355 356  #pragma omp target357  #pragma omp teams358  #pragma omp distribute simd lastprivate(ii) linear(jj) collapse(2) // expected-note {{defined as linear}}359  for (ii = 0; ii < 10; ii++)360  for (jj = 0; jj < 10; jj++) // expected-error {{loop iteration variable in the associated loop of 'omp distribute simd' directive may not be linear, predetermined as lastprivate}}361    c[ii] = a[jj];362 363 364  #pragma omp parallel365  {366    #pragma omp target367    #pragma omp teams368// expected-error@+2 {{loop iteration variable in the associated loop of 'omp distribute simd' directive may not be threadprivate or thread local, predetermined as linear}}369    #pragma omp distribute simd370    for (sii = 0; sii < 10; sii+=1)371      c[sii] = a[sii];372  }373 374  #pragma omp parallel375  {376    #pragma omp target377    #pragma omp teams378    #pragma omp distribute simd379    for (globalii = 0; globalii < 10; globalii+=1)380      c[globalii] = a[globalii];381  }382 383  #pragma omp parallel384  {385#pragma omp target386#pragma omp teams387#pragma omp distribute simd collapse(2)388    for (ii = 0; ii < 10; ii += 1)389    for (globalii = 0; globalii < 10; globalii += 1)390      c[globalii] += a[globalii] + ii;391  }392 393  #pragma omp target394  #pragma omp teams395  // omp4-error@+2 {{statement after '#pragma omp distribute simd' must be a for loop}}396  #pragma omp distribute simd397  for (auto &item : a) {398    item = item + 1;399  }400 401  #pragma omp target402  #pragma omp teams403  // expected-note@+3 {{loop step is expected to be positive due to this condition}}404  // expected-error@+2 {{increment expression must cause 'i' to increase on each iteration of OpenMP for loop}}405  #pragma omp distribute simd406  for (unsigned i = 9; i < 10; i--) {407    c[i] = a[i] + b[i];408  }409 410  int (*lb)[4] = nullptr;411  #pragma omp target412  #pragma omp teams413  #pragma omp distribute simd414  for (int (*p)[4] = lb; p < lb + 8; ++p) {415  }416 417  #pragma omp target418  #pragma omp teams419  // expected-warning@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}420  #pragma omp distribute simd421  for (int a{0}; a<10; ++a) {422  }423 424  return 0;425}426 427// Iterators allowed in openmp for-loops.428namespace std {429struct random_access_iterator_tag { };430template <class Iter> struct iterator_traits {431  typedef typename Iter::difference_type difference_type;432  typedef typename Iter::iterator_category iterator_category;433};434template <class Iter>435typename iterator_traits<Iter>::difference_type436distance(Iter first, Iter last) { return first - last; }437}438class Iter0 {439  public:440    Iter0() { }441    Iter0(const Iter0 &) { }442    Iter0 operator ++() { return *this; }443    Iter0 operator --() { return *this; }444    Iter0 operator + (int delta) { return *this; }445    bool operator <(Iter0 a) { return true; }446};447// expected-note@+1 2 {{candidate function not viable: no known conversion from 'Iter1' to 'Iter0' for 1st argument}}448int operator -(Iter0 a, Iter0 b) { return 0; }449class Iter1 {450  public:451    Iter1(float f=0.0f, double d=0.0) { }452    Iter1(const Iter1 &) { }453    Iter1 operator ++() { return *this; }454    Iter1 operator --() { return *this; }455    bool operator <(Iter1 a) { return true; }456    bool operator >=(Iter1 a) { return false; }457};458class GoodIter {459  public:460    GoodIter() { }461    GoodIter(const GoodIter &) { }462    GoodIter(int fst, int snd) { }463    GoodIter &operator =(const GoodIter &that) { return *this; }464    GoodIter &operator =(const Iter0 &that) { return *this; }465    GoodIter &operator +=(int x) { return *this; }466    explicit GoodIter(void *) { }467    GoodIter operator ++() { return *this; }468    GoodIter operator --() { return *this; }469    bool operator !() { return true; }470    bool operator <(GoodIter a) { return true; }471    bool operator <=(GoodIter a) { return true; }472    bool operator >=(GoodIter a) { return false; }473    typedef int difference_type;474    typedef std::random_access_iterator_tag iterator_category;475};476// expected-note@+1 2 {{candidate function not viable: no known conversion from 'Iter1' to 'GoodIter' for 1st argument}}477int operator -(GoodIter a, GoodIter b) { return 0; }478// expected-note@+1 2 {{candidate function not viable: requires single argument 'a', but 2 arguments were provided}}479GoodIter operator -(GoodIter a) { return a; }480// expected-note@+1 2 {{candidate function not viable: no known conversion from 'Iter1' to 'GoodIter' for 1st argument}}481GoodIter operator -(GoodIter a, int v) { return GoodIter(); }482GoodIter operator +(GoodIter a, int v) { return GoodIter(); }483// expected-note@+1 2 {{candidate function not viable: no known conversion from 'Iter1' to 'int' for 1st argument}}484GoodIter operator -(int v, GoodIter a) { return GoodIter(); }485GoodIter operator +(int v, GoodIter a) { return GoodIter(); }486 487int test_with_random_access_iterator() {488  GoodIter begin, end;489  Iter0 begin0, end0;490  #pragma omp target491  #pragma omp teams492  #pragma omp distribute simd493  for (GoodIter I = begin; I < end; ++I) // expected-warning 2 {{type 'GoodIter' is not trivially copyable and not guaranteed to be mapped correctly}}494    ++I;495  #pragma omp target496  #pragma omp teams497  // expected-error@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}498  #pragma omp distribute simd499  for (GoodIter &I = begin; I < end; ++I)500    ++I;501  #pragma omp target502  #pragma omp teams503  #pragma omp distribute simd504  for (GoodIter I = begin; I >= end; --I) // expected-warning 2 {{type 'GoodIter' is not trivially copyable and not guaranteed to be mapped correctly}}505    ++I;506  #pragma omp target507  #pragma omp teams508  // expected-warning@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}509  #pragma omp distribute simd510  for (GoodIter I(begin); I < end; ++I) // expected-warning 2 {{type 'GoodIter' is not trivially copyable and not guaranteed to be mapped correctly}}511    ++I;512  #pragma omp target513  #pragma omp teams514  // expected-warning@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}515  #pragma omp distribute simd516  for (GoodIter I(nullptr); I < end; ++I) // expected-warning {{type 'GoodIter' is not trivially copyable and not guaranteed to be mapped correctly}}517    ++I;518  #pragma omp target519  #pragma omp teams520  // expected-warning@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}521  #pragma omp distribute simd522  for (GoodIter I(0); I < end; ++I) // expected-warning {{type 'GoodIter' is not trivially copyable and not guaranteed to be mapped correctly}}523    ++I;524  #pragma omp target525  #pragma omp teams526  // expected-warning@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}527  #pragma omp distribute simd528  for (GoodIter I(1,2); I < end; ++I) // expected-warning {{type 'GoodIter' is not trivially copyable and not guaranteed to be mapped correctly}}529    ++I;530  #pragma omp target531  #pragma omp teams532  #pragma omp distribute simd533  for (begin = GoodIter(0); begin < end; ++begin) // expected-warning 2 {{type 'GoodIter' is not trivially copyable and not guaranteed to be mapped correctly}}534    ++begin;535  #pragma omp target536  #pragma omp teams537  #pragma omp distribute simd538  for (begin = GoodIter(1,2); begin < end; ++begin) // expected-warning 2 {{type 'GoodIter' is not trivially copyable and not guaranteed to be mapped correctly}}539    ++begin;540  #pragma omp target541  #pragma omp teams542  // expected-error@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}543  #pragma omp distribute simd544  for (++begin; begin < end; ++begin)545    ++begin;546  #pragma omp target547  #pragma omp teams548  #pragma omp distribute simd549  for (begin = end; begin < end; ++begin) // expected-warning 2 {{type 'GoodIter' is not trivially copyable and not guaranteed to be mapped correctly}}550    ++begin;551  #pragma omp target552  #pragma omp teams553  // 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'}}554  #pragma omp distribute simd555  for (GoodIter I = begin; I - I; ++I)556    ++I;557  #pragma omp target558  #pragma omp teams559  // 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'}}560  #pragma omp distribute simd561  for (GoodIter I = begin; begin < end; ++I)562    ++I;563  #pragma omp target564  #pragma omp teams565  // 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'}}566  #pragma omp distribute simd567  for (GoodIter I = begin; !I; ++I)568    ++I;569  #pragma omp target570  #pragma omp teams571  // expected-note@+3 {{loop step is expected to be negative due to this condition}}572  // expected-error@+2 {{increment expression must cause 'I' to decrease on each iteration of OpenMP for loop}}573  #pragma omp distribute simd574  for (GoodIter I = begin; I >= end; I = I + 1)575    ++I;576  #pragma omp target577  #pragma omp teams578  #pragma omp distribute simd579  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}}580    ++I;581  #pragma omp target582  #pragma omp teams583  // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'I'}}584  #pragma omp distribute simd585  for (GoodIter I = begin; I >= end; I = -I)586    ++I;587  #pragma omp target588  #pragma omp teams589  // expected-note@+3 {{loop step is expected to be negative due to this condition}}590  // expected-error@+2 {{increment expression must cause 'I' to decrease on each iteration of OpenMP for loop}}591  #pragma omp distribute simd592  for (GoodIter I = begin; I >= end; I = 2 + I)593    ++I;594  #pragma omp target595  #pragma omp teams596  // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'I'}}597  #pragma omp distribute simd598  for (GoodIter I = begin; I >= end; I = 2 - I)599    ++I;600  #pragma omp target601  #pragma omp teams602  #pragma omp distribute simd603  for (Iter0 I = begin0; I < end0; ++I) // expected-warning 2 {{type 'Iter0' is not trivially copyable and not guaranteed to be mapped correctly}}604    ++I;605 606  #pragma omp target607  #pragma omp teams608  // Initializer is constructor without params.609  // expected-warning@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}610  #pragma omp distribute simd611  for (Iter0 I; I < end0; ++I) // expected-warning {{type 'Iter0' is not trivially copyable and not guaranteed to be mapped correctly}}612    ++I;613 614  Iter1 begin1, end1;615  #pragma omp target616  #pragma omp teams617  // expected-error@+3 {{invalid operands to binary expression ('Iter1' and 'Iter1')}}618  // expected-error@+2 {{could not calculate number of iterations calling 'operator-' with upper and lower loop bounds}}619  #pragma omp distribute simd620  for (Iter1 I = begin1; I < end1; ++I)621    ++I;622  #pragma omp target623  #pragma omp teams624  // expected-note@+3 {{loop step is expected to be negative due to this condition}}625  // expected-error@+2 {{increment expression must cause 'I' to decrease on each iteration of OpenMP for loop}}626  #pragma omp distribute simd627  for (Iter1 I = begin1; I >= end1; ++I)628    ++I;629 630  // Initializer is constructor with all default params.631  #pragma omp target632  #pragma omp teams633  // expected-error@+4 {{invalid operands to binary expression ('Iter1' and 'float')}}634  // expected-error@+3 {{could not calculate number of iterations calling 'operator-' with upper and lower loop bounds}}635  // expected-warning@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}636  #pragma omp distribute simd637  for (Iter1 I; I < end1; ++I) {638  }639 640  return 0;641}642 643template <typename IT, int ST> class TC {644  public:645    int dotest_lt(IT begin, IT end) {646      // expected-note@+3 {{loop step is expected to be positive due to this condition}}647      // expected-error@+2 {{increment expression must cause 'I' to increase on each iteration of OpenMP for loop}}648      #pragma omp distribute simd649      for (IT I = begin; I < end; I = I + ST) {650        ++I;651      }652      #pragma omp target653      #pragma omp teams654      // expected-note@+3 {{loop step is expected to be positive due to this condition}}655      // expected-error@+2 {{increment expression must cause 'I' to increase on each iteration of OpenMP for loop}}656      #pragma omp distribute simd657      for (IT I = begin; I <= end; I += ST) { // expected-warning 2 {{type 'GoodIter' is not trivially copyable and not guaranteed to be mapped correctly}}658        ++I;659      }660      #pragma omp distribute simd661      for (IT I = begin; I < end; ++I) {662        ++I;663      }664    }665 666    static IT step() {667      return IT(ST);668    }669};670template <typename IT, int ST=0> int dotest_gt(IT begin, IT end) {671  #pragma omp target672  #pragma omp teams673  // expected-note@+3 2 {{loop step is expected to be negative due to this condition}}674  // expected-error@+2 2 {{increment expression must cause 'I' to decrease on each iteration of OpenMP for loop}}675  #pragma omp distribute simd676  for (IT I = begin; I >= end; I = I + ST) {677    ++I;678  }679  #pragma omp target680  #pragma omp teams681  // expected-note@+3 2 {{loop step is expected to be negative due to this condition}}682  // expected-error@+2 2 {{increment expression must cause 'I' to decrease on each iteration of OpenMP for loop}}683  #pragma omp distribute simd684  for (IT I = begin; I >= end; I += ST) {685    ++I;686  }687 688  #pragma omp target689  #pragma omp teams690  // expected-note@+3 {{loop step is expected to be negative due to this condition}}691  // expected-error@+2 {{increment expression must cause 'I' to decrease on each iteration of OpenMP for loop}}692  #pragma omp distribute simd693  for (IT I = begin; I >= end; ++I) {694    ++I;695  }696 697  #pragma omp target698  #pragma omp teams699  #pragma omp distribute simd700  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}}701    ++I;702  }703}704 705void test_with_template() {706  GoodIter begin, end;707  TC<GoodIter, 100> t1;708  TC<GoodIter, -100> t2;709  t1.dotest_lt(begin, end); // expected-note {{in instantiation of member function 'TC<GoodIter, 100>::dotest_lt' requested here}}710  t2.dotest_lt(begin, end); // expected-note {{in instantiation of member function 'TC<GoodIter, -100>::dotest_lt' requested here}}711  dotest_gt(begin, end); // expected-note {{in instantiation of function template specialization 'dotest_gt<GoodIter, 0>' requested here}}712  dotest_gt<unsigned, 10>(0, 100); // expected-note {{in instantiation of function template specialization 'dotest_gt<unsigned int, 10>' requested here}}713}714 715void test_loop_break() {716  const int N = 100;717  float a[N], b[N], c[N];718  #pragma omp target719  #pragma omp teams720  #pragma omp distribute simd721  for (int i = 0; i < 10; i++) {722    c[i] = a[i] + b[i];723    for (int j = 0; j < 10; ++j) {724      if (a[i] > b[j])725        break; // OK in nested loop726    }727    switch(i) {728      case 1:729        b[i]++;730        break;731      default:732        break;733    }734    if (c[i] > 10)735      break; // expected-error {{'break' statement cannot be used in OpenMP for loop}}736 737    if (c[i] > 11)738      break; // expected-error {{'break' statement cannot be used in OpenMP for loop}}739  }740 741  #pragma omp target742  #pragma omp teams743  #pragma omp distribute simd744  for (int i = 0; i < 10; i++) {745    for (int j = 0; j < 10; j++) {746      c[i] = a[i] + b[i];747      if (c[i] > 10) {748        if (c[i] < 20) {749          break; // OK750        }751      }752    }753  }754}755 756void test_loop_eh() {757  const int N = 100;758  float a[N], b[N], c[N];759  #pragma omp target760  #pragma omp teams761  #pragma omp distribute simd762  for (int i = 0; i < 10; i++) {763    c[i] = a[i] + b[i];764    try { // expected-error {{'try' statement cannot be used in OpenMP simd region}}765      for (int j = 0; j < 10; ++j) {766        if (a[i] > b[j])767          throw a[i]; // expected-error {{'throw' statement cannot be used in OpenMP simd region}}768      }769      throw a[i]; // expected-error {{'throw' statement cannot be used in OpenMP simd region}}770    }771    catch (float f) {772      if (f > 0.1)773        throw a[i]; // expected-error {{'throw' statement cannot be used in OpenMP simd region}}774      return; // expected-error {{cannot return from OpenMP region}}775    }776    switch(i) {777      case 1:778        b[i]++;779        break;780      default:781        break;782    }783    for (int j = 0; j < 10; j++) {784      if (c[i] > 10)785        throw c[i]; // expected-error {{'throw' statement cannot be used in OpenMP simd region}}786    }787  }788  if (c[9] > 10)789    throw c[9]; // OK790 791  #pragma omp target792  #pragma omp teams793  #pragma omp distribute simd794  for (int i = 0; i < 10; ++i) {795    struct S {796      void g() { throw 0; }797    };798  }799}800 801