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