blob: d97be2ab9be06c96819ed5861847abae7c2d2b45 [file] [log] [blame]
Alexey Bataeva9148882019-07-08 15:45:24 +00001// RUN: %clang_cc1 -verify -fopenmp %s -Wuninitialized
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00002
Alexey Bataeva9148882019-07-08 15:45:24 +00003// RUN: %clang_cc1 -verify -fopenmp-simd %s -Wuninitialized
Alexey Bataeva8a9153a2017-12-29 18:07:07 +00004
Alexey Bataeve04483e2019-03-27 14:14:31 +00005extern int omp_default_mem_alloc;
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00006void foo() {
7}
8
9bool foobool(int argc) {
10 return argc;
11}
12
13struct S1; // expected-note 2 {{declared here}} expected-note 2 {{forward declaration of 'S1'}}
14extern S1 a;
15class S2 {
16 mutable int a;
17
18public:
19 S2() : a(0) {}
Alexey Bataev4a5bb772014-10-08 14:01:46 +000020 S2(const S2 &s2) : a(s2.a) {}
Alexey Bataevd1e40fb2014-06-26 12:05:45 +000021 static float S2s;
22 static const float S2sc;
23};
24const float S2::S2sc = 0;
25const S2 b;
26const S2 ba[5];
27class S3 {
28 int a;
29 S3 &operator=(const S3 &s3);
30
31public:
32 S3() : a(0) {}
Alexey Bataev4a5bb772014-10-08 14:01:46 +000033 S3(const S3 &s3) : a(s3.a) {}
Alexey Bataevd1e40fb2014-06-26 12:05:45 +000034};
35const S3 c;
36const S3 ca[5];
37extern const int f;
Alexey Bataev4a5bb772014-10-08 14:01:46 +000038class S4 {
Alexey Bataevd1e40fb2014-06-26 12:05:45 +000039 int a;
40 S4();
Alexey Bataev4a5bb772014-10-08 14:01:46 +000041 S4(const S4 &s4); // expected-note 2 {{implicitly declared private here}}
Alexey Bataevd1e40fb2014-06-26 12:05:45 +000042
43public:
44 S4(int v) : a(v) {}
45};
Alexey Bataev4a5bb772014-10-08 14:01:46 +000046class S5 {
Alexey Bataevd1e40fb2014-06-26 12:05:45 +000047 int a;
Alexey Bataev4a5bb772014-10-08 14:01:46 +000048 S5(const S5 &s5) : a(s5.a) {} // expected-note 4 {{implicitly declared private here}}
Alexey Bataevd1e40fb2014-06-26 12:05:45 +000049
50public:
51 S5() : a(0) {}
52 S5(int v) : a(v) {}
53};
54class S6 {
55 int a;
56 S6() : a(0) {}
57
58public:
59 S6(const S6 &s6) : a(s6.a) {}
60 S6(int v) : a(v) {}
61};
62
63S3 h;
64#pragma omp threadprivate(h) // expected-note 2 {{defined as threadprivate or thread local}}
65
66template <class I, class C>
67int foomain(int argc, char **argv) {
Alexey Bataev4a5bb772014-10-08 14:01:46 +000068 I e(4);
69 C g(5);
Alexey Bataeva9148882019-07-08 15:45:24 +000070 int i, z;
Alexey Bataevbd9fec12015-08-18 06:47:21 +000071 int &j = i;
Alexey Bataevd1e40fb2014-06-26 12:05:45 +000072#pragma omp parallel
73#pragma omp single firstprivate // expected-error {{expected '(' after 'firstprivate'}}
74 foo();
75#pragma omp parallel
76#pragma omp single firstprivate( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
77 foo();
78#pragma omp parallel
79#pragma omp single firstprivate() // expected-error {{expected expression}}
80 foo();
81#pragma omp parallel
82#pragma omp single firstprivate(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
83 foo();
84#pragma omp parallel
Alexey Bataevc5970622016-04-01 08:43:42 +000085#pragma omp single firstprivate(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
Alexey Bataevd1e40fb2014-06-26 12:05:45 +000086 foo();
87#pragma omp parallel
88#pragma omp single firstprivate(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
89 foo();
90#pragma omp parallel
Alexey Bataeve04483e2019-03-27 14:14:31 +000091#pragma omp single 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 '('}}
Alexey Bataevd1e40fb2014-06-26 12:05:45 +000092 foo();
93#pragma omp parallel
94#pragma omp single firstprivate(S1) // expected-error {{'S1' does not refer to a value}}
95 foo();
96#pragma omp parallel
Alexey Bataeva9148882019-07-08 15:45:24 +000097#pragma omp single firstprivate(z, a, b) // expected-error {{firstprivate variable with incomplete type 'S1'}}
Alexey Bataevd1e40fb2014-06-26 12:05:45 +000098 foo();
99#pragma omp parallel
100#pragma omp single firstprivate(argv[1]) // expected-error {{expected variable name}}
101 foo();
102#pragma omp parallel
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000103#pragma omp single firstprivate(e, g) // expected-error {{calling a private constructor of class 'S4'}} expected-error {{calling a private constructor of class 'S5'}}
Alexey Bataevd1e40fb2014-06-26 12:05:45 +0000104 foo();
105#pragma omp parallel
106#pragma omp single firstprivate(h) // expected-error {{threadprivate or thread local variable cannot be firstprivate}}
107 foo();
108#pragma omp parallel
109#pragma omp single linear(i) // expected-error {{unexpected OpenMP clause 'linear' in directive '#pragma omp single'}}
110 foo();
111#pragma omp parallel
112 {
113 int v = 0;
114 int i; // expected-note {{variable with automatic storage duration is predetermined as private; perhaps you forget to enclose 'omp single' directive into a parallel or another task region?}}
Alexey Bataevdffa93a2015-12-10 08:20:58 +0000115#pragma omp single firstprivate(i) // expected-error {{firstprivate variable must be shared}}
Alexey Bataevd1e40fb2014-06-26 12:05:45 +0000116 foo();
117 v += i;
118 }
119#pragma omp parallel shared(i)
120#pragma omp parallel private(i)
Alexey Bataevbd9fec12015-08-18 06:47:21 +0000121#pragma omp single firstprivate(j)
Alexey Bataevd1e40fb2014-06-26 12:05:45 +0000122 foo();
123#pragma omp parallel
124#pragma omp single firstprivate(i)
125 foo();
126#pragma omp parallel
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000127#pragma omp single firstprivate(g) // expected-error {{calling a private constructor of class 'S5'}}
Alexey Bataevd1e40fb2014-06-26 12:05:45 +0000128 foo();
129#pragma omp parallel private(i) // expected-note {{defined as private}}
130#pragma omp single firstprivate(i) // expected-error {{firstprivate variable must be shared}}
131 foo();
132#pragma omp parallel reduction(+ : i) // expected-note {{defined as reduction}}
133#pragma omp single firstprivate(i) // expected-error {{firstprivate variable must be shared}}
134 foo();
135 return 0;
136}
137
Alexey Bataev6ddfe1a2015-04-16 13:49:42 +0000138namespace A {
139double x;
140#pragma omp threadprivate(x) // expected-note {{defined as threadprivate or thread local}}
141}
142namespace B {
143using A::x;
144}
145
Alexey Bataevd1e40fb2014-06-26 12:05:45 +0000146int main(int argc, char **argv) {
147 const int d = 5;
148 const int da[5] = {0};
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000149 S4 e(4);
150 S5 g(5);
Alexey Bataevd1e40fb2014-06-26 12:05:45 +0000151 S3 m;
152 S6 n(2);
Alexey Bataeva9148882019-07-08 15:45:24 +0000153 int i, z;
Alexey Bataevbd9fec12015-08-18 06:47:21 +0000154 int &j = i;
Alexey Bataevd1e40fb2014-06-26 12:05:45 +0000155#pragma omp parallel
156#pragma omp single firstprivate // expected-error {{expected '(' after 'firstprivate'}}
157 foo();
158#pragma omp parallel
159#pragma omp single firstprivate( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
160 foo();
161#pragma omp parallel
162#pragma omp single firstprivate() // expected-error {{expected expression}}
163 foo();
164#pragma omp parallel
165#pragma omp single firstprivate(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
166 foo();
167#pragma omp parallel
Alexey Bataevc5970622016-04-01 08:43:42 +0000168#pragma omp single firstprivate(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
Alexey Bataevd1e40fb2014-06-26 12:05:45 +0000169 foo();
170#pragma omp parallel
171#pragma omp single firstprivate(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
172 foo();
173#pragma omp parallel
Alexey Bataeva9148882019-07-08 15:45:24 +0000174#pragma omp single firstprivate(argc, z)
Alexey Bataevd1e40fb2014-06-26 12:05:45 +0000175 foo();
176#pragma omp parallel
177#pragma omp single firstprivate(S1) // expected-error {{'S1' does not refer to a value}}
178 foo();
179#pragma omp parallel
180#pragma omp single firstprivate(a, b, c, d, f) // expected-error {{firstprivate variable with incomplete type 'S1'}}
181 foo();
182#pragma omp parallel
183#pragma omp single firstprivate(argv[1]) // expected-error {{expected variable name}}
184 foo();
185#pragma omp parallel
186#pragma omp single firstprivate(2 * 2) // expected-error {{expected variable name}}
187 foo();
188#pragma omp parallel
189#pragma omp single firstprivate(ba) // OK
190 foo();
191#pragma omp parallel
192#pragma omp single firstprivate(ca) // OK
193 foo();
194#pragma omp parallel
195#pragma omp single firstprivate(da) // OK
196 foo();
197 int xa;
198#pragma omp parallel
199#pragma omp single firstprivate(xa) // OK
200 foo();
201#pragma omp parallel
202#pragma omp single firstprivate(S2::S2s) // OK
203 foo();
204#pragma omp parallel
205#pragma omp single firstprivate(S2::S2sc) // OK
206 foo();
207#pragma omp parallel
208#pragma omp single safelen(5) // expected-error {{unexpected OpenMP clause 'safelen' in directive '#pragma omp single'}}
209 foo();
210#pragma omp parallel
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000211#pragma omp single firstprivate(e, g) // expected-error {{calling a private constructor of class 'S4'}} expected-error {{calling a private constructor of class 'S5'}}
Alexey Bataevd1e40fb2014-06-26 12:05:45 +0000212 foo();
213#pragma omp parallel
214#pragma omp single firstprivate(m) // OK
215 foo();
216#pragma omp parallel
Alexey Bataev6ddfe1a2015-04-16 13:49:42 +0000217#pragma omp single firstprivate(h, B::x) // expected-error 2 {{threadprivate or thread local variable cannot be firstprivate}}
Alexey Bataevd1e40fb2014-06-26 12:05:45 +0000218 foo();
219#pragma omp parallel
220#pragma omp single private(xa), firstprivate(xa) // expected-error {{private variable cannot be firstprivate}} expected-note {{defined as private}}
221 foo();
222#pragma omp parallel shared(xa)
223#pragma omp single firstprivate(xa) // OK: may be firstprivate
224 foo();
225#pragma omp parallel
Alexey Bataevbd9fec12015-08-18 06:47:21 +0000226#pragma omp single firstprivate(j)
Alexey Bataevd1e40fb2014-06-26 12:05:45 +0000227 foo();
228#pragma omp parallel
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000229#pragma omp single firstprivate(g) // expected-error {{calling a private constructor of class 'S5'}}
Alexey Bataevd1e40fb2014-06-26 12:05:45 +0000230 foo();
231#pragma omp parallel
232#pragma omp single firstprivate(n) // OK
233 foo();
234#pragma omp parallel
235 {
236 int v = 0;
237 int i; // expected-note {{variable with automatic storage duration is predetermined as private; perhaps you forget to enclose 'omp single' directive into a parallel or another task region?}}
Alexey Bataevdffa93a2015-12-10 08:20:58 +0000238#pragma omp single firstprivate(i) // expected-error {{firstprivate variable must be shared}}
Alexey Bataevd1e40fb2014-06-26 12:05:45 +0000239 foo();
240 v += i;
241 }
242#pragma omp parallel private(i) // expected-note {{defined as private}}
243#pragma omp single firstprivate(i) // expected-error {{firstprivate variable must be shared}}
244 foo();
245#pragma omp parallel reduction(+ : i) // expected-note {{defined as reduction}}
246#pragma omp single firstprivate(i) // expected-error {{firstprivate variable must be shared}}
247 foo();
Kelvin Li4eea8c62015-09-15 18:56:58 +0000248 static int t;
249#pragma omp single firstprivate(t) // OK
250 foo();
Alexey Bataevd1e40fb2014-06-26 12:05:45 +0000251
252 return foomain<S4, S5>(argc, argv); // expected-note {{in instantiation of function template specialization 'foomain<S4, S5>' requested here}}
253}