Clang Project

clang_source_code/test/OpenMP/taskloop_private_messages.cpp
1// RUN: %clang_cc1 -verify -fopenmp %s
2
3// RUN: %clang_cc1 -verify -fopenmp-simd %s
4
5typedef void **omp_allocator_handle_t;
6extern const omp_allocator_handle_t omp_default_mem_alloc;
7extern const omp_allocator_handle_t omp_large_cap_mem_alloc;
8extern const omp_allocator_handle_t omp_const_mem_alloc;
9extern const omp_allocator_handle_t omp_high_bw_mem_alloc;
10extern const omp_allocator_handle_t omp_low_lat_mem_alloc;
11extern const omp_allocator_handle_t omp_cgroup_mem_alloc;
12extern const omp_allocator_handle_t omp_pteam_mem_alloc;
13extern const omp_allocator_handle_t omp_thread_mem_alloc;
14
15void foo() {
16}
17
18bool foobool(int argc) {
19  return argc;
20}
21
22struct S1; // expected-note 2 {{declared here}} expected-note 2 {{forward declaration of 'S1'}}
23extern S1 a;
24class S2 {
25  mutable int a;
26
27public:
28  S2() : a(0) {}
29};
30const S2 b;
31const S2 ba[5];
32class S3 {
33  int a;
34
35public:
36  S3() : a(0) {}
37};
38const S3 ca[5];
39class S4 {
40  int a;
41  S4(); // expected-note {{implicitly declared private here}}
42
43public:
44  S4(int v) : a(v) {
45#pragma omp taskloop private(a) private(this->a)
46    for (int k = 0; k < v; ++k)
47      ++this->a;
48  }
49};
50class S5 {
51  int a;
52  S5() : a(0) {} // expected-note {{implicitly declared private here}}
53
54public:
55  S5(int v) : a(v) {}
56  S5 &operator=(S5 &s) {
57#pragma omp taskloop private(a) private(this->a) private(s.a) // expected-error {{expected variable name or data member of current class}}
58    for (int k = 0; k < s.a; ++k)
59      ++s.a;
60    return *this;
61  }
62};
63
64template <typename T>
65class S6 {
66public:
67  T a;
68
69  S6() : a(0) {}
70  S6(T v) : a(v) {
71#pragma omp taskloop private(a) private(this->a) allocate(omp_thread_mem_alloc: a) // expected-warning {{allocator with the 'thread' trait access has unspecified behavior on 'taskloop' directive}}
72    for (int k = 0; k < v; ++k)
73      ++this->a;
74  }
75  S6 &operator=(S6 &s) {
76#pragma omp taskloop private(a) private(this->a) private(s.a) // expected-error {{expected variable name or data member of current class}}
77    for (int k = 0; k < s.a; ++k)
78      ++s.a;
79    return *this;
80  }
81};
82
83template <typename T>
84class S7 : public T {
85  T a;
86  S7() : a(0) {}
87
88public:
89  S7(T v) : a(v) {
90#pragma omp taskloop private(a) private(this->a) private(T::a)
91    for (int k = 0; k < a.a; ++k)
92      ++this->a.a;
93  }
94  S7 &operator=(S7 &s) {
95#pragma omp taskloop private(a) private(this->a) private(s.a) private(s.T::a) // expected-error 2 {{expected variable name or data member of current class}}
96    for (int k = 0; k < s.a.a; ++k)
97      ++s.a.a;
98    return *this;
99  }
100};
101
102S3 h;
103#pragma omp threadprivate(h) // expected-note 2 {{defined as threadprivate or thread local}}
104
105template <class I, class C>
106int foomain(I argc, C **argv) {
107  I e(4);
108  I g(5);
109  int i;
110  int &j = i;
111#pragma omp taskloop private // expected-error {{expected '(' after 'private'}}
112  for (int k = 0; k < argc; ++k)
113    ++k;
114#pragma omp taskloop private( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
115  for (int k = 0; k < argc; ++k)
116    ++k;
117#pragma omp taskloop private() // expected-error {{expected expression}}
118  for (int k = 0; k < argc; ++k)
119    ++k;
120#pragma omp taskloop private(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
121  for (int k = 0; k < argc; ++k)
122    ++k;
123#pragma omp taskloop private(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
124  for (int k = 0; k < argc; ++k)
125    ++k;
126#pragma omp taskloop private(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
127  for (int k = 0; k < argc; ++k)
128    ++k;
129#pragma omp taskloop private(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 '('}}
130  for (int k = 0; k < argc; ++k)
131    ++k;
132#pragma omp taskloop private(S1) // expected-error {{'S1' does not refer to a value}}
133  for (int k = 0; k < argc; ++k)
134    ++k;
135#pragma omp taskloop private(a, b) // expected-error {{private variable with incomplete type 'S1'}}
136  for (int k = 0; k < argc; ++k)
137    ++k;
138#pragma omp taskloop private(argv[1]) // expected-error {{expected variable name}}
139  for (int k = 0; k < argc; ++k)
140    ++k;
141#pragma omp taskloop private(e, g)
142  for (int k = 0; k < argc; ++k)
143    ++k;
144#pragma omp taskloop private(h) // expected-error {{threadprivate or thread local variable cannot be private}}
145  for (int k = 0; k < argc; ++k)
146    ++k;
147#pragma omp taskloop shared(i)
148  for (int k = 0; k < argc; ++k)
149    ++k;
150#pragma omp parallel
151  {
152    int v = 0;
153    int i;
154#pragma omp taskloop private(i)
155    for (int k = 0; k < argc; ++k) {
156      i = k;
157      v += i;
158    }
159  }
160#pragma omp parallel shared(i)
161#pragma omp parallel private(i)
162#pragma omp taskloop private(j)
163  for (int k = 0; k < argc; ++k)
164    ++k;
165#pragma omp taskloop private(i)
166  for (int k = 0; k < argc; ++k)
167    ++k;
168  return 0;
169}
170
171void bar(S4 a[2]) {
172#pragma omp parallel
173#pragma omp taskloop private(a)
174  for (int i = 0; i < 2; ++i)
175    foo();
176}
177
178namespace A {
179double x;
180#pragma omp threadprivate(x) // expected-note {{defined as threadprivate or thread local}}
181}
182namespace B {
183using A::x;
184}
185
186int main(int argc, char **argv) {
187  S4 e(4);
188  S5 g(5);
189  S6<float> s6(0.0) , s6_0(1.0); // expected-note {{in instantiation of member function 'S6<float>::S6' requested here}}
190  S7<S6<float> > s7(0.0) , s7_0(1.0);
191  int i;
192  int &j = i;
193#pragma omp taskloop private // expected-error {{expected '(' after 'private'}}
194  for (int k = 0; k < argc; ++k)
195    ++k;
196#pragma omp taskloop private( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
197  for (int k = 0; k < argc; ++k)
198    ++k;
199#pragma omp taskloop private() // expected-error {{expected expression}}
200  for (int k = 0; k < argc; ++k)
201    ++k;
202#pragma omp taskloop private(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
203  for (int k = 0; k < argc; ++k)
204    ++k;
205#pragma omp taskloop private(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
206  for (int k = 0; k < argc; ++k)
207    ++k;
208#pragma omp taskloop private(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
209  for (int k = 0; k < argc; ++k)
210    ++k;
211#pragma omp taskloop private(argc)
212  for (int k = 0; k < argc; ++k)
213    ++k;
214#pragma omp taskloop private(S1) // expected-error {{'S1' does not refer to a value}}
215  for (int k = 0; k < argc; ++k)
216    ++k;
217#pragma omp taskloop private(a, b) // expected-error {{private variable with incomplete type 'S1'}}
218  for (int k = 0; k < argc; ++k)
219    ++k;
220#pragma omp taskloop private(argv[1]) // expected-error {{expected variable name}}
221  for (int k = 0; k < argc; ++k)
222    ++k;
223#pragma omp taskloop private(e, g) // expected-error {{calling a private constructor of class 'S4'}} expected-error {{calling a private constructor of class 'S5'}}
224  for (int k = 0; k < argc; ++k)
225    ++k;
226#pragma omp taskloop private(h) // expected-error {{threadprivate or thread local variable cannot be private}}
227  for (int k = 0; k < argc; ++k)
228    ++k;
229#pragma omp taskloop private(B::x) // expected-error {{threadprivate or thread local variable cannot be private}}
230  for (int k = 0; k < argc; ++k)
231    ++k;
232#pragma omp taskloop shared(i)
233  for (int k = 0; k < argc; ++k)
234    ++k;
235#pragma omp parallel
236  {
237    int i;
238#pragma omp taskloop private(i)
239    for (int k = 0; k < argc; ++k)
240      ++k;
241  }
242#pragma omp parallel shared(i)
243#pragma omp parallel private(i)
244#pragma omp taskloop private(j)
245  for (int k = 0; k < argc; ++k)
246    ++k;
247#pragma omp taskloop private(i)
248  for (int k = 0; k < argc; ++k)
249    ++k;
250  static int si;
251#pragma omp taskloop private(si) // OK
252  for(int k = 0; k < argc; ++k)
253    si = k + 1;
254
255  s6 = s6_0; // expected-note {{in instantiation of member function 'S6<float>::operator=' requested here}}
256  s7 = s7_0; // expected-note {{in instantiation of member function 'S7<S6<float> >::operator=' requested here}}
257  return foomain(argc, argv); // expected-note {{in instantiation of function template specialization 'foomain<int, char>' requested here}}
258}
259
260