[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / OpenMP / parallel_masked_firstprivate_messages.cpp
blob26ad93d6953a913c037a3fa6ff4321ba51775d1d
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 void xxx(int argc) {
14 int fp; // expected-note {{initialize the variable 'fp' to silence this warning}}
15 #pragma omp parallel masked firstprivate(fp) // expected-warning {{variable 'fp' is uninitialized when used here}}
17 for (int i = 0; i < 10; ++i)
22 struct S1; // expected-note 2 {{declared here}} expected-note 2 {{forward declaration of 'S1'}}
23 extern S1 a;
24 class S2 {
25 mutable int a;
27 public:
28 S2() : a(0) {}
29 S2(const S2 &s2) : a(s2.a) {}
30 static float S2s;
31 static const float S2sc;
33 const float S2::S2sc = 0;
34 const S2 b;
35 const S2 ba[5];
36 class S3 {
37 int a;
38 S3 &operator=(const S3 &s3);
40 public:
41 S3() : a(0) {}
42 S3(const S3 &s3) : a(s3.a) {}
44 const S3 c;
45 const S3 ca[5];
46 extern const int f;
47 class S4 {
48 int a;
49 S4();
50 S4(const S4 &s4); // expected-note 2 {{implicitly declared private here}}
52 public:
53 S4(int v) : a(v) {}
55 class S5 {
56 int a;
57 S5(const S5 &s5) : a(s5.a) {} // expected-note 4 {{implicitly declared private here}}
59 public:
60 S5() : a(0) {}
61 S5(int v) : a(v) {}
63 class S6 {
64 int a;
65 S6() : a(0) {}
67 public:
68 S6(const S6 &s6) : a(s6.a) {}
69 S6(int v) : a(v) {}
72 S3 h;
73 #pragma omp threadprivate(h) // expected-note 2 {{defined as threadprivate or thread local}}
75 template <class I, class C>
76 int foomain(int argc, char **argv) {
77 I e(4);
78 C g(5);
79 int i, z;
80 int &j = i;
81 #pragma omp parallel masked firstprivate // expected-error {{expected '(' after 'firstprivate'}}
83 foo();
85 #pragma omp parallel masked firstprivate( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
87 foo();
89 #pragma omp parallel masked firstprivate() // expected-error {{expected expression}}
91 foo();
93 #pragma omp parallel masked firstprivate(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
95 foo();
97 #pragma omp parallel masked firstprivate(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
99 foo();
101 #pragma omp parallel masked firstprivate(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
103 foo();
105 #pragma omp parallel masked 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 '('}}
107 foo();
109 #pragma omp parallel masked firstprivate(S1) // expected-error {{'S1' does not refer to a value}}
111 foo();
113 #pragma omp parallel masked firstprivate(z, a, b) // expected-error {{firstprivate variable with incomplete type 'S1'}}
115 foo();
117 #pragma omp parallel masked firstprivate(argv[1]) // expected-error {{expected variable name}}
119 foo();
121 #pragma omp parallel masked firstprivate(e, g) // expected-error {{calling a private constructor of class 'S4'}} expected-error {{calling a private constructor of class 'S5'}}
123 foo();
125 #pragma omp parallel masked firstprivate(h) // expected-error {{threadprivate or thread local variable cannot be firstprivate}}
127 foo();
129 #pragma omp parallel masked linear(i) // expected-error {{unexpected OpenMP clause 'linear' in directive '#pragma omp parallel masked'}}
131 foo();
133 #pragma omp parallel
135 int v = 0;
136 int i;
137 #pragma omp parallel masked firstprivate(i)
139 foo();
141 v += i;
143 #pragma omp parallel shared(i)
144 #pragma omp parallel private(i)
145 #pragma omp parallel masked firstprivate(j)
147 foo();
149 #pragma omp parallel masked firstprivate(i)
151 foo();
153 #pragma omp parallel masked firstprivate(g) // expected-error {{calling a private constructor of class 'S5'}}
155 foo();
157 #pragma omp parallel private(i)
158 #pragma omp parallel masked firstprivate(i)
160 foo();
162 #pragma omp parallel reduction(+ : i)
163 #pragma omp parallel masked firstprivate(i)
165 foo();
167 return 0;
170 namespace A {
171 double x;
172 #pragma omp threadprivate(x) // expected-note {{defined as threadprivate or thread local}}
174 namespace B {
175 using A::x;
178 int 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, z;
186 int &j = i;
187 #pragma omp parallel masked firstprivate // expected-error {{expected '(' after 'firstprivate'}}
189 foo();
191 #pragma omp parallel masked firstprivate( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
193 foo();
195 #pragma omp parallel masked firstprivate() // expected-error {{expected expression}}
197 foo();
199 #pragma omp parallel masked firstprivate(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
201 foo();
203 #pragma omp parallel masked firstprivate(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
205 foo();
207 #pragma omp parallel masked firstprivate(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
209 foo();
211 #pragma omp parallel masked firstprivate(argc, z)
213 foo();
215 #pragma omp parallel masked firstprivate(S1) // expected-error {{'S1' does not refer to a value}}
217 foo();
219 #pragma omp parallel masked firstprivate(a, b, c, d, f) // expected-error {{firstprivate variable with incomplete type 'S1'}}
221 foo();
223 #pragma omp parallel masked firstprivate(argv[1]) // expected-error {{expected variable name}}
225 foo();
227 #pragma omp parallel masked firstprivate(2 * 2) // expected-error {{expected variable name}}
229 foo();
231 #pragma omp parallel masked firstprivate(ba) // OK
233 foo();
235 #pragma omp parallel masked firstprivate(ca) // OK
237 foo();
239 #pragma omp parallel masked firstprivate(da) // OK
241 foo();
243 int xa;
244 #pragma omp parallel masked firstprivate(xa) // OK
246 foo();
248 #pragma omp parallel masked firstprivate(S2::S2s) // OK
250 foo();
252 #pragma omp parallel masked firstprivate(S2::S2sc) // OK
254 foo();
256 #pragma omp parallel masked safelen(5) // expected-error {{unexpected OpenMP clause 'safelen' in directive '#pragma omp parallel masked'}}
258 foo();
260 #pragma omp parallel masked firstprivate(e, g) // expected-error {{calling a private constructor of class 'S4'}} expected-error {{calling a private constructor of class 'S5'}}
262 foo();
264 #pragma omp parallel masked firstprivate(m) // OK
266 foo();
268 #pragma omp parallel masked firstprivate(h, B::x) // expected-error 2 {{threadprivate or thread local variable cannot be firstprivate}}
270 foo();
272 #pragma omp parallel masked private(xa), firstprivate(xa) // expected-error {{private variable cannot be firstprivate}} expected-note {{defined as private}}
274 foo();
276 #pragma omp parallel shared(xa)
277 #pragma omp parallel masked firstprivate(xa) // OK: may be firstprivate
279 foo();
281 #pragma omp parallel masked firstprivate(j)
283 foo();
285 #pragma omp parallel masked firstprivate(g) // expected-error {{calling a private constructor of class 'S5'}}
287 foo();
289 #pragma omp parallel masked firstprivate(n) // OK
291 foo();
293 #pragma omp parallel
295 int v = 0;
296 int i;
297 #pragma omp parallel masked firstprivate(i)
299 foo();
301 v += i;
303 #pragma omp parallel private(i)
304 #pragma omp parallel masked firstprivate(i)
306 foo();
308 #pragma omp parallel reduction(+ : i)
309 #pragma omp parallel masked firstprivate(i)
311 foo();
313 static int r;
314 #pragma omp parallel masked firstprivate(r) // OK
316 foo();
319 return foomain<S4, S5>(argc, argv); // expected-note {{in instantiation of function template specialization 'foomain<S4, S5>' requested here}}