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