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