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