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