Clang Project

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