1 // RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=45 %s -Wuninitialized
2 // RUN: %clang_cc1 -verify -fopenmp %s -Wuninitialized
3 
4 // RUN: %clang_cc1 -verify -fopenmp-simd -fopenmp-version=45 %s -Wuninitialized
5 // RUN: %clang_cc1 -verify -fopenmp-simd %s -Wuninitialized
6 
foo()7 void foo() {
8 }
9 
foobool(int argc)10 bool foobool(int argc) {
11   return argc;
12 }
13 extern int omp_default_mem_alloc;
14 struct S1; // expected-note 2 {{declared here}} expected-note 2 {{forward declaration of 'S1'}}
15 extern S1 a;
16 class S2 {
17   mutable int a;
18 
19 public:
S2()20   S2() : a(0) {}
S2(S2 & s2)21   S2(S2 &s2) : a(s2.a) {}
22   const S2 &operator =(const S2&) const;
23   S2 &operator =(const S2&);
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 {{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) {} // expected-note {{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;
74   int &j = i;
75 #pragma omp target
76 #pragma omp teams
77 #pragma omp distribute parallel for lastprivate // expected-error {{expected '(' after 'lastprivate'}}
78   for (int k = 0; k < argc; ++k)
79     ++k;
80 #pragma omp target
81 #pragma omp teams
82 #pragma omp distribute parallel for lastprivate( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
83   for (int k = 0; k < argc; ++k)
84     ++k;
85 #pragma omp target
86 #pragma omp teams
87 #pragma omp distribute parallel for lastprivate() // expected-error {{expected expression}}
88   for (int k = 0; k < argc; ++k)
89     ++k;
90 #pragma omp target
91 #pragma omp teams
92 #pragma omp distribute parallel for lastprivate(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
93   for (int k = 0; k < argc; ++k)
94     ++k;
95 #pragma omp target
96 #pragma omp teams
97 #pragma omp distribute parallel for lastprivate(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
98   for (int k = 0; k < argc; ++k)
99     ++k;
100 #pragma omp target
101 #pragma omp teams
102 #pragma omp distribute parallel for lastprivate(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
103   for (int k = 0; k < argc; ++k)
104     ++k;
105 #pragma omp target
106 #pragma omp teams
107 #pragma omp distribute parallel for 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 '('}}
108   for (int k = 0; k < argc; ++k)
109     ++k;
110 #pragma omp target
111 #pragma omp teams
112 #pragma omp distribute parallel for lastprivate(conditional: argc) lastprivate(conditional: // expected-error 2 {{use of undeclared identifier 'conditional'}} expected-error {{expected ')'}} expected-note {{to match this '('}}
113   for (int k = 0; k < argc; ++k)
114     ++k;
115 #pragma omp target
116 #pragma omp teams
117 #pragma omp distribute parallel for lastprivate(S1) // expected-error {{'S1' does not refer to a value}}
118   for (int k = 0; k < argc; ++k)
119     ++k;
120 #pragma omp target
121 #pragma omp teams
122 #pragma omp distribute parallel for lastprivate(a, b) // expected-error {{lastprivate variable with incomplete type 'S1'}} expected-warning {{Type 'const S2' is not trivially copyable and not guaranteed to be mapped correctly}}
123   for (int k = 0; k < argc; ++k)
124     ++k;
125 #pragma omp target
126 #pragma omp teams
127 #pragma omp distribute parallel for lastprivate(argv[1]) // expected-error {{expected variable name}}
128   for (int k = 0; k < argc; ++k)
129     ++k;
130 #pragma omp target
131 #pragma omp teams
132 #pragma omp distribute parallel for lastprivate(e, g) // expected-error 2 {{calling a private constructor of class 'S4'}} expected-warning 2 {{Type 'S4' is not trivially copyable and not guaranteed to be mapped correctly}}
133   for (int k = 0; k < argc; ++k)
134     ++k;
135 #pragma omp target
136 #pragma omp teams
137 #pragma omp distribute parallel for lastprivate(h) // expected-error {{threadprivate or thread local variable cannot be lastprivate}}
138   for (int k = 0; k < argc; ++k)
139     ++k;
140 
141   int v = 0;
142 #pragma omp target
143 #pragma omp teams
144   {
145 #pragma omp distribute parallel for lastprivate(i)
146     for (int k = 0; k < argc; ++k) {
147       i = k;
148       v += i;
149     }
150   }
151 #pragma omp target
152 #pragma omp teams private(i)
153 #pragma omp distribute parallel for lastprivate(j)
154   for (int k = 0; k < argc; ++k)
155     ++k;
156 #pragma omp target
157 #pragma omp teams
158 #pragma omp distribute parallel for lastprivate(i)
159   for (int k = 0; k < argc; ++k)
160     ++k;
161   return 0;
162 }
163 
bar(S4 a[2])164 void bar(S4 a[2]) {
165 #pragma omp target
166 #pragma omp teams
167 #pragma omp distribute parallel for lastprivate(a)
168   for (int i = 0; i < 2; ++i)
169     foo();
170 }
171 
172 namespace A {
173 double x;
174 #pragma omp threadprivate(x) // expected-note {{defined as threadprivate or thread local}}
175 }
176 namespace B {
177 using A::x;
178 }
179 
main(int argc,char ** argv)180 int main(int argc, char **argv) {
181   const int d = 5;       // expected-note {{'d' defined here}}
182   const int da[5] = {0}; // expected-note {{'da' defined here}}
183   S4 e(4);
184   S5 g(5);
185   S3 m;
186   S6 n(2);
187   int i;
188   int &j = i;
189 #pragma omp target
190 #pragma omp teams
191 #pragma omp distribute parallel for lastprivate // expected-error {{expected '(' after 'lastprivate'}}
192   for (i = 0; i < argc; ++i)
193     foo();
194 #pragma omp target
195 #pragma omp teams
196 #pragma omp distribute parallel for lastprivate( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
197   for (i = 0; i < argc; ++i)
198     foo();
199 #pragma omp target
200 #pragma omp teams
201 #pragma omp distribute parallel for lastprivate() // expected-error {{expected expression}}
202   for (i = 0; i < argc; ++i)
203     foo();
204 #pragma omp target
205 #pragma omp teams
206 #pragma omp distribute parallel for lastprivate(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
207   for (i = 0; i < argc; ++i)
208     foo();
209 #pragma omp target
210 #pragma omp teams
211 #pragma omp distribute parallel for lastprivate(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
212   for (i = 0; i < argc; ++i)
213     foo();
214 #pragma omp target
215 #pragma omp teams
216 #pragma omp distribute parallel for lastprivate(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
217   for (i = 0; i < argc; ++i)
218     foo();
219 #pragma omp target
220 #pragma omp teams
221 #pragma omp distribute parallel for lastprivate(argc)
222   for (i = 0; i < argc; ++i)
223     foo();
224 #pragma omp target
225 #pragma omp teams
226 #pragma omp distribute parallel for lastprivate(S1) // expected-error {{'S1' does not refer to a value}}
227   for (i = 0; i < argc; ++i)
228     foo();
229 #pragma omp target
230 #pragma omp teams
231 #pragma omp distribute parallel for 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}} expected-error {{incomplete type 'S1' where a complete type is required}} expected-warning {{Type 'const S2' is not trivially copyable and not guaranteed to be mapped correctly}} expected-warning {{Type 'const S3' is not trivially copyable and not guaranteed to be mapped correctly}}
232   for (i = 0; i < argc; ++i)
233     foo();
234 #pragma omp target
235 #pragma omp teams
236 #pragma omp distribute parallel for lastprivate(argv[1]) // expected-error {{expected variable name}}
237   for (i = 0; i < argc; ++i)
238     foo();
239 #pragma omp target
240 #pragma omp teams
241 #pragma omp distribute parallel for lastprivate(2 * 2) // expected-error {{expected variable name}}
242   for (i = 0; i < argc; ++i)
243     foo();
244 #pragma omp target
245 #pragma omp teams
246 #pragma omp distribute parallel for lastprivate(ba) // expected-warning {{Type 'const S2 [5]' is not trivially copyable and not guaranteed to be mapped correctly}}
247   for (i = 0; i < argc; ++i)
248     foo();
249 #pragma omp target
250 #pragma omp teams
251 #pragma omp distribute parallel for lastprivate(ca) // expected-error {{const-qualified variable without mutable fields cannot be lastprivate}} expected-warning {{Type 'const S3 [5]' is not trivially copyable and not guaranteed to be mapped correctly}}
252   for (i = 0; i < argc; ++i)
253     foo();
254 #pragma omp target
255 #pragma omp teams
256 #pragma omp distribute parallel for lastprivate(da) // expected-error {{const-qualified variable cannot be lastprivate}}
257   for (i = 0; i < argc; ++i)
258     foo();
259   int xa;
260 #pragma omp target
261 #pragma omp teams
262 #pragma omp distribute parallel for lastprivate(xa) // OK
263   for (i = 0; i < argc; ++i)
264     foo();
265 #pragma omp target
266 #pragma omp teams
267 #pragma omp distribute parallel for lastprivate(S2::S2s) // expected-error {{shared variable cannot be lastprivate}}
268   for (i = 0; i < argc; ++i)
269     foo();
270 #pragma omp target
271 #pragma omp teams
272 #pragma omp distribute parallel for lastprivate(S2::S2sc) // expected-error {{const-qualified variable cannot be lastprivate}}
273   for (i = 0; i < argc; ++i)
274     foo();
275 #pragma omp target
276 #pragma omp teams
277 #pragma omp distribute parallel for safelen(5) // expected-error {{unexpected OpenMP clause 'safelen' in directive '#pragma omp distribute parallel for'}}
278   for (i = 0; i < argc; ++i)
279     foo();
280 #pragma omp target
281 #pragma omp teams
282 #pragma omp distribute parallel for lastprivate(e, g) // expected-error {{calling a private constructor of class 'S4'}} expected-error {{calling a private constructor of class 'S5'}} expected-warning {{Type 'S4' is not trivially copyable and not guaranteed to be mapped correctly}} expected-warning {{Type 'S5' is not trivially copyable and not guaranteed to be mapped correctly}}
283   for (i = 0; i < argc; ++i)
284     foo();
285 #pragma omp target
286 #pragma omp teams
287 #pragma omp distribute parallel for lastprivate(m) // expected-error {{'operator=' is a private member of 'S3'}} expected-warning {{Type 'S3' is not trivially copyable and not guaranteed to be mapped correctly}}
288   for (i = 0; i < argc; ++i)
289     foo();
290 #pragma omp target
291 #pragma omp teams
292 #pragma omp distribute parallel for lastprivate(h) // expected-error {{threadprivate or thread local variable cannot be lastprivate}}
293   for (i = 0; i < argc; ++i)
294     foo();
295 #pragma omp target
296 #pragma omp teams
297 #pragma omp distribute parallel for lastprivate(B::x) // expected-error {{threadprivate or thread local variable cannot be lastprivate}}
298   for (i = 0; i < argc; ++i)
299     foo();
300 #pragma omp target
301 #pragma omp teams
302 #pragma omp distribute parallel for private(xa), lastprivate(xa) // expected-error {{private variable cannot be lastprivate}} expected-note {{defined as private}}
303   for (i = 0; i < argc; ++i)
304     foo();
305 #pragma omp target
306 #pragma omp teams
307 #pragma omp distribute parallel for lastprivate(i)
308   for (i = 0; i < argc; ++i)
309     foo();
310 #pragma omp target
311 #pragma omp teams
312 #pragma omp distribute parallel for lastprivate(xa)
313   for (i = 0; i < argc; ++i)
314     foo();
315 #pragma omp target
316 #pragma omp teams
317 #pragma omp distribute parallel for lastprivate(xa)
318   for (i = 0; i < argc; ++i)
319     foo();
320 #pragma omp target
321 #pragma omp teams
322 #pragma omp distribute parallel for lastprivate(j)
323   for (i = 0; i < argc; ++i)
324     foo();
325 // expected-error@+3 {{firstprivate variable cannot be lastprivate}} expected-note@+3 {{defined as firstprivate}}
326 #pragma omp target
327 #pragma omp teams
328 #pragma omp distribute parallel for firstprivate(m) lastprivate(m) // expected-warning {{Type 'S3' is not trivially copyable and not guaranteed to be mapped correctly}}
329   for (i = 0; i < argc; ++i)
330     foo();
331 // expected-error@+3 {{lastprivate variable cannot be firstprivate}} expected-note@+3 {{defined as lastprivate}}
332 #pragma omp target
333 #pragma omp teams
334 #pragma omp distribute parallel for lastprivate(n) firstprivate(n) // expected-error {{calling a private constructor of class 'S6'}} expected-warning {{Type 'S6' is not trivially copyable and not guaranteed to be mapped correctly}}
335   for (i = 0; i < argc; ++i)
336     foo();
337   static int si;
338 #pragma omp target
339 #pragma omp teams
340 #pragma omp distribute parallel for lastprivate(si) // OK
341   for (i = 0; i < argc; ++i)
342     si = i + 1;
343   return foomain<S4, S5>(argc, argv); // expected-note {{in instantiation of function template specialization 'foomain<S4, S5>' requested here}}
344 }
345