1 // RUN: %clang_cc1 -fsyntax-only -fopenmp -verify %s
2 
3 // expected-error@+1 {{unexpected OpenMP directive '#pragma omp parallel for'}}
4 #pragma omp parallel for
5 
6 // expected-error@+1 {{unexpected OpenMP directive '#pragma omp parallel for'}}
7 #pragma omp parallel for foo
8 
9 void test_no_clause() {
10   int i;
11 #pragma omp parallel for
12   for (i = 0; i < 16; ++i)
13     ;
14 
15 // expected-error@+2 {{statement after '#pragma omp parallel for' must be a for loop}}
16 #pragma omp parallel for
17   ++i;
18 }
19 
20 void test_branch_protected_scope() {
21   int i = 0;
22 L1:
23   ++i;
24 
25   int x[24];
26 
27 #pragma omp parallel for
28   for (i = 0; i < 16; ++i) {
29     if (i == 5)
30       goto L1; // expected-error {{use of undeclared label 'L1'}}
31     else if (i == 6)
32       return; // expected-error {{cannot return from OpenMP region}}
33     else if (i == 7)
34       goto L2;
35     else if (i == 8) {
36     L2:
37       x[i]++;
38     }
39   }
40 
41   if (x[0] == 0)
42     goto L2; // expected-error {{use of undeclared label 'L2'}}
43   else if (x[1] == 1)
44     goto L1;
45 }
46 
47 void test_invalid_clause() {
48   int i;
49 // expected-warning@+1 {{extra tokens at the end of '#pragma omp parallel for' are ignored}}
50 #pragma omp parallel for foo bar
51   for (i = 0; i < 16; ++i)
52     ;
53 }
54 
55 void test_non_identifiers() {
56   int i, x;
57 
58 // expected-warning@+1 {{extra tokens at the end of '#pragma omp parallel for' are ignored}}
59 #pragma omp parallel for;
60   for (i = 0; i < 16; ++i)
61     ;
62 
63 // expected-warning@+1 {{extra tokens at the end of '#pragma omp parallel for' are ignored}}
64 #pragma omp parallel for private(x);
65   for (i = 0; i < 16; ++i)
66     ;
67 
68 // expected-warning@+1 {{extra tokens at the end of '#pragma omp parallel for' are ignored}}
69 #pragma omp parallel for, private(x);
70   for (i = 0; i < 16; ++i)
71     ;
72 }
73 
74 extern int foo();
75 
76 void test_collapse() {
77   int i;
78 // expected-error@+1 {{expected '('}}
79 #pragma omp parallel for collapse
80   for (i = 0; i < 16; ++i)
81     ;
82 // expected-error@+1 {{expected expression}} expected-error@+1 {{expected ')'}} expected-note@+1 {{to match this '('}}
83 #pragma omp parallel for collapse(
84   for (i = 0; i < 16; ++i)
85     ;
86 // expected-error@+1 {{expected expression}}
87 #pragma omp parallel for collapse()
88   for (i = 0; i < 16; ++i)
89     ;
90 // expected-error@+1 {{expected expression}} expected-error@+1 {{expected ')'}} expected-note@+1 {{to match this '('}}
91 #pragma omp parallel for collapse(,
92   for (i = 0; i < 16; ++i)
93     ;
94 // expected-error@+1 {{expected expression}}  expected-error@+1 {{expected ')'}} expected-note@+1 {{to match this '('}}
95 #pragma omp parallel for collapse(, )
96   for (i = 0; i < 16; ++i)
97     ;
98 // expected-warning@+2 {{extra tokens at the end of '#pragma omp parallel for' are ignored}}
99 // expected-error@+1 {{expected '('}}
100 #pragma omp parallel for collapse 4)
101   for (i = 0; i < 16; ++i)
102     ;
103 // expected-error@+2 {{expected ')'}}
104 // expected-note@+1 {{to match this '('}} expected-note@+1 {{as specified in 'collapse' clause}}
105 #pragma omp parallel for collapse(4
106   for (i = 0; i < 16; ++i)
107     ; // expected-error {{expected 4 for loops after '#pragma omp parallel for', but found only 1}}
108 // expected-error@+2 {{expected ')'}}
109 // expected-note@+1 {{to match this '('}} expected-note@+1 {{as specified in 'collapse' clause}}
110 #pragma omp parallel for collapse(4,
111   for (i = 0; i < 16; ++i)
112     ; // expected-error {{expected 4 for loops after '#pragma omp parallel for', but found only 1}}
113 // expected-error@+2 {{expected ')'}}
114 // expected-note@+1 {{to match this '('}} expected-note@+1 {{as specified in 'collapse' clause}}
115 #pragma omp parallel for collapse(4, )
116   for (i = 0; i < 16; ++i)
117     ; // expected-error {{expected 4 for loops after '#pragma omp parallel for', but found only 1}}
118 // expected-note@+1 {{as specified in 'collapse' clause}}
119 #pragma omp parallel for collapse(4)
120   for (i = 0; i < 16; ++i)
121     ; // expected-error {{expected 4 for loops after '#pragma omp parallel for', but found only 1}}
122 // expected-error@+2 {{expected ')'}}
123 // expected-note@+1 {{to match this '('}} expected-note@+1 {{as specified in 'collapse' clause}}
124 #pragma omp parallel for collapse(4 4)
125   for (i = 0; i < 16; ++i)
126     ; // expected-error {{expected 4 for loops after '#pragma omp parallel for', but found only 1}}
127 // expected-error@+2 {{expected ')'}}
128 // expected-note@+1 {{to match this '('}} expected-note@+1 {{as specified in 'collapse' clause}}
129 #pragma omp parallel for collapse(4, , 4)
130   for (i = 0; i < 16; ++i)
131     ; // expected-error {{expected 4 for loops after '#pragma omp parallel for', but found only 1}}
132 #pragma omp parallel for collapse(4)
133   for (int i1 = 0; i1 < 16; ++i1)
134     for (int i2 = 0; i2 < 16; ++i2)
135       for (int i3 = 0; i3 < 16; ++i3)
136         for (int i4 = 0; i4 < 16; ++i4)
137           foo();
138 // expected-error@+2 {{expected ')'}}
139 // expected-note@+1 {{to match this '('}} expected-note@+1 {{as specified in 'collapse' clause}}
140 #pragma omp parallel for collapse(4, 8)
141   for (i = 0; i < 16; ++i)
142     ; // expected-error {{expected 4 for loops after '#pragma omp parallel for', but found only 1}}
143 // expected-error@+1 {{expression is not an integer constant expression}}
144 #pragma omp parallel for collapse(2.5)
145   for (i = 0; i < 16; ++i)
146     ;
147 // expected-error@+1 {{expression is not an integer constant expression}}
148 #pragma omp parallel for collapse(foo())
149   for (i = 0; i < 16; ++i)
150     ;
151 // expected-error@+1 {{argument to 'collapse' clause must be a strictly positive integer value}}
152 #pragma omp parallel for collapse(-5)
153   for (i = 0; i < 16; ++i)
154     ;
155 // expected-error@+1 {{argument to 'collapse' clause must be a strictly positive integer value}}
156 #pragma omp parallel for collapse(0)
157   for (i = 0; i < 16; ++i)
158     ;
159 // expected-error@+1 {{argument to 'collapse' clause must be a strictly positive integer value}}
160 #pragma omp parallel for collapse(5 - 5)
161   for (i = 0; i < 16; ++i)
162     ;
163 // expected-note@+1 {{defined as firstprivate}}
164 #pragma omp parallel for collapse(2) firstprivate(i)
165   for (i = 0; i < 16; ++i)
166 // expected-note@+1 {{variable with automatic storage duration is predetermined as private; perhaps you forget to enclose 'omp for' directive into a parallel or another task region?}}
167     for (int j = 0; j < 16; ++j)
168 // expected-error@+2 2 {{reduction variable must be shared}}
169 // expected-error@+1 {{region cannot be closely nested inside 'parallel for' region; perhaps you forget to enclose 'omp for' directive into a parallel region?}}
170 #pragma omp for reduction(+ : i, j)
171       for (int k = 0; k < 16; ++k)
172         i += j;
173 }
174 
175 void test_private() {
176   int i;
177 // expected-error@+2 {{expected expression}}
178 // expected-error@+1 {{expected ')'}} expected-note@+1 {{to match this '('}}
179 #pragma omp parallel for private(
180   for (i = 0; i < 16; ++i)
181     ;
182 // expected-error@+2 {{expected ')'}} expected-note@+2 {{to match this '('}}
183 // expected-error@+1 2 {{expected expression}}
184 #pragma omp parallel for private(,
185   for (i = 0; i < 16; ++i)
186     ;
187 // expected-error@+1 2 {{expected expression}}
188 #pragma omp parallel for private(, )
189   for (i = 0; i < 16; ++i)
190     ;
191 // expected-error@+1 {{expected expression}}
192 #pragma omp parallel for private()
193   for (i = 0; i < 16; ++i)
194     ;
195 // expected-error@+1 {{expected expression}}
196 #pragma omp parallel for private(int)
197   for (i = 0; i < 16; ++i)
198     ;
199 // expected-error@+1 {{expected variable name}}
200 #pragma omp parallel for private(0)
201   for (i = 0; i < 16; ++i)
202     ;
203 
204   int x, y, z;
205 #pragma omp parallel for private(x)
206   for (i = 0; i < 16; ++i)
207     ;
208 #pragma omp parallel for private(x, y)
209   for (i = 0; i < 16; ++i)
210     ;
211 #pragma omp parallel for private(x, y, z)
212   for (i = 0; i < 16; ++i) {
213     x = y * i + z;
214   }
215 }
216 
217 void test_lastprivate() {
218   int i;
219 // expected-error@+2 {{expected ')'}} expected-note@+2 {{to match this '('}}
220 // expected-error@+1 {{expected expression}}
221 #pragma omp parallel for lastprivate(
222   for (i = 0; i < 16; ++i)
223     ;
224 
225 // expected-error@+2 {{expected ')'}} expected-note@+2 {{to match this '('}}
226 // expected-error@+1 2 {{expected expression}}
227 #pragma omp parallel for lastprivate(,
228   for (i = 0; i < 16; ++i)
229     ;
230 // expected-error@+1 2 {{expected expression}}
231 #pragma omp parallel for lastprivate(, )
232   for (i = 0; i < 16; ++i)
233     ;
234 // expected-error@+1 {{expected expression}}
235 #pragma omp parallel for lastprivate()
236   for (i = 0; i < 16; ++i)
237     ;
238 // expected-error@+1 {{expected expression}}
239 #pragma omp parallel for lastprivate(int)
240   for (i = 0; i < 16; ++i)
241     ;
242 // expected-error@+1 {{expected variable name}}
243 #pragma omp parallel for lastprivate(0)
244   for (i = 0; i < 16; ++i)
245     ;
246 
247   int x, y, z;
248 #pragma omp parallel for lastprivate(x)
249   for (i = 0; i < 16; ++i)
250     ;
251 #pragma omp parallel for lastprivate(x, y)
252   for (i = 0; i < 16; ++i)
253     ;
254 #pragma omp parallel for lastprivate(x, y, z)
255   for (i = 0; i < 16; ++i)
256     ;
257 }
258 
259 void test_firstprivate() {
260   int i;
261 // expected-error@+2 {{expected ')'}} expected-note@+2 {{to match this '('}}
262 // expected-error@+1 {{expected expression}}
263 #pragma omp parallel for firstprivate(
264   for (i = 0; i < 16; ++i)
265     ;
266 
267 // expected-error@+2 {{expected ')'}} expected-note@+2 {{to match this '('}}
268 // expected-error@+1 2 {{expected expression}}
269 #pragma omp parallel for firstprivate(,
270   for (i = 0; i < 16; ++i)
271     ;
272 // expected-error@+1 2 {{expected expression}}
273 #pragma omp parallel for firstprivate(, )
274   for (i = 0; i < 16; ++i)
275     ;
276 // expected-error@+1 {{expected expression}}
277 #pragma omp parallel for firstprivate()
278   for (i = 0; i < 16; ++i)
279     ;
280 // expected-error@+1 {{expected expression}}
281 #pragma omp parallel for firstprivate(int)
282   for (i = 0; i < 16; ++i)
283     ;
284 // expected-error@+1 {{expected variable name}}
285 #pragma omp parallel for firstprivate(0)
286   for (i = 0; i < 16; ++i)
287     ;
288 
289   int x, y, z;
290 #pragma omp parallel for lastprivate(x) firstprivate(x)
291   for (i = 0; i < 16; ++i)
292     ;
293 #pragma omp parallel for lastprivate(x, y) firstprivate(x, y)
294   for (i = 0; i < 16; ++i)
295     ;
296 #pragma omp parallel for lastprivate(x, y, z) firstprivate(x, y, z)
297   for (i = 0; i < 16; ++i)
298     ;
299 }
300 
301 void test_loop_messages() {
302   float a[100], b[100], c[100];
303 // expected-error@+2 {{variable must be of integer or pointer type}}
304 #pragma omp parallel for
305   for (float fi = 0; fi < 10.0; fi++) {
306     c[(int)fi] = a[(int)fi] + b[(int)fi];
307   }
308 // expected-error@+2 {{variable must be of integer or pointer type}}
309 #pragma omp parallel for
310   for (double fi = 0; fi < 10.0; fi++) {
311     c[(int)fi] = a[(int)fi] + b[(int)fi];
312   }
313 }
314 
315