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