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