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