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