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