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