1 // RUN: %clang_cc1 -verify -fopenmp %s
2 
3 // RUN: %clang_cc1 -verify -fopenmp-simd %s
4 
5 void foo() {
6 }
7 
8 bool foobool(int argc) {
9   return argc;
10 }
11 
12 struct S1; // expected-note 2 {{declared here}} expected-note 2 {{forward declaration of 'S1'}}
13 extern S1 a;
14 class S2 {
15   mutable int a;
16 
17 public:
18   S2() : a(0) {}
19   S2(const S2 &s2) : a(s2.a) {}
20   static float S2s;
21   static const float S2sc;
22 };
23 const float S2::S2sc = 0;
24 const S2 b;
25 const S2 ba[5];
26 class S3 {
27   int a;
28   S3 &operator=(const S3 &s3);
29 
30 public:
31   S3() : a(0) {}
32   S3(const S3 &s3) : a(s3.a) {}
33 };
34 const S3 c;
35 const S3 ca[5];
36 extern const int f;
37 class S4 {
38   int a;
39   S4();
40   S4(const S4 &s4); // expected-note 2 {{implicitly declared private here}}
41 
42 public:
43   S4(int v) : a(v) {}
44 };
45 class S5 {
46   int a;
47   S5(const S5 &s5) : a(s5.a) {} // expected-note 4 {{implicitly declared private here}}
48 
49 public:
50   S5() : a(0) {}
51   S5(int v) : a(v) {}
52 };
53 class S6 {
54   int a;
55   S6() : a(0) {}
56 
57 public:
58   S6(const S6 &s6) : a(s6.a) {}
59   S6(int v) : a(v) {}
60 };
61 
62 S3 h;
63 #pragma omp threadprivate(h) // expected-note 2 {{defined as threadprivate or thread local}}
64 
65 template <class I, class C>
66 int foomain(int argc, char **argv) {
67   I e(4);
68   C g(5);
69   int i;
70   int &j = i;
71 #pragma omp parallel
72 #pragma omp sections firstprivate // expected-error {{expected '(' after 'firstprivate'}}
73   {
74     foo();
75   }
76 #pragma omp parallel
77 #pragma omp sections firstprivate( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
78   {
79     foo();
80   }
81 #pragma omp parallel
82 #pragma omp sections firstprivate() // expected-error {{expected expression}}
83   {
84     foo();
85   }
86 #pragma omp parallel
87 #pragma omp sections firstprivate(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
88   {
89     foo();
90   }
91 #pragma omp parallel
92 #pragma omp sections firstprivate(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
93   {
94     foo();
95   }
96 #pragma omp parallel
97 #pragma omp sections firstprivate(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
98   {
99     foo();
100   }
101 #pragma omp parallel
102 #pragma omp sections firstprivate(argc)
103   {
104     foo();
105   }
106 #pragma omp parallel
107 #pragma omp sections firstprivate(S1) // expected-error {{'S1' does not refer to a value}}
108   {
109     foo();
110   }
111 #pragma omp parallel
112 #pragma omp sections firstprivate(a, b) // expected-error {{firstprivate variable with incomplete type 'S1'}}
113   {
114     foo();
115   }
116 #pragma omp parallel
117 #pragma omp sections firstprivate(argv[1]) // expected-error {{expected variable name}}
118   {
119     foo();
120   }
121 #pragma omp parallel
122 #pragma omp sections firstprivate(e, g) // expected-error {{calling a private constructor of class 'S4'}} expected-error {{calling a private constructor of class 'S5'}}
123   {
124     foo();
125   }
126 #pragma omp parallel
127 #pragma omp sections firstprivate(h) // expected-error {{threadprivate or thread local variable cannot be firstprivate}}
128   {
129     foo();
130   }
131 #pragma omp parallel
132 #pragma omp sections linear(i) // expected-error {{unexpected OpenMP clause 'linear' in directive '#pragma omp sections'}}
133   {
134     foo();
135   }
136 #pragma omp parallel
137   {
138     int v = 0;
139     int i;                           // expected-note {{variable with automatic storage duration is predetermined as private; perhaps you forget to enclose 'omp sections' directive into a parallel or another task region?}}
140 #pragma omp sections firstprivate(i) // expected-error {{firstprivate variable must be shared}}
141     {
142       foo();
143     }
144     v += i;
145   }
146 #pragma omp parallel shared(i)
147 #pragma omp parallel private(i)
148 #pragma omp sections firstprivate(j)
149   {
150     foo();
151   }
152 #pragma omp parallel
153 #pragma omp sections firstprivate(i)
154   {
155     foo();
156   }
157 #pragma omp parallel
158 #pragma omp sections lastprivate(g) firstprivate(g) // expected-error {{calling a private constructor of class 'S5'}}
159   {
160     foo();
161   }
162 #pragma omp parallel private(i)      // expected-note {{defined as private}}
163 #pragma omp sections firstprivate(i) // expected-error {{firstprivate variable must be shared}}
164   {
165     foo();
166   }
167 #pragma omp parallel reduction(+ : i) // expected-note {{defined as reduction}}
168 #pragma omp sections firstprivate(i)  // expected-error {{firstprivate variable must be shared}}
169   {
170     foo();
171   }
172   return 0;
173 }
174 
175 namespace A {
176 double x;
177 #pragma omp threadprivate(x) // expected-note {{defined as threadprivate or thread local}}
178 }
179 namespace B {
180 using A::x;
181 }
182 
183 int main(int argc, char **argv) {
184   const int d = 5;
185   const int da[5] = {0};
186   S4 e(4);
187   S5 g(5);
188   S3 m;
189   S6 n(2);
190   int i;
191   int &j = i;
192 #pragma omp parallel
193 #pragma omp sections firstprivate // expected-error {{expected '(' after 'firstprivate'}}
194   {
195     foo();
196   }
197 #pragma omp parallel
198 #pragma omp sections firstprivate( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
199   {
200     foo();
201   }
202 #pragma omp parallel
203 #pragma omp sections firstprivate() // expected-error {{expected expression}}
204   {
205     foo();
206   }
207 #pragma omp parallel
208 #pragma omp sections firstprivate(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
209   {
210     foo();
211   }
212 #pragma omp parallel
213 #pragma omp sections firstprivate(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
214   {
215     foo();
216   }
217 #pragma omp parallel
218 #pragma omp sections firstprivate(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
219   {
220     foo();
221   }
222 #pragma omp parallel
223 #pragma omp sections firstprivate(argc)
224   {
225     foo();
226   }
227 #pragma omp parallel
228 #pragma omp sections firstprivate(S1) // expected-error {{'S1' does not refer to a value}}
229   {
230     foo();
231   }
232 #pragma omp parallel
233 #pragma omp sections firstprivate(a, b, c, d, f) // expected-error {{firstprivate variable with incomplete type 'S1'}}
234   {
235     foo();
236   }
237 #pragma omp parallel
238 #pragma omp sections firstprivate(argv[1]) // expected-error {{expected variable name}}
239   {
240     foo();
241   }
242 #pragma omp parallel
243 #pragma omp sections firstprivate(2 * 2) // expected-error {{expected variable name}}
244   {
245     foo();
246   }
247 #pragma omp parallel
248 #pragma omp sections firstprivate(ba) // OK
249   {
250     foo();
251   }
252 #pragma omp parallel
253 #pragma omp sections firstprivate(ca) // OK
254   {
255     foo();
256   }
257 #pragma omp parallel
258 #pragma omp sections firstprivate(da) // OK
259   {
260     foo();
261   }
262   int xa;
263 #pragma omp parallel
264 #pragma omp sections firstprivate(xa) // OK
265   {
266     foo();
267   }
268 #pragma omp parallel
269 #pragma omp sections firstprivate(S2::S2s) // OK
270   {
271     foo();
272   }
273 #pragma omp parallel
274 #pragma omp sections firstprivate(S2::S2sc) // OK
275   {
276     foo();
277   }
278 #pragma omp parallel
279 #pragma omp sections safelen(5) // expected-error {{unexpected OpenMP clause 'safelen' in directive '#pragma omp sections'}}
280   {
281     foo();
282   }
283 #pragma omp parallel
284 #pragma omp sections firstprivate(e, g) // expected-error {{calling a private constructor of class 'S4'}} expected-error {{calling a private constructor of class 'S5'}}
285   {
286     foo();
287   }
288 #pragma omp parallel
289 #pragma omp sections firstprivate(m) // OK
290   {
291     foo();
292   }
293 #pragma omp parallel
294 #pragma omp sections firstprivate(h, B::x) // expected-error 2 {{threadprivate or thread local variable cannot be firstprivate}}
295   {
296     foo();
297   }
298 #pragma omp parallel
299 #pragma omp sections private(xa), firstprivate(xa) // expected-error {{private variable cannot be firstprivate}} expected-note {{defined as private}}
300   {
301     foo();
302   }
303 #pragma omp parallel shared(xa)
304 #pragma omp sections firstprivate(xa) // OK: may be firstprivate
305   {
306     foo();
307   }
308 #pragma omp parallel
309 #pragma omp sections firstprivate(j)
310   {
311     foo();
312   }
313 #pragma omp parallel
314 #pragma omp sections lastprivate(g) firstprivate(g) // expected-error {{calling a private constructor of class 'S5'}}
315   {
316     foo();
317   }
318 #pragma omp parallel
319 #pragma omp sections lastprivate(n) firstprivate(n) // OK
320   {
321     foo();
322   }
323 #pragma omp parallel
324   {
325     int v = 0;
326     int i;                           // expected-note {{variable with automatic storage duration is predetermined as private; perhaps you forget to enclose 'omp sections' directive into a parallel or another task region?}}
327 #pragma omp sections firstprivate(i) // expected-error {{firstprivate variable must be shared}}
328     {
329       foo();
330     }
331     v += i;
332   }
333 #pragma omp parallel private(i)      // expected-note {{defined as private}}
334 #pragma omp sections firstprivate(i) // expected-error {{firstprivate variable must be shared}}
335   {
336     foo();
337   }
338 #pragma omp parallel reduction(+ : i) // expected-note {{defined as reduction}}
339 #pragma omp sections firstprivate(i)  // expected-error {{firstprivate variable must be shared}}
340   {
341     foo();
342   }
343   static int r;
344 #pragma omp sections firstprivate(r) // OK
345   {
346     foo();
347   }
348 
349   return foomain<S4, S5>(argc, argv); // expected-note {{in instantiation of function template specialization 'foomain<S4, S5>' requested here}}
350 }
351