blob: 4c714e392f97150c79560e97c049171657230bab [file] [log] [blame]
Alexey Bataevdb390212015-05-20 04:24:19 +00001// RUN: %clang_cc1 -verify -fopenmp %s
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00002
Alexey Bataeva8a9153a2017-12-29 18:07:07 +00003// RUN: %clang_cc1 -verify -fopenmp-simd %s
4
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00005void foo() {
6}
7
8bool foobool(int argc) {
9 return argc;
10}
11
12struct S1; // expected-note 2 {{declared here}} expected-note 2 {{forward declaration of 'S1'}}
13extern S1 a;
14class S2 {
15 mutable int a;
16
17public:
18 S2() : a(0) {}
Alexey Bataev4a5bb772014-10-08 14:01:46 +000019 S2(const S2 &s2) : a(s2.a) {}
Alexey Bataevd1e40fb2014-06-26 12:05:45 +000020 static float S2s;
21 static const float S2sc;
22};
23const float S2::S2sc = 0;
24const S2 b;
25const S2 ba[5];
26class S3 {
27 int a;
28 S3 &operator=(const S3 &s3);
29
30public:
31 S3() : a(0) {}
Alexey Bataev4a5bb772014-10-08 14:01:46 +000032 S3(const S3 &s3) : a(s3.a) {}
Alexey Bataevd1e40fb2014-06-26 12:05:45 +000033};
34const S3 c;
35const S3 ca[5];
36extern const int f;
Alexey Bataev4a5bb772014-10-08 14:01:46 +000037class S4 {
Alexey Bataevd1e40fb2014-06-26 12:05:45 +000038 int a;
39 S4();
Alexey Bataev4a5bb772014-10-08 14:01:46 +000040 S4(const S4 &s4); // expected-note 2 {{implicitly declared private here}}
Alexey Bataevd1e40fb2014-06-26 12:05:45 +000041
42public:
43 S4(int v) : a(v) {}
44};
Alexey Bataev4a5bb772014-10-08 14:01:46 +000045class S5 {
Alexey Bataevd1e40fb2014-06-26 12:05:45 +000046 int a;
Alexey Bataev4a5bb772014-10-08 14:01:46 +000047 S5(const S5 &s5) : a(s5.a) {} // expected-note 4 {{implicitly declared private here}}
Alexey Bataevd1e40fb2014-06-26 12:05:45 +000048
49public:
50 S5() : a(0) {}
51 S5(int v) : a(v) {}
52};
53class S6 {
54 int a;
55 S6() : a(0) {}
56
57public:
58 S6(const S6 &s6) : a(s6.a) {}
59 S6(int v) : a(v) {}
60};
61
62S3 h;
63#pragma omp threadprivate(h) // expected-note 2 {{defined as threadprivate or thread local}}
64
65template <class I, class C>
66int foomain(int argc, char **argv) {
Alexey Bataev4a5bb772014-10-08 14:01:46 +000067 I e(4);
68 C g(5);
Alexey Bataevd1e40fb2014-06-26 12:05:45 +000069 int i;
Alexey Bataevbd9fec12015-08-18 06:47:21 +000070 int &j = i;
Alexey Bataevd1e40fb2014-06-26 12:05:45 +000071#pragma omp parallel
72#pragma omp single firstprivate // expected-error {{expected '(' after 'firstprivate'}}
73 foo();
74#pragma omp parallel
75#pragma omp single firstprivate( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
76 foo();
77#pragma omp parallel
78#pragma omp single firstprivate() // expected-error {{expected expression}}
79 foo();
80#pragma omp parallel
81#pragma omp single firstprivate(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
82 foo();
83#pragma omp parallel
Alexey Bataevc5970622016-04-01 08:43:42 +000084#pragma omp single firstprivate(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
Alexey Bataevd1e40fb2014-06-26 12:05:45 +000085 foo();
86#pragma omp parallel
87#pragma omp single firstprivate(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
88 foo();
89#pragma omp parallel
90#pragma omp single firstprivate(argc)
91 foo();
92#pragma omp parallel
93#pragma omp single firstprivate(S1) // expected-error {{'S1' does not refer to a value}}
94 foo();
95#pragma omp parallel
96#pragma omp single firstprivate(a, b) // expected-error {{firstprivate variable with incomplete type 'S1'}}
97 foo();
98#pragma omp parallel
99#pragma omp single firstprivate(argv[1]) // expected-error {{expected variable name}}
100 foo();
101#pragma omp parallel
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000102#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 +0000103 foo();
104#pragma omp parallel
105#pragma omp single firstprivate(h) // expected-error {{threadprivate or thread local variable cannot be firstprivate}}
106 foo();
107#pragma omp parallel
108#pragma omp single linear(i) // expected-error {{unexpected OpenMP clause 'linear' in directive '#pragma omp single'}}
109 foo();
110#pragma omp parallel
111 {
112 int v = 0;
113 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 +0000114#pragma omp single firstprivate(i) // expected-error {{firstprivate variable must be shared}}
Alexey Bataevd1e40fb2014-06-26 12:05:45 +0000115 foo();
116 v += i;
117 }
118#pragma omp parallel shared(i)
119#pragma omp parallel private(i)
Alexey Bataevbd9fec12015-08-18 06:47:21 +0000120#pragma omp single firstprivate(j)
Alexey Bataevd1e40fb2014-06-26 12:05:45 +0000121 foo();
122#pragma omp parallel
123#pragma omp single firstprivate(i)
124 foo();
125#pragma omp parallel
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000126#pragma omp single firstprivate(g) // expected-error {{calling a private constructor of class 'S5'}}
Alexey Bataevd1e40fb2014-06-26 12:05:45 +0000127 foo();
128#pragma omp parallel private(i) // expected-note {{defined as private}}
129#pragma omp single firstprivate(i) // expected-error {{firstprivate variable must be shared}}
130 foo();
131#pragma omp parallel reduction(+ : i) // expected-note {{defined as reduction}}
132#pragma omp single firstprivate(i) // expected-error {{firstprivate variable must be shared}}
133 foo();
134 return 0;
135}
136
Alexey Bataev6ddfe1a2015-04-16 13:49:42 +0000137namespace A {
138double x;
139#pragma omp threadprivate(x) // expected-note {{defined as threadprivate or thread local}}
140}
141namespace B {
142using A::x;
143}
144
Alexey Bataevd1e40fb2014-06-26 12:05:45 +0000145int main(int argc, char **argv) {
146 const int d = 5;
147 const int da[5] = {0};
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000148 S4 e(4);
149 S5 g(5);
Alexey Bataevd1e40fb2014-06-26 12:05:45 +0000150 S3 m;
151 S6 n(2);
152 int i;
Alexey Bataevbd9fec12015-08-18 06:47:21 +0000153 int &j = i;
Alexey Bataevd1e40fb2014-06-26 12:05:45 +0000154#pragma omp parallel
155#pragma omp single firstprivate // expected-error {{expected '(' after 'firstprivate'}}
156 foo();
157#pragma omp parallel
158#pragma omp single firstprivate( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
159 foo();
160#pragma omp parallel
161#pragma omp single firstprivate() // expected-error {{expected expression}}
162 foo();
163#pragma omp parallel
164#pragma omp single firstprivate(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
165 foo();
166#pragma omp parallel
Alexey Bataevc5970622016-04-01 08:43:42 +0000167#pragma omp single firstprivate(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
Alexey Bataevd1e40fb2014-06-26 12:05:45 +0000168 foo();
169#pragma omp parallel
170#pragma omp single firstprivate(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
171 foo();
172#pragma omp parallel
173#pragma omp single firstprivate(argc)
174 foo();
175#pragma omp parallel
176#pragma omp single firstprivate(S1) // expected-error {{'S1' does not refer to a value}}
177 foo();
178#pragma omp parallel
179#pragma omp single firstprivate(a, b, c, d, f) // expected-error {{firstprivate variable with incomplete type 'S1'}}
180 foo();
181#pragma omp parallel
182#pragma omp single firstprivate(argv[1]) // expected-error {{expected variable name}}
183 foo();
184#pragma omp parallel
185#pragma omp single firstprivate(2 * 2) // expected-error {{expected variable name}}
186 foo();
187#pragma omp parallel
188#pragma omp single firstprivate(ba) // OK
189 foo();
190#pragma omp parallel
191#pragma omp single firstprivate(ca) // OK
192 foo();
193#pragma omp parallel
194#pragma omp single firstprivate(da) // OK
195 foo();
196 int xa;
197#pragma omp parallel
198#pragma omp single firstprivate(xa) // OK
199 foo();
200#pragma omp parallel
201#pragma omp single firstprivate(S2::S2s) // OK
202 foo();
203#pragma omp parallel
204#pragma omp single firstprivate(S2::S2sc) // OK
205 foo();
206#pragma omp parallel
207#pragma omp single safelen(5) // expected-error {{unexpected OpenMP clause 'safelen' in directive '#pragma omp single'}}
208 foo();
209#pragma omp parallel
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000210#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 +0000211 foo();
212#pragma omp parallel
213#pragma omp single firstprivate(m) // OK
214 foo();
215#pragma omp parallel
Alexey Bataev6ddfe1a2015-04-16 13:49:42 +0000216#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 +0000217 foo();
218#pragma omp parallel
219#pragma omp single private(xa), firstprivate(xa) // expected-error {{private variable cannot be firstprivate}} expected-note {{defined as private}}
220 foo();
221#pragma omp parallel shared(xa)
222#pragma omp single firstprivate(xa) // OK: may be firstprivate
223 foo();
224#pragma omp parallel
Alexey Bataevbd9fec12015-08-18 06:47:21 +0000225#pragma omp single firstprivate(j)
Alexey Bataevd1e40fb2014-06-26 12:05:45 +0000226 foo();
227#pragma omp parallel
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000228#pragma omp single firstprivate(g) // expected-error {{calling a private constructor of class 'S5'}}
Alexey Bataevd1e40fb2014-06-26 12:05:45 +0000229 foo();
230#pragma omp parallel
231#pragma omp single firstprivate(n) // OK
232 foo();
233#pragma omp parallel
234 {
235 int v = 0;
236 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 +0000237#pragma omp single firstprivate(i) // expected-error {{firstprivate variable must be shared}}
Alexey Bataevd1e40fb2014-06-26 12:05:45 +0000238 foo();
239 v += i;
240 }
241#pragma omp parallel private(i) // expected-note {{defined as private}}
242#pragma omp single firstprivate(i) // expected-error {{firstprivate variable must be shared}}
243 foo();
244#pragma omp parallel reduction(+ : i) // expected-note {{defined as reduction}}
245#pragma omp single firstprivate(i) // expected-error {{firstprivate variable must be shared}}
246 foo();
Kelvin Li4eea8c62015-09-15 18:56:58 +0000247 static int t;
248#pragma omp single firstprivate(t) // OK
249 foo();
Alexey Bataevd1e40fb2014-06-26 12:05:45 +0000250
251 return foomain<S4, S5>(argc, argv); // expected-note {{in instantiation of function template specialization 'foomain<S4, S5>' requested here}}
252}