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