Clang Project

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