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