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