1 // RUN: %clang_cc1 -fsyntax-only -fopenmp -triple x86_64-unknown-unknown -verify %s
3 // expected-error@+1 {{unexpected OpenMP directive '#pragma omp for'}}
6 // expected-error@+1 {{unexpected OpenMP directive '#pragma omp for'}}
9 void test_no_clause() {
12 for (i = 0; i < 16; ++i)
15 // expected-error@+2 {{statement after '#pragma omp for' must be a for loop}}
20 void test_branch_protected_scope() {
29 for (i = 0; i < 16; ++i) {
31 goto L1; // expected-error {{use of undeclared label 'L1'}}
33 return; // expected-error {{cannot return from OpenMP region}}
43 goto L2; // expected-error {{use of undeclared label 'L2'}}
48 void test_invalid_clause() {
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)
57 void test_non_identifiers() {
61 // expected-warning@+1 {{extra tokens at the end of '#pragma omp for' are ignored}}
63 for (i = 0; i < 16; ++i)
65 // expected-warning@+2 {{extra tokens at the end of '#pragma omp for' are ignored}}
67 #pragma omp for linear(x);
68 for (i = 0; i < 16; ++i)
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)
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)
86 void test_collapse() {
89 // expected-error@+1 {{expected '('}}
90 #pragma omp for collapse
91 for (i = 0; i < 16; ++i)
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)
99 // expected-error@+1 {{expected expression}}
100 #pragma omp for collapse()
101 for (i = 0; i < 16; ++i)
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)
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)
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)
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}}
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}}
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}}
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}}
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}}
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}}
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)
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}}
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)
173 // expected-error@+1 {{expression is not an integer constant expression}}
174 #pragma omp for collapse(foo())
175 for (i = 0; i < 16; ++i)
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)
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)
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)
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)
204 void test_private() {
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)
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)
219 // expected-error@+1 2 {{expected expression}}
220 #pragma omp for private(, )
221 for (i = 0; i < 16; ++i)
224 // expected-error@+1 {{expected expression}}
225 #pragma omp for private()
226 for (i = 0; i < 16; ++i)
229 // expected-error@+1 {{expected expression}}
230 #pragma omp for private(int)
231 for (i = 0; i < 16; ++i)
234 // expected-error@+1 {{expected variable name}}
235 #pragma omp for private(0)
236 for (i = 0; i < 16; ++i)
241 #pragma omp for private(x)
242 for (i = 0; i < 16; ++i)
245 #pragma omp for private(x, y)
246 for (i = 0; i < 16; ++i)
249 #pragma omp for private(x, y, z)
250 for (i = 0; i < 16; ++i) {
255 void test_lastprivate() {
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)
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)
271 // expected-error@+1 2 {{expected expression}}
272 #pragma omp for lastprivate(, )
273 for (i = 0; i < 16; ++i)
276 // expected-error@+1 {{expected expression}}
277 #pragma omp for lastprivate()
278 for (i = 0; i < 16; ++i)
281 // expected-error@+1 {{expected expression}}
282 #pragma omp for lastprivate(int)
283 for (i = 0; i < 16; ++i)
286 // expected-error@+1 {{expected variable name}}
287 #pragma omp for lastprivate(0)
288 for (i = 0; i < 16; ++i)
293 #pragma omp for lastprivate(x)
294 for (i = 0; i < 16; ++i)
297 #pragma omp for lastprivate(x, y)
298 for (i = 0; i < 16; ++i)
301 #pragma omp for lastprivate(x, y, z)
302 for (i = 0; i < 16; ++i)
306 void test_firstprivate() {
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)
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)
322 // expected-error@+1 2 {{expected expression}}
323 #pragma omp for firstprivate(, )
324 for (i = 0; i < 16; ++i)
327 // expected-error@+1 {{expected expression}}
328 #pragma omp for firstprivate()
329 for (i = 0; i < 16; ++i)
332 // expected-error@+1 {{expected expression}}
333 #pragma omp for firstprivate(int)
334 for (i = 0; i < 16; ++i)
337 // expected-error@+1 {{expected variable name}}
338 #pragma omp for firstprivate(0)
339 for (i = 0; i < 16; ++i)
344 #pragma omp for lastprivate(x) firstprivate(x)
345 for (i = 0; i < 16; ++i)
348 #pragma omp for lastprivate(x, y) firstprivate(x, y)
349 for (i = 0; i < 16; ++i)
352 #pragma omp for lastprivate(x, y, z) firstprivate(x, y, z)
353 for (i = 0; i < 16; ++i)
357 void test_loop_messages() {
358 float a[100], b[100], c[100];
360 // expected-error@+2 {{variable must be of integer or pointer type}}
362 for (float fi = 0; fi < 10.0; fi++) {
363 c[(int)fi] = a[(int)fi] + b[(int)fi];
366 // expected-error@+2 {{variable must be of integer or pointer type}}
368 for (double fi = 0; fi < 10.0; fi++) {
369 c[(int)fi] = a[(int)fi] + b[(int)fi];
372 // expected-warning@+2 {{OpenMP loop iteration variable cannot have more than 64 bits size and will be narrowed}}
374 for (__int128 ii = 0; ii < 10; ii++) {
375 c[ii] = a[ii] + b[ii];