blob: 5b0b562869b22dc6aba00e3488d4587564211d8c [file] [log] [blame]
Alexey Bataevdb390212015-05-20 04:24:19 +00001// RUN: %clang_cc1 -verify -fopenmp %s
Alexey Bataevf29276e2014-06-18 04:14:57 +00002
Alexey Bataeva8a9153a2017-12-29 18:07:07 +00003// RUN: %clang_cc1 -verify -fopenmp-simd %s
4
Alexey Bataevf29276e2014-06-18 04:14:57 +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;
Alexey Bataev7ff55242014-06-19 09:13:45 +000016
Alexey Bataevf29276e2014-06-18 04:14:57 +000017public:
Alexey Bataev7ff55242014-06-19 09:13:45 +000018 S2() : a(0) {}
Alexey Bataevf29276e2014-06-18 04:14:57 +000019};
20const S2 b;
21const S2 ba[5];
22class S3 {
23 int a;
Alexey Bataev7ff55242014-06-19 09:13:45 +000024
Alexey Bataevf29276e2014-06-18 04:14:57 +000025public:
Alexey Bataev7ff55242014-06-19 09:13:45 +000026 S3() : a(0) {}
Alexey Bataevf29276e2014-06-18 04:14:57 +000027};
28const S3 ca[5];
Alexey Bataev03b340a2014-10-21 03:16:40 +000029class S4 {
Alexey Bataevf29276e2014-06-18 04:14:57 +000030 int a;
Alexey Bataev5129d3a2015-05-21 09:47:46 +000031 S4(); // expected-note {{implicitly declared private here}}
Alexey Bataev7ff55242014-06-19 09:13:45 +000032
Alexey Bataevf29276e2014-06-18 04:14:57 +000033public:
Alexey Bataev48c0bfb2016-01-20 09:07:54 +000034 S4(int v) : a(v) {
35#pragma omp for private(a) private(this->a)
36 for (int k = 0; k < v; ++k)
37 ++this->a;
38 }
Alexey Bataevf29276e2014-06-18 04:14:57 +000039};
Alexey Bataev03b340a2014-10-21 03:16:40 +000040class S5 {
Alexey Bataevf29276e2014-06-18 04:14:57 +000041 int a;
Alexey Bataev03b340a2014-10-21 03:16:40 +000042 S5() : a(0) {} // expected-note {{implicitly declared private here}}
Alexey Bataev7ff55242014-06-19 09:13:45 +000043
Alexey Bataevf29276e2014-06-18 04:14:57 +000044public:
Alexey Bataev7ff55242014-06-19 09:13:45 +000045 S5(int v) : a(v) {}
Alexey Bataev48c0bfb2016-01-20 09:07:54 +000046 S5 &operator=(S5 &s) {
47#pragma omp for private(a) private(this->a) private(s.a) // expected-error {{expected variable name or data member of current class}}
48 for (int k = 0; k < s.a; ++k)
49 ++s.a;
50 return *this;
51 }
52};
53
54template <typename T>
55class S6 {
56public:
57 T a;
58
59 S6() : a(0) {}
60 S6(T v) : a(v) {
61#pragma omp for private(a) private(this->a)
62 for (int k = 0; k < v; ++k)
63 ++this->a;
64 }
65 S6 &operator=(S6 &s) {
66#pragma omp for private(a) private(this->a) private(s.a) // expected-error {{expected variable name or data member of current class}}
67 for (int k = 0; k < s.a; ++k)
68 ++s.a;
69 return *this;
70 }
71};
72
73template <typename T>
74class S7 : public T {
75 T a;
76 S7() : a(0) {}
77
78public:
79 S7(T v) : a(v) {
80#pragma omp for private(a) private(this->a) private(T::a)
81 for (int k = 0; k < a.a; ++k)
82 ++this->a.a;
83 }
84 S7 &operator=(S7 &s) {
85#pragma omp for private(a) private(this->a) private(s.a) private(s.T::a) // expected-error 2 {{expected variable name or data member of current class}}
86 for (int k = 0; k < s.a.a; ++k)
87 ++s.a.a;
88 return *this;
89 }
Alexey Bataevf29276e2014-06-18 04:14:57 +000090};
91
92S3 h;
93#pragma omp threadprivate(h) // expected-note 2 {{defined as threadprivate or thread local}}
94
Alexey Bataev7ff55242014-06-19 09:13:45 +000095template <class I, class C>
96int foomain(I argc, C **argv) {
Alexey Bataevf29276e2014-06-18 04:14:57 +000097 I e(4);
98 I g(5);
99 int i;
Alexey Bataevbd9fec12015-08-18 06:47:21 +0000100 int &j = i;
Alexey Bataev7ff55242014-06-19 09:13:45 +0000101#pragma omp for private // expected-error {{expected '(' after 'private'}}
102 for (int k = 0; k < argc; ++k)
103 ++k;
104#pragma omp for private( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
105 for (int k = 0; k < argc; ++k)
106 ++k;
107#pragma omp for private() // expected-error {{expected expression}}
108 for (int k = 0; k < argc; ++k)
109 ++k;
110#pragma omp for private(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
111 for (int k = 0; k < argc; ++k)
112 ++k;
Alexey Bataevc5970622016-04-01 08:43:42 +0000113#pragma omp for private(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
Alexey Bataev7ff55242014-06-19 09:13:45 +0000114 for (int k = 0; k < argc; ++k)
115 ++k;
116#pragma omp for private(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
117 for (int k = 0; k < argc; ++k)
118 ++k;
119#pragma omp for private(argc)
120 for (int k = 0; k < argc; ++k)
121 ++k;
122#pragma omp for private(S1) // expected-error {{'S1' does not refer to a value}}
123 for (int k = 0; k < argc; ++k)
124 ++k;
125#pragma omp for private(a, b) // expected-error {{private variable with incomplete type 'S1'}}
126 for (int k = 0; k < argc; ++k)
127 ++k;
128#pragma omp for private(argv[1]) // expected-error {{expected variable name}}
129 for (int k = 0; k < argc; ++k)
130 ++k;
131#pragma omp for private(e, g)
132 for (int k = 0; k < argc; ++k)
133 ++k;
134#pragma omp for private(h) // expected-error {{threadprivate or thread local variable cannot be private}}
135 for (int k = 0; k < argc; ++k)
136 ++k;
137#pragma omp for shared(i) // expected-error {{unexpected OpenMP clause 'shared' in directive '#pragma omp for'}}
138 for (int k = 0; k < argc; ++k)
139 ++k;
140#pragma omp parallel
Alexey Bataevf29276e2014-06-18 04:14:57 +0000141 {
142 int v = 0;
143 int i;
Alexey Bataev7ff55242014-06-19 09:13:45 +0000144#pragma omp for private(i)
145 for (int k = 0; k < argc; ++k) {
146 i = k;
147 v += i;
148 }
Alexey Bataevf29276e2014-06-18 04:14:57 +0000149 }
Alexey Bataev7ff55242014-06-19 09:13:45 +0000150#pragma omp parallel shared(i)
151#pragma omp parallel private(i)
Alexey Bataevbd9fec12015-08-18 06:47:21 +0000152#pragma omp for private(j)
Alexey Bataev7ff55242014-06-19 09:13:45 +0000153 for (int k = 0; k < argc; ++k)
154 ++k;
155#pragma omp for private(i)
156 for (int k = 0; k < argc; ++k)
157 ++k;
Alexey Bataevf29276e2014-06-18 04:14:57 +0000158 return 0;
159}
160
Alexey Bataevf120c0d2015-05-19 07:46:42 +0000161void bar(S4 a[2]) {
162#pragma omp parallel
Alexey Bataev5129d3a2015-05-21 09:47:46 +0000163#pragma omp for private(a)
Alexey Bataevf120c0d2015-05-19 07:46:42 +0000164 for (int i = 0; i < 2; ++i)
165 foo();
166}
167
Alexey Bataev6ddfe1a2015-04-16 13:49:42 +0000168namespace A {
169double x;
170#pragma omp threadprivate(x) // expected-note {{defined as threadprivate or thread local}}
171}
172namespace B {
173using A::x;
174}
175
Alexey Bataevf29276e2014-06-18 04:14:57 +0000176int main(int argc, char **argv) {
Alexey Bataev03b340a2014-10-21 03:16:40 +0000177 S4 e(4);
178 S5 g(5);
Alexey Bataev48c0bfb2016-01-20 09:07:54 +0000179 S6<float> s6(0.0) , s6_0(1.0);
180 S7<S6<float> > s7(0.0) , s7_0(1.0);
Alexey Bataevf29276e2014-06-18 04:14:57 +0000181 int i;
Alexey Bataevbd9fec12015-08-18 06:47:21 +0000182 int &j = i;
Alexey Bataev7ff55242014-06-19 09:13:45 +0000183#pragma omp for private // expected-error {{expected '(' after 'private'}}
184 for (int k = 0; k < argc; ++k)
185 ++k;
186#pragma omp for private( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
187 for (int k = 0; k < argc; ++k)
188 ++k;
189#pragma omp for private() // expected-error {{expected expression}}
190 for (int k = 0; k < argc; ++k)
191 ++k;
192#pragma omp for private(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
193 for (int k = 0; k < argc; ++k)
194 ++k;
Alexey Bataevc5970622016-04-01 08:43:42 +0000195#pragma omp for private(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
Alexey Bataev7ff55242014-06-19 09:13:45 +0000196 for (int k = 0; k < argc; ++k)
197 ++k;
198#pragma omp for private(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
199 for (int k = 0; k < argc; ++k)
200 ++k;
201#pragma omp for private(argc)
202 for (int k = 0; k < argc; ++k)
203 ++k;
204#pragma omp for private(S1) // expected-error {{'S1' does not refer to a value}}
205 for (int k = 0; k < argc; ++k)
206 ++k;
207#pragma omp for private(a, b) // expected-error {{private variable with incomplete type 'S1'}}
208 for (int k = 0; k < argc; ++k)
209 ++k;
210#pragma omp for private(argv[1]) // expected-error {{expected variable name}}
211 for (int k = 0; k < argc; ++k)
212 ++k;
Alexey Bataev03b340a2014-10-21 03:16:40 +0000213#pragma omp for private(e, g) // expected-error {{calling a private constructor of class 'S4'}} expected-error {{calling a private constructor of class 'S5'}}
Alexey Bataev7ff55242014-06-19 09:13:45 +0000214 for (int k = 0; k < argc; ++k)
215 ++k;
216#pragma omp for private(h) // expected-error {{threadprivate or thread local variable cannot be private}}
217 for (int k = 0; k < argc; ++k)
218 ++k;
Alexey Bataev6ddfe1a2015-04-16 13:49:42 +0000219#pragma omp for private(B::x) // expected-error {{threadprivate or thread local variable cannot be private}}
220 for (int k = 0; k < argc; ++k)
221 ++k;
Alexey Bataev7ff55242014-06-19 09:13:45 +0000222#pragma omp for shared(i) // expected-error {{unexpected OpenMP clause 'shared' in directive '#pragma omp for'}}
223 for (int k = 0; k < argc; ++k)
224 ++k;
225#pragma omp parallel
Alexey Bataevf29276e2014-06-18 04:14:57 +0000226 {
227 int i;
Alexey Bataev7ff55242014-06-19 09:13:45 +0000228#pragma omp for private(i)
229 for (int k = 0; k < argc; ++k)
230 ++k;
Alexey Bataevf29276e2014-06-18 04:14:57 +0000231 }
Alexey Bataev7ff55242014-06-19 09:13:45 +0000232#pragma omp parallel shared(i)
233#pragma omp parallel private(i)
Alexey Bataevbd9fec12015-08-18 06:47:21 +0000234#pragma omp for private(j)
Alexey Bataev7ff55242014-06-19 09:13:45 +0000235 for (int k = 0; k < argc; ++k)
236 ++k;
237#pragma omp for private(i)
238 for (int k = 0; k < argc; ++k)
239 ++k;
Kelvin Li4eea8c62015-09-15 18:56:58 +0000240 static int si;
241#pragma omp for private(si) // OK
242 for(int k = 0; k < argc; ++k)
243 si = k + 1;
Alexey Bataevf29276e2014-06-18 04:14:57 +0000244
Alexey Bataev48c0bfb2016-01-20 09:07:54 +0000245 s6 = s6_0; // expected-note {{in instantiation of member function 'S6<float>::operator=' requested here}}
246 s7 = s7_0; // expected-note {{in instantiation of member function 'S7<S6<float> >::operator=' requested here}}
247 return foomain(argc, argv); // expected-note {{in instantiation of function template specialization 'foomain<int, char>' requested here}}
Alexey Bataevf29276e2014-06-18 04:14:57 +0000248}
249