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