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