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