• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // RUN: %clang_cc1 -fsyntax-only -fopenmp=libiomp5 -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 
test_no_clause()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 
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 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 
test_invalid_clause()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 
test_non_identifiers()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 // expected-error@+2 {{unexpected OpenMP clause 'linear' in directive '#pragma omp parallel for'}}
63 // expected-warning@+1 {{extra tokens at the end of '#pragma omp parallel for' are ignored}}
64 #pragma omp parallel for linear(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 // expected-warning@+1 {{extra tokens at the end of '#pragma omp parallel for' are ignored}}
74 #pragma omp parallel for, private(x);
75   for (i = 0; i < 16; ++i)
76     ;
77 }
78 
79 extern int foo();
80 
test_collapse()81 void test_collapse() {
82   int i;
83 // expected-error@+1 {{expected '('}}
84 #pragma omp parallel for collapse
85   for (i = 0; i < 16; ++i)
86     ;
87 // expected-error@+1 {{expected expression}} expected-error@+1 {{expected ')'}} expected-note@+1 {{to match this '('}}
88 #pragma omp parallel for collapse(
89   for (i = 0; i < 16; ++i)
90     ;
91 // expected-error@+1 {{expected expression}}
92 #pragma omp parallel for collapse()
93   for (i = 0; i < 16; ++i)
94     ;
95 // expected-error@+1 {{expected expression}} expected-error@+1 {{expected ')'}} expected-note@+1 {{to match this '('}}
96 #pragma omp parallel for collapse(,
97   for (i = 0; i < 16; ++i)
98     ;
99 // expected-error@+1 {{expected expression}}  expected-error@+1 {{expected ')'}} expected-note@+1 {{to match this '('}}
100 #pragma omp parallel for collapse(, )
101   for (i = 0; i < 16; ++i)
102     ;
103 // expected-warning@+2 {{extra tokens at the end of '#pragma omp parallel for' are ignored}}
104 // expected-error@+1 {{expected '('}}
105 #pragma omp parallel for collapse 4)
106   for (i = 0; i < 16; ++i)
107     ;
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-error@+2 {{expected ')'}}
119 // expected-note@+1 {{to match this '('}} expected-note@+1 {{as specified in 'collapse' clause}}
120 #pragma omp parallel for collapse(4, )
121   for (i = 0; i < 16; ++i)
122     ; // expected-error {{expected 4 for loops after '#pragma omp parallel for', but found only 1}}
123 // expected-note@+1 {{as specified in 'collapse' clause}}
124 #pragma omp parallel for collapse(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 // expected-error@+2 {{expected ')'}}
133 // expected-note@+1 {{to match this '('}} expected-note@+1 {{as specified in 'collapse' clause}}
134 #pragma omp parallel for collapse(4, , 4)
135   for (i = 0; i < 16; ++i)
136     ; // expected-error {{expected 4 for loops after '#pragma omp parallel for', but found only 1}}
137 #pragma omp parallel for collapse(4)
138   for (int i1 = 0; i1 < 16; ++i1)
139     for (int i2 = 0; i2 < 16; ++i2)
140       for (int i3 = 0; i3 < 16; ++i3)
141         for (int i4 = 0; i4 < 16; ++i4)
142           foo();
143 // expected-error@+2 {{expected ')'}}
144 // expected-note@+1 {{to match this '('}} expected-note@+1 {{as specified in 'collapse' clause}}
145 #pragma omp parallel for collapse(4, 8)
146   for (i = 0; i < 16; ++i)
147     ; // expected-error {{expected 4 for loops after '#pragma omp parallel for', but found only 1}}
148 // expected-error@+1 {{expression is not an integer constant expression}}
149 #pragma omp parallel for collapse(2.5)
150   for (i = 0; i < 16; ++i)
151     ;
152 // expected-error@+1 {{expression is not an integer constant expression}}
153 #pragma omp parallel for collapse(foo())
154   for (i = 0; i < 16; ++i)
155     ;
156 // expected-error@+1 {{argument to 'collapse' clause must be a positive integer value}}
157 #pragma omp parallel for collapse(-5)
158   for (i = 0; i < 16; ++i)
159     ;
160 // expected-error@+1 {{argument to 'collapse' clause must be a positive integer value}}
161 #pragma omp parallel for collapse(0)
162   for (i = 0; i < 16; ++i)
163     ;
164 // expected-error@+1 {{argument to 'collapse' clause must be a positive integer value}}
165 #pragma omp parallel for collapse(5 - 5)
166   for (i = 0; i < 16; ++i)
167     ;
168 }
169 
test_private()170 void test_private() {
171   int i;
172 // expected-error@+2 {{expected expression}}
173 // expected-error@+1 {{expected ')'}} expected-note@+1 {{to match this '('}}
174 #pragma omp parallel for private(
175   for (i = 0; i < 16; ++i)
176     ;
177 // expected-error@+2 {{expected ')'}} expected-note@+2 {{to match this '('}}
178 // expected-error@+1 2 {{expected expression}}
179 #pragma omp parallel for private(,
180   for (i = 0; i < 16; ++i)
181     ;
182 // expected-error@+1 2 {{expected expression}}
183 #pragma omp parallel for private(, )
184   for (i = 0; i < 16; ++i)
185     ;
186 // expected-error@+1 {{expected expression}}
187 #pragma omp parallel for private()
188   for (i = 0; i < 16; ++i)
189     ;
190 // expected-error@+1 {{expected expression}}
191 #pragma omp parallel for private(int)
192   for (i = 0; i < 16; ++i)
193     ;
194 // expected-error@+1 {{expected variable name}}
195 #pragma omp parallel for private(0)
196   for (i = 0; i < 16; ++i)
197     ;
198 
199   int x, y, z;
200 #pragma omp parallel for private(x)
201   for (i = 0; i < 16; ++i)
202     ;
203 #pragma omp parallel for private(x, y)
204   for (i = 0; i < 16; ++i)
205     ;
206 #pragma omp parallel for private(x, y, z)
207   for (i = 0; i < 16; ++i) {
208     x = y * i + z;
209   }
210 }
211 
test_lastprivate()212 void test_lastprivate() {
213   int i;
214 // expected-error@+2 {{expected ')'}} expected-note@+2 {{to match this '('}}
215 // expected-error@+1 {{expected expression}}
216 #pragma omp parallel for lastprivate(
217   for (i = 0; i < 16; ++i)
218     ;
219 
220 // expected-error@+2 {{expected ')'}} expected-note@+2 {{to match this '('}}
221 // expected-error@+1 2 {{expected expression}}
222 #pragma omp parallel for lastprivate(,
223   for (i = 0; i < 16; ++i)
224     ;
225 // expected-error@+1 2 {{expected expression}}
226 #pragma omp parallel for lastprivate(, )
227   for (i = 0; i < 16; ++i)
228     ;
229 // expected-error@+1 {{expected expression}}
230 #pragma omp parallel for lastprivate()
231   for (i = 0; i < 16; ++i)
232     ;
233 // expected-error@+1 {{expected expression}}
234 #pragma omp parallel for lastprivate(int)
235   for (i = 0; i < 16; ++i)
236     ;
237 // expected-error@+1 {{expected variable name}}
238 #pragma omp parallel for lastprivate(0)
239   for (i = 0; i < 16; ++i)
240     ;
241 
242   int x, y, z;
243 #pragma omp parallel for lastprivate(x)
244   for (i = 0; i < 16; ++i)
245     ;
246 #pragma omp parallel for lastprivate(x, y)
247   for (i = 0; i < 16; ++i)
248     ;
249 #pragma omp parallel for lastprivate(x, y, z)
250   for (i = 0; i < 16; ++i)
251     ;
252 }
253 
test_firstprivate()254 void test_firstprivate() {
255   int i;
256 // expected-error@+2 {{expected ')'}} expected-note@+2 {{to match this '('}}
257 // expected-error@+1 {{expected expression}}
258 #pragma omp parallel for firstprivate(
259   for (i = 0; i < 16; ++i)
260     ;
261 
262 // expected-error@+2 {{expected ')'}} expected-note@+2 {{to match this '('}}
263 // expected-error@+1 2 {{expected expression}}
264 #pragma omp parallel for firstprivate(,
265   for (i = 0; i < 16; ++i)
266     ;
267 // expected-error@+1 2 {{expected expression}}
268 #pragma omp parallel for firstprivate(, )
269   for (i = 0; i < 16; ++i)
270     ;
271 // expected-error@+1 {{expected expression}}
272 #pragma omp parallel for firstprivate()
273   for (i = 0; i < 16; ++i)
274     ;
275 // expected-error@+1 {{expected expression}}
276 #pragma omp parallel for firstprivate(int)
277   for (i = 0; i < 16; ++i)
278     ;
279 // expected-error@+1 {{expected variable name}}
280 #pragma omp parallel for firstprivate(0)
281   for (i = 0; i < 16; ++i)
282     ;
283 
284   int x, y, z;
285 #pragma omp parallel for lastprivate(x) firstprivate(x)
286   for (i = 0; i < 16; ++i)
287     ;
288 #pragma omp parallel for lastprivate(x, y) firstprivate(x, y)
289   for (i = 0; i < 16; ++i)
290     ;
291 #pragma omp parallel for lastprivate(x, y, z) firstprivate(x, y, z)
292   for (i = 0; i < 16; ++i)
293     ;
294 }
295 
test_loop_messages()296 void test_loop_messages() {
297   float a[100], b[100], c[100];
298 // expected-error@+2 {{variable must be of integer or pointer type}}
299 #pragma omp parallel for
300   for (float fi = 0; fi < 10.0; fi++) {
301     c[(int)fi] = a[(int)fi] + b[(int)fi];
302   }
303 // expected-error@+2 {{variable must be of integer or pointer type}}
304 #pragma omp parallel for
305   for (double fi = 0; fi < 10.0; fi++) {
306     c[(int)fi] = a[(int)fi] + b[(int)fi];
307   }
308 }
309 
310