1*2bfce22aSSaiyedul Islam // RUN: %clang_cc1 -fsyntax-only -fopenmp -fopenmp-version=45 -x c++ -std=c++11 -fexceptions -fcxx-exceptions -verify=expected,omp4 %s -Wuninitialized
214a388f4SAlexey Bataev // RUN: %clang_cc1 -fsyntax-only -fopenmp -fopenmp-version=50 -x c++ -std=c++11 -fexceptions -fcxx-exceptions -verify=expected,omp5 %s -Wuninitialized
314a388f4SAlexey Bataev 
4*2bfce22aSSaiyedul Islam // RUN: %clang_cc1 -fsyntax-only -fopenmp-simd -fopenmp-version=45 -x c++ -std=c++11 -fexceptions -fcxx-exceptions -verify=expected,omp4 %s -Wuninitialized
514a388f4SAlexey Bataev // RUN: %clang_cc1 -fsyntax-only -fopenmp-simd -fopenmp-version=50 -x c++ -std=c++11 -fexceptions -fcxx-exceptions -verify=expected,omp5 %s -Wuninitialized
614a388f4SAlexey Bataev 
714a388f4SAlexey Bataev class S {
814a388f4SAlexey Bataev   int a;
S()914a388f4SAlexey Bataev   S() : a(0) {}
1014a388f4SAlexey Bataev 
1114a388f4SAlexey Bataev public:
S(int v)1214a388f4SAlexey Bataev   S(int v) : a(v) {}
S(const S & s)1314a388f4SAlexey Bataev   S(const S &s) : a(s.a) {}
1414a388f4SAlexey Bataev };
1514a388f4SAlexey Bataev 
1614a388f4SAlexey Bataev static int sii;
1714a388f4SAlexey Bataev // expected-note@+1 {{defined as threadprivate or thread local}}
1814a388f4SAlexey Bataev #pragma omp threadprivate(sii)
1914a388f4SAlexey Bataev static int globalii;
2014a388f4SAlexey Bataev 
2114a388f4SAlexey Bataev // Currently, we cannot use "0" for global register variables.
2214a388f4SAlexey Bataev // register int reg0 __asm__("0");
2314a388f4SAlexey Bataev int reg0;
2414a388f4SAlexey Bataev 
test_iteration_spaces()2514a388f4SAlexey Bataev int test_iteration_spaces() {
2614a388f4SAlexey Bataev   const int N = 100;
2714a388f4SAlexey Bataev   float a[N], b[N], c[N];
2814a388f4SAlexey Bataev   int ii, jj, kk;
2914a388f4SAlexey Bataev   float fii;
3014a388f4SAlexey Bataev   double dii;
3114a388f4SAlexey Bataev   register int reg; // expected-warning {{'register' storage class specifier is deprecated}}
3214a388f4SAlexey Bataev #pragma omp parallel
3314a388f4SAlexey Bataev #pragma omp parallel master taskloop simd
3414a388f4SAlexey Bataev   for (int i = 0; i < 10; i += 1) {
3514a388f4SAlexey Bataev     c[i] = a[i] + b[i];
3614a388f4SAlexey Bataev   }
3714a388f4SAlexey Bataev #pragma omp parallel
3814a388f4SAlexey Bataev #pragma omp parallel master taskloop simd
3914a388f4SAlexey Bataev   for (char i = 0; i < 10; i++) {
4014a388f4SAlexey Bataev     c[i] = a[i] + b[i];
4114a388f4SAlexey Bataev   }
4214a388f4SAlexey Bataev #pragma omp parallel
4314a388f4SAlexey Bataev #pragma omp parallel master taskloop simd
4414a388f4SAlexey Bataev   for (char i = 0; i < 10; i += '\1') {
4514a388f4SAlexey Bataev     c[i] = a[i] + b[i];
4614a388f4SAlexey Bataev   }
4714a388f4SAlexey Bataev #pragma omp parallel
4814a388f4SAlexey Bataev #pragma omp parallel master taskloop simd
4914a388f4SAlexey Bataev   for (long long i = 0; i < 10; i++) {
5014a388f4SAlexey Bataev     c[i] = a[i] + b[i];
5114a388f4SAlexey Bataev   }
5214a388f4SAlexey Bataev #pragma omp parallel
5314a388f4SAlexey Bataev // expected-error@+2 {{expression must have integral or unscoped enumeration type, not 'double'}}
5414a388f4SAlexey Bataev #pragma omp parallel master taskloop simd
5514a388f4SAlexey Bataev   for (long long i = 0; i < 10; i += 1.5) {
5614a388f4SAlexey Bataev     c[i] = a[i] + b[i];
5714a388f4SAlexey Bataev   }
5814a388f4SAlexey Bataev #pragma omp parallel
5914a388f4SAlexey Bataev #pragma omp parallel master taskloop simd
6014a388f4SAlexey Bataev   for (long long i = 0; i < 'z'; i += 1u) {
6114a388f4SAlexey Bataev     c[i] = a[i] + b[i];
6214a388f4SAlexey Bataev   }
6314a388f4SAlexey Bataev #pragma omp parallel
6414a388f4SAlexey Bataev // expected-error@+2 {{variable must be of integer or random access iterator type}}
6514a388f4SAlexey Bataev #pragma omp parallel master taskloop simd
6614a388f4SAlexey Bataev   for (float fi = 0; fi < 10.0; fi++) {
6714a388f4SAlexey Bataev     c[(int)fi] = a[(int)fi] + b[(int)fi];
6814a388f4SAlexey Bataev   }
6914a388f4SAlexey Bataev #pragma omp parallel
7014a388f4SAlexey Bataev // expected-error@+2 {{variable must be of integer or random access iterator type}}
7114a388f4SAlexey Bataev #pragma omp parallel master taskloop simd
7214a388f4SAlexey Bataev   for (double fi = 0; fi < 10.0; fi++) {
7314a388f4SAlexey Bataev     c[(int)fi] = a[(int)fi] + b[(int)fi];
7414a388f4SAlexey Bataev   }
7514a388f4SAlexey Bataev #pragma omp parallel
7614a388f4SAlexey Bataev // expected-error@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
7714a388f4SAlexey Bataev #pragma omp parallel master taskloop simd
7814a388f4SAlexey Bataev   for (int &ref = ii; ref < 10; ref++) {
7914a388f4SAlexey Bataev   }
8014a388f4SAlexey Bataev #pragma omp parallel
8114a388f4SAlexey Bataev // expected-error@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
8214a388f4SAlexey Bataev #pragma omp parallel master taskloop simd
8314a388f4SAlexey Bataev   for (int i; i < 10; i++)
8414a388f4SAlexey Bataev     c[i] = a[i];
8514a388f4SAlexey Bataev 
8614a388f4SAlexey Bataev #pragma omp parallel
8714a388f4SAlexey Bataev // expected-error@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
8814a388f4SAlexey Bataev #pragma omp parallel master taskloop simd
8914a388f4SAlexey Bataev   for (int i = 0, j = 0; i < 10; ++i)
9014a388f4SAlexey Bataev     c[i] = a[i];
9114a388f4SAlexey Bataev 
9214a388f4SAlexey Bataev #pragma omp parallel
9314a388f4SAlexey Bataev // expected-error@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
9414a388f4SAlexey Bataev #pragma omp parallel master taskloop simd
9514a388f4SAlexey Bataev   for (; ii < 10; ++ii)
9614a388f4SAlexey Bataev     c[ii] = a[ii];
9714a388f4SAlexey Bataev 
9814a388f4SAlexey Bataev #pragma omp parallel
9914a388f4SAlexey Bataev // expected-warning@+3 {{expression result unused}}
10014a388f4SAlexey Bataev // expected-error@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
10114a388f4SAlexey Bataev #pragma omp parallel master taskloop simd
10214a388f4SAlexey Bataev   for (ii + 1; ii < 10; ++ii)
10314a388f4SAlexey Bataev     c[ii] = a[ii];
10414a388f4SAlexey Bataev 
10514a388f4SAlexey Bataev #pragma omp parallel
10614a388f4SAlexey Bataev // expected-error@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
10714a388f4SAlexey Bataev #pragma omp parallel master taskloop simd
10814a388f4SAlexey Bataev   for (c[ii] = 0; ii < 10; ++ii)
10914a388f4SAlexey Bataev     c[ii] = a[ii];
11014a388f4SAlexey Bataev 
11114a388f4SAlexey Bataev #pragma omp parallel
11214a388f4SAlexey Bataev // Ok to skip parenthesises.
11314a388f4SAlexey Bataev #pragma omp parallel master taskloop simd
11414a388f4SAlexey Bataev   for (((ii)) = 0; ii < 10; ++ii)
11514a388f4SAlexey Bataev     c[ii] = a[ii];
11614a388f4SAlexey Bataev 
11714a388f4SAlexey Bataev #pragma omp parallel
11814a388f4SAlexey Bataev // 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'}}
11914a388f4SAlexey Bataev #pragma omp parallel master taskloop simd
12014a388f4SAlexey Bataev   for (int i = 0; i; i++)
12114a388f4SAlexey Bataev     c[i] = a[i];
12214a388f4SAlexey Bataev 
12314a388f4SAlexey Bataev #pragma omp parallel
12414a388f4SAlexey Bataev // 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'}}
12514a388f4SAlexey Bataev // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'i'}}
12614a388f4SAlexey Bataev #pragma omp parallel master taskloop simd
12714a388f4SAlexey Bataev   for (int i = 0; jj < kk; ii++)
12814a388f4SAlexey Bataev     c[i] = a[i];
12914a388f4SAlexey Bataev 
13014a388f4SAlexey Bataev #pragma omp parallel
13114a388f4SAlexey Bataev // 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'}}
13214a388f4SAlexey Bataev #pragma omp parallel master taskloop simd
13314a388f4SAlexey Bataev   for (int i = 0; !!i; i++)
13414a388f4SAlexey Bataev     c[i] = a[i];
13514a388f4SAlexey Bataev 
13614a388f4SAlexey Bataev // Ok
13714a388f4SAlexey Bataev #pragma omp parallel
13814a388f4SAlexey Bataev // omp4-error@+2 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', or '>=') of loop variable 'i'}}
13914a388f4SAlexey Bataev #pragma omp parallel master taskloop simd
14014a388f4SAlexey Bataev   for (int i = 0; i != 1; i++)
14114a388f4SAlexey Bataev     c[i] = a[i];
14214a388f4SAlexey Bataev 
14314a388f4SAlexey Bataev #pragma omp parallel
14414a388f4SAlexey Bataev // 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'}}
14514a388f4SAlexey Bataev #pragma omp parallel master taskloop simd
14614a388f4SAlexey Bataev   for (int i = 0;; i++)
14714a388f4SAlexey Bataev     c[i] = a[i];
14814a388f4SAlexey Bataev 
14914a388f4SAlexey Bataev #pragma omp parallel
15014a388f4SAlexey Bataev // Ok.
15114a388f4SAlexey Bataev #pragma omp parallel master taskloop simd
15214a388f4SAlexey Bataev   for (int i = 11; i > 10; i--)
15314a388f4SAlexey Bataev     c[i] = a[i];
15414a388f4SAlexey Bataev 
15514a388f4SAlexey Bataev #pragma omp parallel
15614a388f4SAlexey Bataev // Ok.
15714a388f4SAlexey Bataev #pragma omp parallel master taskloop simd
15814a388f4SAlexey Bataev   for (int i = 0; i < 10; ++i)
15914a388f4SAlexey Bataev     c[i] = a[i];
16014a388f4SAlexey Bataev 
16114a388f4SAlexey Bataev #pragma omp parallel
16214a388f4SAlexey Bataev // Ok.
16314a388f4SAlexey Bataev #pragma omp parallel master taskloop simd
16414a388f4SAlexey Bataev   for (ii = 0; ii < 10; ++ii)
16514a388f4SAlexey Bataev     c[ii] = a[ii];
16614a388f4SAlexey Bataev 
16714a388f4SAlexey Bataev #pragma omp parallel
16814a388f4SAlexey Bataev // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'ii'}}
16914a388f4SAlexey Bataev #pragma omp parallel master taskloop simd
17014a388f4SAlexey Bataev   for (ii = 0; ii < 10; ++jj)
17114a388f4SAlexey Bataev     c[ii] = a[jj];
17214a388f4SAlexey Bataev 
17314a388f4SAlexey Bataev #pragma omp parallel
17414a388f4SAlexey Bataev // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'ii'}}
17514a388f4SAlexey Bataev #pragma omp parallel master taskloop simd
17614a388f4SAlexey Bataev   for (ii = 0; ii < 10; ++++ii)
17714a388f4SAlexey Bataev     c[ii] = a[ii];
17814a388f4SAlexey Bataev 
17914a388f4SAlexey Bataev #pragma omp parallel
18014a388f4SAlexey Bataev // Ok but undefined behavior (in general, cannot check that incr
18114a388f4SAlexey Bataev // is really loop-invariant).
18214a388f4SAlexey Bataev #pragma omp parallel master taskloop simd
18314a388f4SAlexey Bataev   for (ii = 0; ii < 10; ii = ii + ii)
18414a388f4SAlexey Bataev     c[ii] = a[ii];
18514a388f4SAlexey Bataev 
18614a388f4SAlexey Bataev #pragma omp parallel
18714a388f4SAlexey Bataev // expected-error@+2 {{expression must have integral or unscoped enumeration type, not 'float'}}
18814a388f4SAlexey Bataev #pragma omp parallel master taskloop simd
18914a388f4SAlexey Bataev   for (ii = 0; ii < 10; ii = ii + 1.0f)
19014a388f4SAlexey Bataev     c[ii] = a[ii];
19114a388f4SAlexey Bataev 
19214a388f4SAlexey Bataev #pragma omp parallel
19314a388f4SAlexey Bataev // Ok - step was converted to integer type.
19414a388f4SAlexey Bataev #pragma omp parallel master taskloop simd
19514a388f4SAlexey Bataev   for (ii = 0; ii < 10; ii = ii + (int)1.1f)
19614a388f4SAlexey Bataev     c[ii] = a[ii];
19714a388f4SAlexey Bataev 
19814a388f4SAlexey Bataev #pragma omp parallel
19914a388f4SAlexey Bataev // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'ii'}}
20014a388f4SAlexey Bataev #pragma omp parallel master taskloop simd
20114a388f4SAlexey Bataev   for (ii = 0; ii < 10; jj = ii + 2)
20214a388f4SAlexey Bataev     c[ii] = a[ii];
20314a388f4SAlexey Bataev 
20414a388f4SAlexey Bataev #pragma omp parallel
20514a388f4SAlexey Bataev // expected-warning@+3 {{relational comparison result unused}}
20614a388f4SAlexey Bataev // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'ii'}}
20714a388f4SAlexey Bataev #pragma omp parallel master taskloop simd
20814a388f4SAlexey Bataev   for (ii = 0; ii<10; jj> kk + 2)
20914a388f4SAlexey Bataev     c[ii] = a[ii];
21014a388f4SAlexey Bataev 
21114a388f4SAlexey Bataev #pragma omp parallel
21214a388f4SAlexey Bataev // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'ii'}}
21314a388f4SAlexey Bataev #pragma omp parallel master taskloop simd
21414a388f4SAlexey Bataev   for (ii = 0; ii < 10;)
21514a388f4SAlexey Bataev     c[ii] = a[ii];
21614a388f4SAlexey Bataev 
21714a388f4SAlexey Bataev #pragma omp parallel
21814a388f4SAlexey Bataev // expected-warning@+3 {{expression result unused}}
21914a388f4SAlexey Bataev // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'ii'}}
22014a388f4SAlexey Bataev #pragma omp parallel master taskloop simd
22114a388f4SAlexey Bataev   for (ii = 0; ii < 10; !ii)
22214a388f4SAlexey Bataev     c[ii] = a[ii];
22314a388f4SAlexey Bataev 
22414a388f4SAlexey Bataev #pragma omp parallel
22514a388f4SAlexey Bataev // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'ii'}}
22614a388f4SAlexey Bataev #pragma omp parallel master taskloop simd
22714a388f4SAlexey Bataev   for (ii = 0; ii < 10; ii ? ++ii : ++jj)
22814a388f4SAlexey Bataev     c[ii] = a[ii];
22914a388f4SAlexey Bataev 
23014a388f4SAlexey Bataev #pragma omp parallel
23114a388f4SAlexey Bataev // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'ii'}}
23214a388f4SAlexey Bataev #pragma omp parallel master taskloop simd
23314a388f4SAlexey Bataev   for (ii = 0; ii < 10; ii = ii < 10)
23414a388f4SAlexey Bataev     c[ii] = a[ii];
23514a388f4SAlexey Bataev 
23614a388f4SAlexey Bataev #pragma omp parallel
23714a388f4SAlexey Bataev // expected-note@+3 {{loop step is expected to be positive due to this condition}}
23814a388f4SAlexey Bataev // expected-error@+2 {{increment expression must cause 'ii' to increase on each iteration of OpenMP for loop}}
23914a388f4SAlexey Bataev #pragma omp parallel master taskloop simd
24014a388f4SAlexey Bataev   for (ii = 0; ii < 10; ii = ii + 0)
24114a388f4SAlexey Bataev     c[ii] = a[ii];
24214a388f4SAlexey Bataev 
24314a388f4SAlexey Bataev #pragma omp parallel
24414a388f4SAlexey Bataev // expected-note@+3 {{loop step is expected to be positive due to this condition}}
24514a388f4SAlexey Bataev // expected-error@+2 {{increment expression must cause 'ii' to increase on each iteration of OpenMP for loop}}
24614a388f4SAlexey Bataev #pragma omp parallel master taskloop simd
24714a388f4SAlexey Bataev   for (ii = 0; ii < 10; ii = ii + (int)(0.8 - 0.45))
24814a388f4SAlexey Bataev     c[ii] = a[ii];
24914a388f4SAlexey Bataev 
25014a388f4SAlexey Bataev #pragma omp parallel
25114a388f4SAlexey Bataev // expected-note@+3 {{loop step is expected to be positive due to this condition}}
25214a388f4SAlexey Bataev // expected-error@+2 {{increment expression must cause 'ii' to increase on each iteration of OpenMP for loop}}
25314a388f4SAlexey Bataev #pragma omp parallel master taskloop simd
25414a388f4SAlexey Bataev   for (ii = 0; (ii) < 10; ii -= 25)
25514a388f4SAlexey Bataev     c[ii] = a[ii];
25614a388f4SAlexey Bataev 
25714a388f4SAlexey Bataev #pragma omp parallel
25814a388f4SAlexey Bataev // expected-note@+3 {{loop step is expected to be positive due to this condition}}
25914a388f4SAlexey Bataev // expected-error@+2 {{increment expression must cause 'ii' to increase on each iteration of OpenMP for loop}}
26014a388f4SAlexey Bataev #pragma omp parallel master taskloop simd
26114a388f4SAlexey Bataev   for (ii = 0; (ii < 10); ii -= 0)
26214a388f4SAlexey Bataev     c[ii] = a[ii];
26314a388f4SAlexey Bataev 
26414a388f4SAlexey Bataev #pragma omp parallel
26514a388f4SAlexey Bataev // expected-note@+3 {{loop step is expected to be negative due to this condition}}
26614a388f4SAlexey Bataev // expected-error@+2 {{increment expression must cause 'ii' to decrease on each iteration of OpenMP for loop}}
26714a388f4SAlexey Bataev #pragma omp parallel master taskloop simd
26814a388f4SAlexey Bataev   for (ii = 0; ii > 10; (ii += 0))
26914a388f4SAlexey Bataev     c[ii] = a[ii];
27014a388f4SAlexey Bataev 
27114a388f4SAlexey Bataev #pragma omp parallel
27214a388f4SAlexey Bataev // expected-note@+3 {{loop step is expected to be positive due to this condition}}
27314a388f4SAlexey Bataev // expected-error@+2 {{increment expression must cause 'ii' to increase on each iteration of OpenMP for loop}}
27414a388f4SAlexey Bataev #pragma omp parallel master taskloop simd
27514a388f4SAlexey Bataev   for (ii = 0; ii < 10; (ii) = (1 - 1) + (ii))
27614a388f4SAlexey Bataev     c[ii] = a[ii];
27714a388f4SAlexey Bataev 
27814a388f4SAlexey Bataev #pragma omp parallel
27914a388f4SAlexey Bataev // expected-note@+3 {{loop step is expected to be negative due to this condition}}
28014a388f4SAlexey Bataev // expected-error@+2 {{increment expression must cause 'ii' to decrease on each iteration of OpenMP for loop}}
28114a388f4SAlexey Bataev #pragma omp parallel master taskloop simd
28214a388f4SAlexey Bataev   for ((ii = 0); ii > 10; (ii -= 0))
28314a388f4SAlexey Bataev     c[ii] = a[ii];
28414a388f4SAlexey Bataev 
28514a388f4SAlexey Bataev #pragma omp parallel
28614a388f4SAlexey Bataev // expected-note@+3 {{loop step is expected to be positive due to this condition}}
28714a388f4SAlexey Bataev // expected-error@+2 {{increment expression must cause 'ii' to increase on each iteration of OpenMP for loop}}
28814a388f4SAlexey Bataev #pragma omp parallel master taskloop simd
28914a388f4SAlexey Bataev   for (ii = 0; (ii < 10); (ii -= 0))
29014a388f4SAlexey Bataev     c[ii] = a[ii];
29114a388f4SAlexey Bataev 
29214a388f4SAlexey Bataev #pragma omp parallel
29314a388f4SAlexey Bataev // expected-note@+2  {{defined as firstprivate}}
29414a388f4SAlexey Bataev // expected-error@+2 {{loop iteration variable in the associated loop of 'omp parallel master taskloop simd' directive may not be firstprivate, predetermined as linear}}
29514a388f4SAlexey Bataev #pragma omp parallel master taskloop simd firstprivate(ii)
29614a388f4SAlexey Bataev   for (ii = 0; ii < 10; ii++)
29714a388f4SAlexey Bataev     c[ii] = a[ii];
29814a388f4SAlexey Bataev 
29914a388f4SAlexey Bataev #pragma omp parallel
30014a388f4SAlexey Bataev // expected-error@+1 {{unexpected OpenMP clause 'in_reduction' in directive '#pragma omp parallel master taskloop simd'}}
30114a388f4SAlexey Bataev #pragma omp parallel master taskloop simd in_reduction(+:ii)
30214a388f4SAlexey Bataev   for (ii = 0; ii < 10; ii++)
30314a388f4SAlexey Bataev     c[ii] = a[ii];
30414a388f4SAlexey Bataev 
30514a388f4SAlexey Bataev #pragma omp parallel
30614a388f4SAlexey Bataev #pragma omp parallel master taskloop simd linear(ii)
30714a388f4SAlexey Bataev   for (ii = 0; ii < 10; ii++)
30814a388f4SAlexey Bataev     c[ii] = a[ii];
30914a388f4SAlexey Bataev 
31014a388f4SAlexey Bataev #pragma omp parallel
31114a388f4SAlexey Bataev   {
31214a388f4SAlexey Bataev // expected-error@+2 {{loop iteration variable in the associated loop of 'omp parallel master taskloop simd' directive may not be threadprivate or thread local, predetermined as linear}}
31314a388f4SAlexey Bataev #pragma omp parallel master taskloop simd
31414a388f4SAlexey Bataev     for (sii = 0; sii < 10; sii += 1)
31514a388f4SAlexey Bataev       c[sii] = a[sii];
31614a388f4SAlexey Bataev   }
31714a388f4SAlexey Bataev 
31814a388f4SAlexey Bataev #pragma omp parallel
31914a388f4SAlexey Bataev   {
32014a388f4SAlexey Bataev #pragma omp parallel master taskloop simd
32114a388f4SAlexey Bataev     for (reg0 = 0; reg0 < 10; reg0 += 1)
32214a388f4SAlexey Bataev       c[reg0] = a[reg0];
32314a388f4SAlexey Bataev   }
32414a388f4SAlexey Bataev 
32514a388f4SAlexey Bataev #pragma omp parallel
32614a388f4SAlexey Bataev   {
32714a388f4SAlexey Bataev #pragma omp parallel master taskloop simd
32814a388f4SAlexey Bataev     for (reg = 0; reg < 10; reg += 1)
32914a388f4SAlexey Bataev       c[reg] = a[reg];
33014a388f4SAlexey Bataev   }
33114a388f4SAlexey Bataev 
33214a388f4SAlexey Bataev #pragma omp parallel
33314a388f4SAlexey Bataev   {
33414a388f4SAlexey Bataev #pragma omp parallel master taskloop simd
33514a388f4SAlexey Bataev     for (globalii = 0; globalii < 10; globalii += 1)
33614a388f4SAlexey Bataev       c[globalii] = a[globalii];
33714a388f4SAlexey Bataev   }
33814a388f4SAlexey Bataev 
33914a388f4SAlexey Bataev #pragma omp parallel
34014a388f4SAlexey Bataev   {
34114a388f4SAlexey Bataev #pragma omp parallel master taskloop simd collapse(2)
34214a388f4SAlexey Bataev     for (ii = 0; ii < 10; ii += 1)
34314a388f4SAlexey Bataev     for (globalii = 0; globalii < 10; globalii += 1)
34414a388f4SAlexey Bataev       c[globalii] += a[globalii] + ii;
34514a388f4SAlexey Bataev   }
34614a388f4SAlexey Bataev 
34714a388f4SAlexey Bataev #pragma omp parallel
34814a388f4SAlexey Bataev // omp4-error@+2 {{statement after '#pragma omp parallel master taskloop simd' must be a for loop}}
34914a388f4SAlexey Bataev #pragma omp parallel master taskloop simd
35014a388f4SAlexey Bataev   for (auto &item : a) {
35114a388f4SAlexey Bataev     item = item + 1;
35214a388f4SAlexey Bataev   }
35314a388f4SAlexey Bataev 
35414a388f4SAlexey Bataev #pragma omp parallel
35514a388f4SAlexey Bataev // expected-note@+3 {{loop step is expected to be positive due to this condition}}
35614a388f4SAlexey Bataev // expected-error@+2 {{increment expression must cause 'i' to increase on each iteration of OpenMP for loop}}
35714a388f4SAlexey Bataev #pragma omp parallel master taskloop simd
35814a388f4SAlexey Bataev   for (unsigned i = 9; i < 10; i--) {
35914a388f4SAlexey Bataev     c[i] = a[i] + b[i];
36014a388f4SAlexey Bataev   }
36114a388f4SAlexey Bataev 
36214a388f4SAlexey Bataev   int(*lb)[4] = nullptr;
36314a388f4SAlexey Bataev #pragma omp parallel
36414a388f4SAlexey Bataev #pragma omp parallel master taskloop simd
36514a388f4SAlexey Bataev   for (int(*p)[4] = lb; p < lb + 8; ++p) {
36614a388f4SAlexey Bataev   }
36714a388f4SAlexey Bataev 
36814a388f4SAlexey Bataev #pragma omp parallel
36914a388f4SAlexey Bataev // expected-warning@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
37014a388f4SAlexey Bataev #pragma omp parallel master taskloop simd
37114a388f4SAlexey Bataev   for (int a{0}; a < 10; ++a) {
37214a388f4SAlexey Bataev   }
37314a388f4SAlexey Bataev 
37414a388f4SAlexey Bataev   return 0;
37514a388f4SAlexey Bataev }
37614a388f4SAlexey Bataev 
37714a388f4SAlexey Bataev // Iterators allowed in openmp for-loops.
37814a388f4SAlexey Bataev namespace std {
37914a388f4SAlexey Bataev struct random_access_iterator_tag {};
38014a388f4SAlexey Bataev template <class Iter>
38114a388f4SAlexey Bataev struct iterator_traits {
38214a388f4SAlexey Bataev   typedef typename Iter::difference_type difference_type;
38314a388f4SAlexey Bataev   typedef typename Iter::iterator_category iterator_category;
38414a388f4SAlexey Bataev };
38514a388f4SAlexey Bataev template <class Iter>
38614a388f4SAlexey Bataev typename iterator_traits<Iter>::difference_type
distance(Iter first,Iter last)38714a388f4SAlexey Bataev distance(Iter first, Iter last) { return first - last; }
38814a388f4SAlexey Bataev }
38914a388f4SAlexey Bataev class Iter0 {
39014a388f4SAlexey Bataev public:
Iter0()39114a388f4SAlexey Bataev   Iter0() {}
Iter0(const Iter0 &)39214a388f4SAlexey Bataev   Iter0(const Iter0 &) {}
operator ++()39314a388f4SAlexey Bataev   Iter0 operator++() { return *this; }
operator --()39414a388f4SAlexey Bataev   Iter0 operator--() { return *this; }
operator <(Iter0 a)39514a388f4SAlexey Bataev   bool operator<(Iter0 a) { return true; }
39614a388f4SAlexey Bataev };
39714a388f4SAlexey Bataev // expected-note@+2 {{candidate function not viable: no known conversion from 'GoodIter' to 'Iter0' for 1st argument}}
39814a388f4SAlexey Bataev // expected-note@+1 2 {{candidate function not viable: no known conversion from 'Iter1' to 'Iter0' for 1st argument}}
operator -(Iter0 a,Iter0 b)39914a388f4SAlexey Bataev int operator-(Iter0 a, Iter0 b) { return 0; }
40014a388f4SAlexey Bataev class Iter1 {
40114a388f4SAlexey Bataev public:
Iter1(float f=0.0f,double d=0.0)40214a388f4SAlexey Bataev   Iter1(float f = 0.0f, double d = 0.0) {}
Iter1(const Iter1 &)40314a388f4SAlexey Bataev   Iter1(const Iter1 &) {}
operator ++()40414a388f4SAlexey Bataev   Iter1 operator++() { return *this; }
operator --()40514a388f4SAlexey Bataev   Iter1 operator--() { return *this; }
operator <(Iter1 a)40614a388f4SAlexey Bataev   bool operator<(Iter1 a) { return true; }
operator >=(Iter1 a)40714a388f4SAlexey Bataev   bool operator>=(Iter1 a) { return false; }
40814a388f4SAlexey Bataev };
40914a388f4SAlexey Bataev class GoodIter {
41014a388f4SAlexey Bataev public:
GoodIter()41114a388f4SAlexey Bataev   GoodIter() {}
GoodIter(const GoodIter &)41214a388f4SAlexey Bataev   GoodIter(const GoodIter &) {}
GoodIter(int fst,int snd)41314a388f4SAlexey Bataev   GoodIter(int fst, int snd) {}
operator =(const GoodIter & that)41414a388f4SAlexey Bataev   GoodIter &operator=(const GoodIter &that) { return *this; }
operator =(const Iter0 & that)41514a388f4SAlexey Bataev   GoodIter &operator=(const Iter0 &that) { return *this; }
operator +=(int x)41614a388f4SAlexey Bataev   GoodIter &operator+=(int x) { return *this; }
operator -=(int x)41714a388f4SAlexey Bataev   GoodIter &operator-=(int x) { return *this; }
GoodIter(void *)41814a388f4SAlexey Bataev   explicit GoodIter(void *) {}
operator ++()41914a388f4SAlexey Bataev   GoodIter operator++() { return *this; }
operator --()42014a388f4SAlexey Bataev   GoodIter operator--() { return *this; }
operator !()42114a388f4SAlexey Bataev   bool operator!() { return true; }
operator <(GoodIter a)42214a388f4SAlexey Bataev   bool operator<(GoodIter a) { return true; }
operator <=(GoodIter a)42314a388f4SAlexey Bataev   bool operator<=(GoodIter a) { return true; }
operator >=(GoodIter a)42414a388f4SAlexey Bataev   bool operator>=(GoodIter a) { return false; }
42514a388f4SAlexey Bataev   typedef int difference_type;
42614a388f4SAlexey Bataev   typedef std::random_access_iterator_tag iterator_category;
42714a388f4SAlexey Bataev };
42814a388f4SAlexey Bataev // expected-note@+2 {{candidate function not viable: no known conversion from 'const Iter0' to 'GoodIter' for 2nd argument}}
42914a388f4SAlexey Bataev // expected-note@+1 2 {{candidate function not viable: no known conversion from 'Iter1' to 'GoodIter' for 1st argument}}
operator -(GoodIter a,GoodIter b)43014a388f4SAlexey Bataev int operator-(GoodIter a, GoodIter b) { return 0; }
43114a388f4SAlexey Bataev // expected-note@+1 3 {{candidate function not viable: requires single argument 'a', but 2 arguments were provided}}
operator -(GoodIter a)43214a388f4SAlexey Bataev GoodIter operator-(GoodIter a) { return a; }
43314a388f4SAlexey Bataev // expected-note@+2 {{candidate function not viable: no known conversion from 'const Iter0' to 'int' for 2nd argument}}
43414a388f4SAlexey Bataev // expected-note@+1 2 {{candidate function not viable: no known conversion from 'Iter1' to 'GoodIter' for 1st argument}}
operator -(GoodIter a,int v)43514a388f4SAlexey Bataev GoodIter operator-(GoodIter a, int v) { return GoodIter(); }
43614a388f4SAlexey Bataev // expected-note@+1 2 {{candidate function not viable: no known conversion from 'Iter0' to 'GoodIter' for 1st argument}}
operator +(GoodIter a,int v)43714a388f4SAlexey Bataev GoodIter operator+(GoodIter a, int v) { return GoodIter(); }
43814a388f4SAlexey Bataev // expected-note@+2 {{candidate function not viable: no known conversion from 'GoodIter' to 'int' for 1st argument}}
43914a388f4SAlexey Bataev // expected-note@+1 2 {{candidate function not viable: no known conversion from 'Iter1' to 'int' for 1st argument}}
operator -(int v,GoodIter a)44014a388f4SAlexey Bataev GoodIter operator-(int v, GoodIter a) { return GoodIter(); }
44114a388f4SAlexey Bataev // expected-note@+1 2 {{candidate function not viable: no known conversion from 'Iter0' to 'int' for 1st argument}}
operator +(int v,GoodIter a)44214a388f4SAlexey Bataev GoodIter operator+(int v, GoodIter a) { return GoodIter(); }
44314a388f4SAlexey Bataev 
test_with_random_access_iterator()44414a388f4SAlexey Bataev int test_with_random_access_iterator() {
44514a388f4SAlexey Bataev   GoodIter begin, end;
44614a388f4SAlexey Bataev   Iter0 begin0, end0;
44714a388f4SAlexey Bataev #pragma omp parallel
44814a388f4SAlexey Bataev #pragma omp parallel master taskloop simd
44914a388f4SAlexey Bataev   for (GoodIter I = begin; I < end; ++I)
45014a388f4SAlexey Bataev     ++I;
45114a388f4SAlexey Bataev #pragma omp parallel
45214a388f4SAlexey Bataev // expected-error@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
45314a388f4SAlexey Bataev #pragma omp parallel master taskloop simd
45414a388f4SAlexey Bataev   for (GoodIter &I = begin; I < end; ++I)
45514a388f4SAlexey Bataev     ++I;
45614a388f4SAlexey Bataev #pragma omp parallel
45714a388f4SAlexey Bataev #pragma omp parallel master taskloop simd
45814a388f4SAlexey Bataev   for (GoodIter I = begin; I >= end; --I)
45914a388f4SAlexey Bataev     ++I;
46014a388f4SAlexey Bataev #pragma omp parallel
46114a388f4SAlexey Bataev // expected-warning@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
46214a388f4SAlexey Bataev #pragma omp parallel master taskloop simd
46314a388f4SAlexey Bataev   for (GoodIter I(begin); I < end; ++I)
46414a388f4SAlexey Bataev     ++I;
46514a388f4SAlexey Bataev #pragma omp parallel
46614a388f4SAlexey Bataev // expected-warning@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
46714a388f4SAlexey Bataev #pragma omp parallel master taskloop simd
46814a388f4SAlexey Bataev   for (GoodIter I(nullptr); I < end; ++I)
46914a388f4SAlexey Bataev     ++I;
47014a388f4SAlexey Bataev #pragma omp parallel
47114a388f4SAlexey Bataev // expected-warning@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
47214a388f4SAlexey Bataev #pragma omp parallel master taskloop simd
47314a388f4SAlexey Bataev   for (GoodIter I(0); I < end; ++I)
47414a388f4SAlexey Bataev     ++I;
47514a388f4SAlexey Bataev #pragma omp parallel
47614a388f4SAlexey Bataev // expected-warning@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
47714a388f4SAlexey Bataev #pragma omp parallel master taskloop simd
47814a388f4SAlexey Bataev   for (GoodIter I(1, 2); I < end; ++I)
47914a388f4SAlexey Bataev     ++I;
48014a388f4SAlexey Bataev #pragma omp parallel
48114a388f4SAlexey Bataev #pragma omp parallel master taskloop simd
48214a388f4SAlexey Bataev   for (begin = GoodIter(0); begin < end; ++begin)
48314a388f4SAlexey Bataev     ++begin;
48414a388f4SAlexey Bataev // expected-error@+4 {{invalid operands to binary expression ('GoodIter' and 'const Iter0')}}
48514a388f4SAlexey Bataev // expected-error@+3 {{could not calculate number of iterations calling 'operator-' with upper and lower loop bounds}}
48614a388f4SAlexey Bataev #pragma omp parallel
48714a388f4SAlexey Bataev #pragma omp parallel master taskloop simd
48814a388f4SAlexey Bataev   for (begin = begin0; begin < end; ++begin)
48914a388f4SAlexey Bataev     ++begin;
49014a388f4SAlexey Bataev #pragma omp parallel
49114a388f4SAlexey Bataev // expected-error@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
49214a388f4SAlexey Bataev #pragma omp parallel master taskloop simd
49314a388f4SAlexey Bataev   for (++begin; begin < end; ++begin)
49414a388f4SAlexey Bataev     ++begin;
49514a388f4SAlexey Bataev #pragma omp parallel
49614a388f4SAlexey Bataev #pragma omp parallel master taskloop simd
49714a388f4SAlexey Bataev   for (begin = end; begin < end; ++begin)
49814a388f4SAlexey Bataev     ++begin;
49914a388f4SAlexey Bataev #pragma omp parallel
50014a388f4SAlexey Bataev // 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'}}
50114a388f4SAlexey Bataev #pragma omp parallel master taskloop simd
50214a388f4SAlexey Bataev   for (GoodIter I = begin; I - I; ++I)
50314a388f4SAlexey Bataev     ++I;
50414a388f4SAlexey Bataev #pragma omp parallel
50514a388f4SAlexey Bataev // 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'}}
50614a388f4SAlexey Bataev #pragma omp parallel master taskloop simd
50714a388f4SAlexey Bataev   for (GoodIter I = begin; begin < end; ++I)
50814a388f4SAlexey Bataev     ++I;
50914a388f4SAlexey Bataev #pragma omp parallel
51014a388f4SAlexey Bataev // 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'}}
51114a388f4SAlexey Bataev #pragma omp parallel master taskloop simd
51214a388f4SAlexey Bataev   for (GoodIter I = begin; !I; ++I)
51314a388f4SAlexey Bataev     ++I;
51414a388f4SAlexey Bataev #pragma omp parallel
51514a388f4SAlexey Bataev // expected-note@+3 {{loop step is expected to be negative due to this condition}}
51614a388f4SAlexey Bataev // expected-error@+2 {{increment expression must cause 'I' to decrease on each iteration of OpenMP for loop}}
51714a388f4SAlexey Bataev #pragma omp parallel master taskloop simd
51814a388f4SAlexey Bataev   for (GoodIter I = begin; I >= end; I = I + 1)
51914a388f4SAlexey Bataev     ++I;
52014a388f4SAlexey Bataev #pragma omp parallel
52114a388f4SAlexey Bataev #pragma omp parallel master taskloop simd
52214a388f4SAlexey Bataev   for (GoodIter I = begin; I >= end; I = I - 1)
52314a388f4SAlexey Bataev     ++I;
52414a388f4SAlexey Bataev #pragma omp parallel
52514a388f4SAlexey Bataev // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'I'}}
52614a388f4SAlexey Bataev #pragma omp parallel master taskloop simd
52714a388f4SAlexey Bataev   for (GoodIter I = begin; I >= end; I = -I)
52814a388f4SAlexey Bataev     ++I;
52914a388f4SAlexey Bataev #pragma omp parallel
53014a388f4SAlexey Bataev // expected-note@+3 {{loop step is expected to be negative due to this condition}}
53114a388f4SAlexey Bataev // expected-error@+2 {{increment expression must cause 'I' to decrease on each iteration of OpenMP for loop}}
53214a388f4SAlexey Bataev #pragma omp parallel master taskloop simd
53314a388f4SAlexey Bataev   for (GoodIter I = begin; I >= end; I = 2 + I)
53414a388f4SAlexey Bataev     ++I;
53514a388f4SAlexey Bataev #pragma omp parallel
53614a388f4SAlexey Bataev // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'I'}}
53714a388f4SAlexey Bataev #pragma omp parallel master taskloop simd
53814a388f4SAlexey Bataev   for (GoodIter I = begin; I >= end; I = 2 - I)
53914a388f4SAlexey Bataev     ++I;
54014a388f4SAlexey Bataev // In the following example, we cannot update the loop variable using '+='
54114a388f4SAlexey Bataev // expected-error@+3 {{invalid operands to binary expression ('Iter0' and 'int')}}
54214a388f4SAlexey Bataev #pragma omp parallel
54314a388f4SAlexey Bataev #pragma omp parallel master taskloop simd
54414a388f4SAlexey Bataev   for (Iter0 I = begin0; I < end0; ++I)
54514a388f4SAlexey Bataev     ++I;
54614a388f4SAlexey Bataev #pragma omp parallel
54714a388f4SAlexey Bataev // Initializer is constructor without params.
54814a388f4SAlexey Bataev // expected-error@+3 {{invalid operands to binary expression ('Iter0' and 'int')}}
54914a388f4SAlexey Bataev // expected-warning@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
55014a388f4SAlexey Bataev #pragma omp parallel master taskloop simd
55114a388f4SAlexey Bataev   for (Iter0 I; I < end0; ++I)
55214a388f4SAlexey Bataev     ++I;
55314a388f4SAlexey Bataev   Iter1 begin1, end1;
55414a388f4SAlexey Bataev // expected-error@+4 {{invalid operands to binary expression ('Iter1' and 'Iter1')}}
55514a388f4SAlexey Bataev // expected-error@+3 {{could not calculate number of iterations calling 'operator-' with upper and lower loop bounds}}
55614a388f4SAlexey Bataev #pragma omp parallel
55714a388f4SAlexey Bataev #pragma omp parallel master taskloop simd
55814a388f4SAlexey Bataev   for (Iter1 I = begin1; I < end1; ++I)
55914a388f4SAlexey Bataev     ++I;
56014a388f4SAlexey Bataev #pragma omp parallel
56114a388f4SAlexey Bataev // expected-note@+3 {{loop step is expected to be negative due to this condition}}
56214a388f4SAlexey Bataev // expected-error@+2 {{increment expression must cause 'I' to decrease on each iteration of OpenMP for loop}}
56314a388f4SAlexey Bataev #pragma omp parallel master taskloop simd
56414a388f4SAlexey Bataev   for (Iter1 I = begin1; I >= end1; ++I)
56514a388f4SAlexey Bataev     ++I;
56614a388f4SAlexey Bataev #pragma omp parallel
56714a388f4SAlexey Bataev // expected-error@+5 {{invalid operands to binary expression ('Iter1' and 'float')}}
56814a388f4SAlexey Bataev // expected-error@+4 {{could not calculate number of iterations calling 'operator-' with upper and lower loop bounds}}
56914a388f4SAlexey Bataev // Initializer is constructor with all default params.
57014a388f4SAlexey Bataev // expected-warning@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
57114a388f4SAlexey Bataev #pragma omp parallel master taskloop simd
57214a388f4SAlexey Bataev   for (Iter1 I; I < end1; ++I) {
57314a388f4SAlexey Bataev   }
57414a388f4SAlexey Bataev   return 0;
57514a388f4SAlexey Bataev }
57614a388f4SAlexey Bataev 
57714a388f4SAlexey Bataev template <typename IT, int ST>
57814a388f4SAlexey Bataev class TC {
57914a388f4SAlexey Bataev public:
dotest_lt(IT begin,IT end)58014a388f4SAlexey Bataev   int dotest_lt(IT begin, IT end) {
58114a388f4SAlexey Bataev #pragma omp parallel
58214a388f4SAlexey Bataev // expected-note@+3 {{loop step is expected to be positive due to this condition}}
58314a388f4SAlexey Bataev // expected-error@+2 {{increment expression must cause 'I' to increase on each iteration of OpenMP for loop}}
58414a388f4SAlexey Bataev #pragma omp parallel master taskloop simd
58514a388f4SAlexey Bataev     for (IT I = begin; I < end; I = I + ST) {
58614a388f4SAlexey Bataev       ++I;
58714a388f4SAlexey Bataev     }
58814a388f4SAlexey Bataev #pragma omp parallel
58914a388f4SAlexey Bataev // expected-note@+3 {{loop step is expected to be positive due to this condition}}
59014a388f4SAlexey Bataev // expected-error@+2 {{increment expression must cause 'I' to increase on each iteration of OpenMP for loop}}
59114a388f4SAlexey Bataev #pragma omp parallel master taskloop simd
59214a388f4SAlexey Bataev     for (IT I = begin; I <= end; I += ST) {
59314a388f4SAlexey Bataev       ++I;
59414a388f4SAlexey Bataev     }
59514a388f4SAlexey Bataev #pragma omp parallel
59614a388f4SAlexey Bataev #pragma omp parallel master taskloop simd
59714a388f4SAlexey Bataev     for (IT I = begin; I < end; ++I) {
59814a388f4SAlexey Bataev       ++I;
59914a388f4SAlexey Bataev     }
60014a388f4SAlexey Bataev   }
60114a388f4SAlexey Bataev 
step()60214a388f4SAlexey Bataev   static IT step() {
60314a388f4SAlexey Bataev     return IT(ST);
60414a388f4SAlexey Bataev   }
60514a388f4SAlexey Bataev };
60614a388f4SAlexey Bataev template <typename IT, int ST = 0>
dotest_gt(IT begin,IT end)60714a388f4SAlexey Bataev int dotest_gt(IT begin, IT end) {
60814a388f4SAlexey Bataev #pragma omp parallel
60914a388f4SAlexey Bataev // expected-note@+3 2 {{loop step is expected to be negative due to this condition}}
61014a388f4SAlexey Bataev // expected-error@+2 2 {{increment expression must cause 'I' to decrease on each iteration of OpenMP for loop}}
61114a388f4SAlexey Bataev #pragma omp parallel master taskloop simd
61214a388f4SAlexey Bataev   for (IT I = begin; I >= end; I = I + ST) {
61314a388f4SAlexey Bataev     ++I;
61414a388f4SAlexey Bataev   }
61514a388f4SAlexey Bataev #pragma omp parallel
61614a388f4SAlexey Bataev // expected-note@+3 2 {{loop step is expected to be negative due to this condition}}
61714a388f4SAlexey Bataev // expected-error@+2 2 {{increment expression must cause 'I' to decrease on each iteration of OpenMP for loop}}
61814a388f4SAlexey Bataev #pragma omp parallel master taskloop simd
61914a388f4SAlexey Bataev   for (IT I = begin; I >= end; I += ST) {
62014a388f4SAlexey Bataev     ++I;
62114a388f4SAlexey Bataev   }
62214a388f4SAlexey Bataev 
62314a388f4SAlexey Bataev #pragma omp parallel
62414a388f4SAlexey Bataev // expected-note@+3 {{loop step is expected to be negative due to this condition}}
62514a388f4SAlexey Bataev // expected-error@+2 {{increment expression must cause 'I' to decrease on each iteration of OpenMP for loop}}
62614a388f4SAlexey Bataev #pragma omp parallel master taskloop simd
62714a388f4SAlexey Bataev   for (IT I = begin; I >= end; ++I) {
62814a388f4SAlexey Bataev     ++I;
62914a388f4SAlexey Bataev   }
63014a388f4SAlexey Bataev 
63114a388f4SAlexey Bataev #pragma omp parallel
63214a388f4SAlexey Bataev #pragma omp parallel master taskloop simd
63314a388f4SAlexey Bataev   for (IT I = begin; I < end; I += TC<int, ST>::step()) {
63414a388f4SAlexey Bataev     ++I;
63514a388f4SAlexey Bataev   }
63614a388f4SAlexey Bataev }
63714a388f4SAlexey Bataev 
test_with_template()63814a388f4SAlexey Bataev void test_with_template() {
63914a388f4SAlexey Bataev   GoodIter begin, end;
64014a388f4SAlexey Bataev   TC<GoodIter, 100> t1;
64114a388f4SAlexey Bataev   TC<GoodIter, -100> t2;
64214a388f4SAlexey Bataev   t1.dotest_lt(begin, end);
64314a388f4SAlexey Bataev   t2.dotest_lt(begin, end);         // expected-note {{in instantiation of member function 'TC<GoodIter, -100>::dotest_lt' requested here}}
64414a388f4SAlexey Bataev   dotest_gt(begin, end);            // expected-note {{in instantiation of function template specialization 'dotest_gt<GoodIter, 0>' requested here}}
64514a388f4SAlexey Bataev   dotest_gt<unsigned, 10>(0, 100);  // expected-note {{in instantiation of function template specialization 'dotest_gt<unsigned int, 10>' requested here}}
64614a388f4SAlexey Bataev }
64714a388f4SAlexey Bataev 
test_loop_break()64814a388f4SAlexey Bataev void test_loop_break() {
64914a388f4SAlexey Bataev   const int N = 100;
65014a388f4SAlexey Bataev   float a[N], b[N], c[N];
65114a388f4SAlexey Bataev #pragma omp parallel
65214a388f4SAlexey Bataev #pragma omp parallel master taskloop simd
65314a388f4SAlexey Bataev   for (int i = 0; i < 10; i++) {
65414a388f4SAlexey Bataev     c[i] = a[i] + b[i];
65514a388f4SAlexey Bataev     for (int j = 0; j < 10; ++j) {
65614a388f4SAlexey Bataev       if (a[i] > b[j])
65714a388f4SAlexey Bataev         break; // OK in nested loop
65814a388f4SAlexey Bataev     }
65914a388f4SAlexey Bataev     switch (i) {
66014a388f4SAlexey Bataev     case 1:
66114a388f4SAlexey Bataev       b[i]++;
66214a388f4SAlexey Bataev       break;
66314a388f4SAlexey Bataev     default:
66414a388f4SAlexey Bataev       break;
66514a388f4SAlexey Bataev     }
66614a388f4SAlexey Bataev     if (c[i] > 10)
66714a388f4SAlexey Bataev       break; // expected-error {{'break' statement cannot be used in OpenMP for loop}}
66814a388f4SAlexey Bataev 
66914a388f4SAlexey Bataev     if (c[i] > 11)
67014a388f4SAlexey Bataev       break; // expected-error {{'break' statement cannot be used in OpenMP for loop}}
67114a388f4SAlexey Bataev   }
67214a388f4SAlexey Bataev 
67314a388f4SAlexey Bataev #pragma omp parallel
67414a388f4SAlexey Bataev #pragma omp parallel master taskloop simd
67514a388f4SAlexey Bataev   for (int i = 0; i < 10; i++) {
67614a388f4SAlexey Bataev     for (int j = 0; j < 10; j++) {
67714a388f4SAlexey Bataev       c[i] = a[i] + b[i];
67814a388f4SAlexey Bataev       if (c[i] > 10) {
67914a388f4SAlexey Bataev         if (c[i] < 20) {
68014a388f4SAlexey Bataev           break; // OK
68114a388f4SAlexey Bataev         }
68214a388f4SAlexey Bataev       }
68314a388f4SAlexey Bataev     }
68414a388f4SAlexey Bataev   }
68514a388f4SAlexey Bataev }
68614a388f4SAlexey Bataev 
test_loop_eh()68714a388f4SAlexey Bataev void test_loop_eh() {
68814a388f4SAlexey Bataev   const int N = 100;
68914a388f4SAlexey Bataev   float a[N], b[N], c[N];
69014a388f4SAlexey Bataev #pragma omp parallel
69114a388f4SAlexey Bataev #pragma omp parallel master taskloop simd
69214a388f4SAlexey Bataev   for (int i = 0; i < 10; i++) {
69314a388f4SAlexey Bataev     c[i] = a[i] + b[i];
69414a388f4SAlexey Bataev     try { // expected-error {{'try' statement cannot be used in OpenMP simd region}}
69514a388f4SAlexey Bataev       for (int j = 0; j < 10; ++j) {
69614a388f4SAlexey Bataev         if (a[i] > b[j])
69714a388f4SAlexey Bataev           throw a[i]; // expected-error {{'throw' statement cannot be used in OpenMP simd region}}
69814a388f4SAlexey Bataev       }
69914a388f4SAlexey Bataev       throw a[i]; // expected-error {{'throw' statement cannot be used in OpenMP simd region}}
70014a388f4SAlexey Bataev     } catch (float f) {
70114a388f4SAlexey Bataev       if (f > 0.1)
70214a388f4SAlexey Bataev         throw a[i]; // expected-error {{'throw' statement cannot be used in OpenMP simd region}}
70314a388f4SAlexey Bataev       return; // expected-error {{cannot return from OpenMP region}}
70414a388f4SAlexey Bataev     }
70514a388f4SAlexey Bataev     switch (i) {
70614a388f4SAlexey Bataev     case 1:
70714a388f4SAlexey Bataev       b[i]++;
70814a388f4SAlexey Bataev       break;
70914a388f4SAlexey Bataev     default:
71014a388f4SAlexey Bataev       break;
71114a388f4SAlexey Bataev     }
71214a388f4SAlexey Bataev     for (int j = 0; j < 10; j++) {
71314a388f4SAlexey Bataev       if (c[i] > 10)
71414a388f4SAlexey Bataev         throw c[i]; // expected-error {{'throw' statement cannot be used in OpenMP simd region}}
71514a388f4SAlexey Bataev     }
71614a388f4SAlexey Bataev   }
71714a388f4SAlexey Bataev   if (c[9] > 10)
71814a388f4SAlexey Bataev     throw c[9]; // OK
71914a388f4SAlexey Bataev 
72014a388f4SAlexey Bataev #pragma omp parallel
72114a388f4SAlexey Bataev #pragma omp parallel master taskloop simd
72214a388f4SAlexey Bataev   for (int i = 0; i < 10; ++i) {
72314a388f4SAlexey Bataev     struct S {
72414a388f4SAlexey Bataev       void g() { throw 0; }
72514a388f4SAlexey Bataev     };
72614a388f4SAlexey Bataev   }
72714a388f4SAlexey Bataev }
72814a388f4SAlexey Bataev 
test_loop_firstprivate_lastprivate()72914a388f4SAlexey Bataev void test_loop_firstprivate_lastprivate() {
73014a388f4SAlexey Bataev   S s(4);
73177d049d0SAlexey Bataev   int c;
73214a388f4SAlexey Bataev #pragma omp parallel
73314a388f4SAlexey Bataev #pragma omp parallel master taskloop simd lastprivate(s) firstprivate(s)
73414a388f4SAlexey Bataev   for (int i = 0; i < 16; ++i)
73514a388f4SAlexey Bataev     ;
73677d049d0SAlexey Bataev #pragma omp parallel master taskloop simd if(c) default(none) // expected-error {{variable 'c' must have explicitly specified data sharing attributes}} expected-note {{explicit data sharing attribute requested here}}
73777d049d0SAlexey Bataev   for (int i = 0; i < 16; ++i)
73877d049d0SAlexey Bataev     ;
73977d049d0SAlexey Bataev #pragma omp parallel master taskloop simd if(taskloop:c) default(none) // expected-error {{variable 'c' must have explicitly specified data sharing attributes}} expected-note {{explicit data sharing attribute requested here}}
74077d049d0SAlexey Bataev   for (int i = 0; i < 16; ++i)
74177d049d0SAlexey Bataev     ;
74277d049d0SAlexey Bataev #pragma omp parallel master taskloop simd if(parallel:c) default(none)
74377d049d0SAlexey Bataev   for (int i = 0; i < 16; ++i)
74477d049d0SAlexey Bataev     ;
74514a388f4SAlexey Bataev }
74614a388f4SAlexey Bataev 
747