[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / OpenMP / sections_firstprivate_messages.cpp
blob1b595f483c422dc7f850f2dce2e87aafb725cdc6
1 // RUN: %clang_cc1 -verify -fopenmp %s -Wuninitialized
3 // RUN: %clang_cc1 -verify -fopenmp-simd %s -Wuninitialized
5 extern int omp_default_mem_alloc;
6 void foo() {
9 bool foobool(int argc) {
10 return argc;
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;
18 public:
19 S2() : a(0) {}
20 S2(const S2 &s2) : a(s2.a) {}
21 static float S2s;
22 static const float S2sc;
24 const float S2::S2sc = 0;
25 const S2 b;
26 const S2 ba[5];
27 class S3 {
28 int a;
29 S3 &operator=(const S3 &s3);
31 public:
32 S3() : a(0) {}
33 S3(const S3 &s3) : a(s3.a) {}
35 const S3 c;
36 const S3 ca[5];
37 extern const int f;
38 class S4 {
39 int a;
40 S4();
41 S4(const S4 &s4); // expected-note 2 {{implicitly declared private here}}
43 public:
44 S4(int v) : a(v) {}
46 class S5 {
47 int a;
48 S5(const S5 &s5) : a(s5.a) {} // expected-note 4 {{implicitly declared private here}}
50 public:
51 S5() : a(0) {}
52 S5(int v) : a(v) {}
54 class S6 {
55 int a;
56 S6() : a(0) {}
58 public:
59 S6(const S6 &s6) : a(s6.a) {}
60 S6(int v) : a(v) {}
63 S3 h;
64 #pragma omp threadprivate(h) // expected-note 2 {{defined as threadprivate or thread local}}
66 template <class I, class C>
67 int foomain(int argc, char **argv) {
68 I e(4);
69 C g(5);
70 int i, z;
71 int &j = i;
72 #pragma omp parallel
73 #pragma omp sections firstprivate // expected-error {{expected '(' after 'firstprivate'}}
75 foo();
77 #pragma omp parallel
78 #pragma omp sections firstprivate( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
80 foo();
82 #pragma omp parallel
83 #pragma omp sections firstprivate() // expected-error {{expected expression}}
85 foo();
87 #pragma omp parallel
88 #pragma omp sections firstprivate(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
90 foo();
92 #pragma omp parallel
93 #pragma omp sections firstprivate(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
95 foo();
97 #pragma omp parallel
98 #pragma omp sections firstprivate(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
100 foo();
102 #pragma omp parallel
103 #pragma omp sections 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 '('}}
105 foo();
107 #pragma omp parallel
108 #pragma omp sections firstprivate(S1) // expected-error {{'S1' does not refer to a value}}
110 foo();
112 #pragma omp parallel
113 #pragma omp sections firstprivate(z, a, b) // expected-error {{firstprivate variable with incomplete type 'S1'}}
115 foo();
117 #pragma omp parallel
118 #pragma omp sections firstprivate(argv[1]) // expected-error {{expected variable name}}
120 foo();
122 #pragma omp parallel
123 #pragma omp sections firstprivate(e, g) // expected-error {{calling a private constructor of class 'S4'}} expected-error {{calling a private constructor of class 'S5'}}
125 foo();
127 #pragma omp parallel
128 #pragma omp sections firstprivate(h) // expected-error {{threadprivate or thread local variable cannot be firstprivate}}
130 foo();
132 #pragma omp parallel
133 #pragma omp sections linear(i) // expected-error {{unexpected OpenMP clause 'linear' in directive '#pragma omp sections'}}
135 foo();
137 #pragma omp parallel
139 int v = 0;
140 int i; // expected-note {{variable with automatic storage duration is predetermined as private; perhaps you forget to enclose 'omp sections' directive into a parallel or another task region?}}
141 #pragma omp sections firstprivate(i) // expected-error {{firstprivate variable must be shared}}
143 foo();
145 v += i;
147 #pragma omp parallel shared(i)
148 #pragma omp parallel private(i)
149 #pragma omp sections firstprivate(j)
151 foo();
153 #pragma omp parallel
154 #pragma omp sections firstprivate(i)
156 foo();
158 #pragma omp parallel
159 #pragma omp sections lastprivate(g) firstprivate(g) // expected-error {{calling a private constructor of class 'S5'}}
161 foo();
163 #pragma omp parallel private(i) // expected-note {{defined as private}}
164 #pragma omp sections firstprivate(i) // expected-error {{firstprivate variable must be shared}}
166 foo();
168 #pragma omp parallel reduction(+ : i) // expected-note {{defined as reduction}}
169 #pragma omp sections firstprivate(i) // expected-error {{firstprivate variable must be shared}}
171 foo();
173 return 0;
176 namespace A {
177 double x;
178 #pragma omp threadprivate(x) // expected-note {{defined as threadprivate or thread local}}
180 namespace B {
181 using A::x;
184 int main(int argc, char **argv) {
185 const int d = 5;
186 const int da[5] = {0};
187 S4 e(4);
188 S5 g(5);
189 S3 m;
190 S6 n(2);
191 int i, z;
192 int &j = i;
193 #pragma omp parallel
194 #pragma omp sections firstprivate // expected-error {{expected '(' after 'firstprivate'}}
196 foo();
198 #pragma omp parallel
199 #pragma omp sections firstprivate( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
201 foo();
203 #pragma omp parallel
204 #pragma omp sections firstprivate() // expected-error {{expected expression}}
206 foo();
208 #pragma omp parallel
209 #pragma omp sections firstprivate(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
211 foo();
213 #pragma omp parallel
214 #pragma omp sections firstprivate(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
216 foo();
218 #pragma omp parallel
219 #pragma omp sections firstprivate(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
221 foo();
223 #pragma omp parallel
224 #pragma omp sections firstprivate(argc, z)
226 foo();
228 #pragma omp parallel
229 #pragma omp sections firstprivate(S1) // expected-error {{'S1' does not refer to a value}}
231 foo();
233 #pragma omp parallel
234 #pragma omp sections firstprivate(a, b, c, d, f) // expected-error {{firstprivate variable with incomplete type 'S1'}}
236 foo();
238 #pragma omp parallel
239 #pragma omp sections firstprivate(argv[1]) // expected-error {{expected variable name}}
241 foo();
243 #pragma omp parallel
244 #pragma omp sections firstprivate(2 * 2) // expected-error {{expected variable name}}
246 foo();
248 #pragma omp parallel
249 #pragma omp sections firstprivate(ba) // OK
251 foo();
253 #pragma omp parallel
254 #pragma omp sections firstprivate(ca) // OK
256 foo();
258 #pragma omp parallel
259 #pragma omp sections firstprivate(da) // OK
261 foo();
263 int xa;
264 #pragma omp parallel
265 #pragma omp sections firstprivate(xa) // OK
267 foo();
269 #pragma omp parallel
270 #pragma omp sections firstprivate(S2::S2s) // OK
272 foo();
274 #pragma omp parallel
275 #pragma omp sections firstprivate(S2::S2sc) // OK
277 foo();
279 #pragma omp parallel
280 #pragma omp sections safelen(5) // expected-error {{unexpected OpenMP clause 'safelen' in directive '#pragma omp sections'}}
282 foo();
284 #pragma omp parallel
285 #pragma omp sections firstprivate(e, g) // expected-error {{calling a private constructor of class 'S4'}} expected-error {{calling a private constructor of class 'S5'}}
287 foo();
289 #pragma omp parallel
290 #pragma omp sections firstprivate(m) // OK
292 foo();
294 #pragma omp parallel
295 #pragma omp sections firstprivate(h, B::x) // expected-error 2 {{threadprivate or thread local variable cannot be firstprivate}}
297 foo();
299 #pragma omp parallel
300 #pragma omp sections private(xa), firstprivate(xa) // expected-error {{private variable cannot be firstprivate}} expected-note {{defined as private}}
302 foo();
304 #pragma omp parallel shared(xa)
305 #pragma omp sections firstprivate(xa) // OK: may be firstprivate
307 foo();
309 #pragma omp parallel
310 #pragma omp sections firstprivate(j)
312 foo();
314 #pragma omp parallel
315 #pragma omp sections lastprivate(g) firstprivate(g) // expected-error {{calling a private constructor of class 'S5'}}
317 foo();
319 #pragma omp parallel
320 #pragma omp sections lastprivate(n) firstprivate(n) // OK
322 foo();
324 #pragma omp parallel
326 int v = 0;
327 int i; // expected-note {{variable with automatic storage duration is predetermined as private; perhaps you forget to enclose 'omp sections' directive into a parallel or another task region?}}
328 #pragma omp sections firstprivate(i) // expected-error {{firstprivate variable must be shared}}
330 foo();
332 v += i;
334 #pragma omp parallel private(i) // expected-note {{defined as private}}
335 #pragma omp sections firstprivate(i) // expected-error {{firstprivate variable must be shared}}
337 foo();
339 #pragma omp parallel reduction(+ : i) // expected-note {{defined as reduction}}
340 #pragma omp sections firstprivate(i) // expected-error {{firstprivate variable must be shared}}
342 foo();
344 static int r;
345 #pragma omp sections firstprivate(r) // OK
347 foo();
350 return foomain<S4, S5>(argc, argv); // expected-note {{in instantiation of function template specialization 'foomain<S4, S5>' requested here}}