blob: 6f21a42208f4fceaf833356b52fd56a1c891ccc5 [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
3void foo() {
4}
5
6bool foobool(int argc) {
7 return argc;
8}
9
10struct S1; // expected-note 2 {{declared here}} expected-note 2 {{forward declaration of 'S1'}}
11extern S1 a;
12class S2 {
13 mutable int a;
14
15public:
16 S2() : a(0) {}
Alexey Bataev4a5bb772014-10-08 14:01:46 +000017 S2(const S2 &s2) : a(s2.a) {}
Alexey Bataevd1e40fb2014-06-26 12:05:45 +000018 static float S2s;
19 static const float S2sc;
20};
21const float S2::S2sc = 0;
22const S2 b;
23const S2 ba[5];
24class S3 {
25 int a;
26 S3 &operator=(const S3 &s3);
27
28public:
29 S3() : a(0) {}
Alexey Bataev4a5bb772014-10-08 14:01:46 +000030 S3(const S3 &s3) : a(s3.a) {}
Alexey Bataevd1e40fb2014-06-26 12:05:45 +000031};
32const S3 c;
33const S3 ca[5];
34extern const int f;
Alexey Bataev4a5bb772014-10-08 14:01:46 +000035class S4 {
Alexey Bataevd1e40fb2014-06-26 12:05:45 +000036 int a;
37 S4();
Alexey Bataev4a5bb772014-10-08 14:01:46 +000038 S4(const S4 &s4); // expected-note 2 {{implicitly declared private here}}
Alexey Bataevd1e40fb2014-06-26 12:05:45 +000039
40public:
41 S4(int v) : a(v) {}
42};
Alexey Bataev4a5bb772014-10-08 14:01:46 +000043class S5 {
Alexey Bataevd1e40fb2014-06-26 12:05:45 +000044 int a;
Alexey Bataev4a5bb772014-10-08 14:01:46 +000045 S5(const S5 &s5) : a(s5.a) {} // expected-note 4 {{implicitly declared private here}}
Alexey Bataevd1e40fb2014-06-26 12:05:45 +000046
47public:
48 S5() : a(0) {}
49 S5(int v) : a(v) {}
50};
51class S6 {
52 int a;
53 S6() : a(0) {}
54
55public:
56 S6(const S6 &s6) : a(s6.a) {}
57 S6(int v) : a(v) {}
58};
59
60S3 h;
61#pragma omp threadprivate(h) // expected-note 2 {{defined as threadprivate or thread local}}
62
63template <class I, class C>
64int foomain(int argc, char **argv) {
Alexey Bataev4a5bb772014-10-08 14:01:46 +000065 I e(4);
66 C g(5);
Alexey Bataevd1e40fb2014-06-26 12:05:45 +000067 int i;
68 int &j = i; // expected-note {{'j' defined here}}
69#pragma omp parallel
70#pragma omp single firstprivate // expected-error {{expected '(' after 'firstprivate'}}
71 foo();
72#pragma omp parallel
73#pragma omp single firstprivate( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
74 foo();
75#pragma omp parallel
76#pragma omp single firstprivate() // expected-error {{expected expression}}
77 foo();
78#pragma omp parallel
79#pragma omp single firstprivate(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
80 foo();
81#pragma omp parallel
82#pragma omp single firstprivate(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
83 foo();
84#pragma omp parallel
85#pragma omp single firstprivate(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
86 foo();
87#pragma omp parallel
88#pragma omp single firstprivate(argc)
89 foo();
90#pragma omp parallel
91#pragma omp single firstprivate(S1) // expected-error {{'S1' does not refer to a value}}
92 foo();
93#pragma omp parallel
94#pragma omp single firstprivate(a, b) // expected-error {{firstprivate variable with incomplete type 'S1'}}
95 foo();
96#pragma omp parallel
97#pragma omp single firstprivate(argv[1]) // expected-error {{expected variable name}}
98 foo();
99#pragma omp parallel
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000100#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 +0000101 foo();
102#pragma omp parallel
103#pragma omp single firstprivate(h) // expected-error {{threadprivate or thread local variable cannot be firstprivate}}
104 foo();
105#pragma omp parallel
106#pragma omp single linear(i) // expected-error {{unexpected OpenMP clause 'linear' in directive '#pragma omp single'}}
107 foo();
108#pragma omp parallel
109 {
110 int v = 0;
111 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?}}
112#pragma omp single firstprivate(i) // expected-error {{private variable cannot be firstprivate}}
113 foo();
114 v += i;
115 }
116#pragma omp parallel shared(i)
117#pragma omp parallel private(i)
118#pragma omp single firstprivate(j) // expected-error {{arguments of OpenMP clause 'firstprivate' cannot be of reference type}}
119 foo();
120#pragma omp parallel
121#pragma omp single firstprivate(i)
122 foo();
123#pragma omp parallel
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000124#pragma omp single firstprivate(g) // expected-error {{calling a private constructor of class 'S5'}}
Alexey Bataevd1e40fb2014-06-26 12:05:45 +0000125 foo();
126#pragma omp parallel private(i) // expected-note {{defined as private}}
127#pragma omp single firstprivate(i) // expected-error {{firstprivate variable must be shared}}
128 foo();
129#pragma omp parallel reduction(+ : i) // expected-note {{defined as reduction}}
130#pragma omp single firstprivate(i) // expected-error {{firstprivate variable must be shared}}
131 foo();
132 return 0;
133}
134
Alexey Bataev6ddfe1a2015-04-16 13:49:42 +0000135namespace A {
136double x;
137#pragma omp threadprivate(x) // expected-note {{defined as threadprivate or thread local}}
138}
139namespace B {
140using A::x;
141}
142
Alexey Bataevd1e40fb2014-06-26 12:05:45 +0000143int main(int argc, char **argv) {
144 const int d = 5;
145 const int da[5] = {0};
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000146 S4 e(4);
147 S5 g(5);
Alexey Bataevd1e40fb2014-06-26 12:05:45 +0000148 S3 m;
149 S6 n(2);
150 int i;
151 int &j = i; // expected-note {{'j' defined here}}
152#pragma omp parallel
153#pragma omp single firstprivate // expected-error {{expected '(' after 'firstprivate'}}
154 foo();
155#pragma omp parallel
156#pragma omp single firstprivate( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
157 foo();
158#pragma omp parallel
159#pragma omp single firstprivate() // expected-error {{expected expression}}
160 foo();
161#pragma omp parallel
162#pragma omp single firstprivate(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
163 foo();
164#pragma omp parallel
165#pragma omp single firstprivate(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
166 foo();
167#pragma omp parallel
168#pragma omp single firstprivate(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
169 foo();
170#pragma omp parallel
171#pragma omp single firstprivate(argc)
172 foo();
173#pragma omp parallel
174#pragma omp single firstprivate(S1) // expected-error {{'S1' does not refer to a value}}
175 foo();
176#pragma omp parallel
177#pragma omp single firstprivate(a, b, c, d, f) // expected-error {{firstprivate variable with incomplete type 'S1'}}
178 foo();
179#pragma omp parallel
180#pragma omp single firstprivate(argv[1]) // expected-error {{expected variable name}}
181 foo();
182#pragma omp parallel
183#pragma omp single firstprivate(2 * 2) // expected-error {{expected variable name}}
184 foo();
185#pragma omp parallel
186#pragma omp single firstprivate(ba) // OK
187 foo();
188#pragma omp parallel
189#pragma omp single firstprivate(ca) // OK
190 foo();
191#pragma omp parallel
192#pragma omp single firstprivate(da) // OK
193 foo();
194 int xa;
195#pragma omp parallel
196#pragma omp single firstprivate(xa) // OK
197 foo();
198#pragma omp parallel
199#pragma omp single firstprivate(S2::S2s) // OK
200 foo();
201#pragma omp parallel
202#pragma omp single firstprivate(S2::S2sc) // OK
203 foo();
204#pragma omp parallel
205#pragma omp single safelen(5) // expected-error {{unexpected OpenMP clause 'safelen' in directive '#pragma omp single'}}
206 foo();
207#pragma omp parallel
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000208#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 +0000209 foo();
210#pragma omp parallel
211#pragma omp single firstprivate(m) // OK
212 foo();
213#pragma omp parallel
Alexey Bataev6ddfe1a2015-04-16 13:49:42 +0000214#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 +0000215 foo();
216#pragma omp parallel
217#pragma omp single private(xa), firstprivate(xa) // expected-error {{private variable cannot be firstprivate}} expected-note {{defined as private}}
218 foo();
219#pragma omp parallel shared(xa)
220#pragma omp single firstprivate(xa) // OK: may be firstprivate
221 foo();
222#pragma omp parallel
223#pragma omp single firstprivate(j) // expected-error {{arguments of OpenMP clause 'firstprivate' cannot be of reference type}}
224 foo();
225#pragma omp parallel
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000226#pragma omp single firstprivate(g) // expected-error {{calling a private constructor of class 'S5'}}
Alexey Bataevd1e40fb2014-06-26 12:05:45 +0000227 foo();
228#pragma omp parallel
229#pragma omp single firstprivate(n) // OK
230 foo();
231#pragma omp parallel
232 {
233 int v = 0;
234 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?}}
235#pragma omp single firstprivate(i) // expected-error {{private variable cannot be firstprivate}}
236 foo();
237 v += i;
238 }
239#pragma omp parallel private(i) // expected-note {{defined as private}}
240#pragma omp single firstprivate(i) // expected-error {{firstprivate variable must be shared}}
241 foo();
242#pragma omp parallel reduction(+ : i) // expected-note {{defined as reduction}}
243#pragma omp single firstprivate(i) // expected-error {{firstprivate variable must be shared}}
244 foo();
245
246 return foomain<S4, S5>(argc, argv); // expected-note {{in instantiation of function template specialization 'foomain<S4, S5>' requested here}}
247}