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