1 // RUN: %clang_cc1 -verify=expected,lt50,lt51 -fopenmp -fopenmp-version=45 -ferror-limit 100 %s -Wno-openmp-mapping -Wuninitialized
2 // RUN: %clang_cc1 -verify=expected,ge50,lt51 -fopenmp -fopenmp-version=50 -ferror-limit 100 %s -Wno-openmp-mapping -Wuninitialized
3 // RUN: %clang_cc1 -verify=expected,ge50,ge51 -fopenmp -fopenmp-version=51 -ferror-limit 100 %s -Wno-openmp-mapping -Wuninitialized
4 
5 // RUN: %clang_cc1 -verify=expected,lt50,lt51 -fopenmp-simd -fopenmp-version=45 -ferror-limit 100 %s -Wno-openmp-mapping -Wuninitialized
6 
foo()7 void foo() {
8 }
9 
foobool(int argc)10 bool foobool(int argc) {
11   return argc;
12 }
13 
xxx(int argc)14 void xxx(int argc) {
15   int map; // expected-note {{initialize the variable 'map' to silence this warning}}
16 #pragma omp target teams distribute parallel for map(tofrom: map) // expected-warning {{variable 'map' is uninitialized when used here}}
17   for (int i = 0; i < 10; ++i)
18     ;
19 }
20 
21 struct S1; // expected-note 2 {{declared here}}
22 extern S1 a;
23 class S2 {
24   mutable int a;
25 public:
S2()26   S2():a(0) { }
S2(S2 & s2)27   S2(S2 &s2):a(s2.a) { }
28   static float S2s;
29   static const float S2sc;
30 };
31 const float S2::S2sc = 0;
32 const S2 b;
33 const S2 ba[5];
34 class S3 {
35   int a;
36 public:
S3()37   S3():a(0) { }
S3(S3 & s3)38   S3(S3 &s3):a(s3.a) { }
39 };
40 const S3 c;
41 const S3 ca[5];
42 extern const int f;
43 class S4 {
44   int a;
45   S4();
46   S4(const S4 &s4);
47 public:
S4(int v)48   S4(int v):a(v) { }
49 };
50 class S5 {
51   int a;
S5()52   S5():a(0) {}
S5(const S5 & s5)53   S5(const S5 &s5):a(s5.a) { }
54 public:
S5(int v)55   S5(int v):a(v) { }
56 };
57 
58 S3 h;
59 #pragma omp threadprivate(h) // expected-note 2 {{defined as threadprivate or thread local}}
60 
61 typedef int from;
62 
63 template <typename T, int I> // expected-note {{declared here}}
64 T tmain(T argc) {
65   const T d = 5;
66   const T da[5] = { 0 };
67   S4 e(4);
68   S5 g(5);
69   T i, t[20];
70   T &j = i;
71   T *k = &j;
72   T x;
73   T y, z;
74   T to, tofrom, always;
75   const T (&l)[5] = da;
76 
77 
78 #pragma omp target teams distribute parallel for map // expected-error {{expected '(' after 'map'}}
79   for (i = 0; i < argc; ++i) foo();
80 #pragma omp target teams distribute parallel for map( // expected-error {{expected ')'}} expected-note {{to match this '('}} expected-error {{expected expression}}
81   for (i = 0; i < argc; ++i) foo();
82 #pragma omp target teams distribute parallel for map() // expected-error {{expected expression}}
83   for (i = 0; i < argc; ++i) foo();
84 #pragma omp target teams distribute parallel for map(alloc) // expected-error {{use of undeclared identifier 'alloc'}}
85   for (i = 0; i < argc; ++i) foo();
86 #pragma omp target teams distribute parallel for map(to argc // expected-error {{expected ')'}} expected-note {{to match this '('}} expected-error {{expected ',' or ')' in 'map' clause}}
87   for (i = 0; i < argc; ++i) foo();
88 #pragma omp target teams distribute parallel for map(to:) // expected-error {{expected expression}}
89   for (i = 0; i < argc; ++i) foo();
90 #pragma omp target teams distribute parallel for map(from: argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
91   for (i = 0; i < argc; ++i) foo();
92 #pragma omp target teams distribute parallel for map(x: y) // expected-error {{incorrect map type, expected one of 'to', 'from', 'tofrom', 'alloc', 'release', or 'delete'}}
93   for (i = 0; i < argc; ++i) foo();
94 #pragma omp target teams distribute parallel for map(l[-1:]) // expected-error 2 {{array section must be a subset of the original array}}
95   for (i = 0; i < argc; ++i) foo();
96 #pragma omp target teams distribute parallel for map(l[:-1]) // expected-error 2 {{section length is evaluated to a negative value -1}}
97   for (i = 0; i < argc; ++i) foo();
98 #pragma omp target teams distribute parallel for map(l[true:true])
99   for (i = 0; i < argc; ++i) foo();
100 #pragma omp target teams distribute parallel for map(x)
101   for (i = 0; i < argc; ++i) foo();
102 #pragma omp target teams distribute parallel for map(tofrom: t[:I])
103   for (i = 0; i < argc; ++i) foo();
104 #pragma omp target teams distribute parallel for map(T: a) // expected-error {{incorrect map type, expected one of 'to', 'from', 'tofrom', 'alloc', 'release', or 'delete'}} expected-error {{incomplete type 'S1' where a complete type is required}}
105   for (i = 0; i < argc; ++i) foo();
106 #pragma omp target teams distribute parallel for map(T) // expected-error {{'T' does not refer to a value}}
107   for (i = 0; i < argc; ++i) foo();
108 // ge50-error@+2 2 {{expected addressable lvalue in 'map' clause}}
109 // lt50-error@+1 2 {{expected expression containing only member accesses and/or array sections based on named variables}}
110 #pragma omp target teams distribute parallel for map(I)
111   for (i = 0; i < argc; ++i) foo();
112 #pragma omp target teams distribute parallel for map(S2::S2s)
113   for (i = 0; i < argc; ++i) foo();
114 #pragma omp target teams distribute parallel for map(S2::S2sc)
115   for (i = 0; i < argc; ++i) foo();
116 #pragma omp target teams distribute parallel for map(x, z)
117   for (i = 0; i < argc; ++i) foo();
118 #pragma omp target teams distribute parallel for map(to: x)
119   for (i = 0; i < argc; ++i) foo();
120 #pragma omp target teams distribute parallel for map(to: to)
121   for (i = 0; i < argc; ++i) foo();
122 #pragma omp target teams distribute parallel for map(to)
123   for (i = 0; i < argc; ++i) foo();
124 #pragma omp target teams distribute parallel for map(to, x)
125   for (i = 0; i < argc; ++i) foo();
126 #pragma omp target teams distribute parallel for map(to x) // expected-error {{expected ',' or ')' in 'map' clause}}
127   for (i = 0; i < argc; ++i) foo();
128 // ge50-error@+3 2 {{expected addressable lvalue in 'map' clause}}
129 // lt50-error@+2 2 {{expected expression containing only member accesses and/or array sections based on named variables}}
130 #pragma omp target teams distribute parallel for map(tofrom \
131                                                      : argc > 0 ? x : y)
132   for (i = 0; i < argc; ++i) foo();
133 #pragma omp target teams distribute parallel for map(argc)
134   for (i = 0; i < argc; ++i) foo();
135 #pragma omp target teams distribute parallel for map(S1) // expected-error {{'S1' does not refer to a value}}
136   for (i = 0; i < argc; ++i) foo();
137 #pragma omp target teams distribute parallel for map(a, b, c, d, f) // expected-error {{incomplete type 'S1' where a complete type is required}}
138   for (i = 0; i < argc; ++i) foo();
139 #pragma omp target teams distribute parallel for map(ba)
140   for (i = 0; i < argc; ++i) foo();
141 #pragma omp target teams distribute parallel for map(ca)
142   for (i = 0; i < argc; ++i) foo();
143 #pragma omp target teams distribute parallel for map(da)
144   for (i = 0; i < argc; ++i) foo();
145 #pragma omp target teams distribute parallel for map(S2::S2s)
146   for (i = 0; i < argc; ++i) foo();
147 #pragma omp target teams distribute parallel for map(S2::S2sc)
148   for (i = 0; i < argc; ++i) foo();
149 #pragma omp target teams distribute parallel for map(e, g)
150   for (i = 0; i < argc; ++i) foo();
151 #pragma omp target teams distribute parallel for map(h) // expected-error {{threadprivate variables are not allowed in 'map' clause}}
152   for (i = 0; i < argc; ++i) foo();
153 #pragma omp target teams distribute parallel for map(k), map(k) // lt50-error 2 {{variable already marked as mapped in current construct}} lt50-note 2 {{used here}}
154   for (i = 0; i < argc; ++i) foo();
155 #pragma omp target teams distribute parallel for map(k), map(k[:5]) // lt50-error 2 {{pointer cannot be mapped along with a section derived from itself}} lt50-note 2 {{used here}}
156   for (i = 0; i < argc; ++i) foo();
157 #pragma omp target teams distribute parallel for map(da)
158   for (i = 0; i < argc; ++i) foo();
159 #pragma omp target teams distribute parallel for map(da[:4])
160   for (i = 0; i < argc; ++i) foo();
161 #pragma omp target data map(k, j, l)                        // lt50-note 2 {{used here}}
162 #pragma omp target teams distribute parallel for map(k[:4]) // lt50-error 2 {{pointer cannot be mapped along with a section derived from itself}}
163   for (i = 0; i < argc; ++i) foo();
164 #pragma omp target teams distribute parallel for map(j)
165   for (i = 0; i < argc; ++i) foo();
166 #pragma omp target teams distribute parallel for map(l) map(l[:5]) // lt50-error 2 {{variable already marked as mapped in current construct}} lt50-note 2 {{used here}}
167   for (i = 0; i < argc; ++i) foo();
168 #pragma omp target data map(k[:4], j, l[:5]) // lt50-note 2 {{used here}}
169   {
170 #pragma omp target teams distribute parallel for map(k) // lt50-error 2 {{pointer cannot be mapped along with a section derived from itself}}
171     for (i = 0; i < argc; ++i)
172       foo();
173 #pragma omp target teams distribute parallel for map(j)
174   for (i = 0; i < argc; ++i) foo();
175 #pragma omp target teams distribute parallel for map(l)
176   for (i = 0; i < argc; ++i) foo();
177 }
178 
179 #pragma omp target teams distribute parallel for map(always, tofrom: x)
180   for (i = 0; i < argc; ++i) foo();
181 #pragma omp target teams distribute parallel for map(always: x) // expected-error {{missing map type}}
182   for (i = 0; i < argc; ++i) foo();
183 // ge51-error@+3 {{incorrect map type modifier, expected 'always', 'close', 'mapper', or 'present'}}
184 // lt51-error@+2 {{incorrect map type modifier, expected 'always', 'close', or 'mapper'}}
185 // expected-error@+1 {{missing map type}}
186 #pragma omp target teams distribute parallel for map(tofrom, always: x)
187   for (i = 0; i < argc; ++i) foo();
188 #pragma omp target teams distribute parallel for map(always, tofrom: always, tofrom, x)
189   for (i = 0; i < argc; ++i) foo();
190 #pragma omp target teams distribute parallel for map(tofrom j) // expected-error {{expected ',' or ')' in 'map' clause}}
191   for (i = 0; i < argc; ++i) foo();
192 
193   return 0;
194 }
195 
main(int argc,char ** argv)196 int main(int argc, char **argv) {
197   const int d = 5;
198   const int da[5] = { 0 };
199   S4 e(4);
200   S5 g(5);
201   int i;
202   int &j = i;
203   int *k = &j;
204   int x;
205   int y, z;
206   int to, tofrom, always;
207   const int (&l)[5] = da;
208 
209 #pragma omp target teams distribute parallel for map // expected-error {{expected '(' after 'map'}}
210   for (i = 0; i < argc; ++i) foo();
211 #pragma omp target teams distribute parallel for map( // expected-error {{expected ')'}} expected-note {{to match this '('}} expected-error {{expected expression}}
212   for (i = 0; i < argc; ++i) foo();
213 #pragma omp target teams distribute parallel for map() // expected-error {{expected expression}}
214   for (i = 0; i < argc; ++i) foo();
215 #pragma omp target teams distribute parallel for map(alloc) // expected-error {{use of undeclared identifier 'alloc'}}
216   for (i = 0; i < argc; ++i) foo();
217 #pragma omp target teams distribute parallel for map(to argc // expected-error {{expected ')'}} expected-note {{to match this '('}} expected-error {{expected ',' or ')' in 'map' clause}}
218   for (i = 0; i < argc; ++i) foo();
219 #pragma omp target teams distribute parallel for map(to:) // expected-error {{expected expression}}
220   for (i = 0; i < argc; ++i) foo();
221 #pragma omp target teams distribute parallel for map(from: argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
222   for (i = 0; i < argc; ++i) foo();
223 #pragma omp target teams distribute parallel for map(x: y) // expected-error {{incorrect map type, expected one of 'to', 'from', 'tofrom', 'alloc', 'release', or 'delete'}}
224   for (i = 0; i < argc; ++i) foo();
225 #pragma omp target teams distribute parallel for map(l[-1:]) // expected-error {{array section must be a subset of the original array}}
226   for (i = 0; i < argc; ++i) foo();
227 #pragma omp target teams distribute parallel for map(l[:-1]) // expected-error {{section length is evaluated to a negative value -1}}
228   for (i = 0; i < argc; ++i) foo();
229 #pragma omp target teams distribute parallel for map(l[true:true])
230   for (i = 0; i < argc; ++i) foo();
231 #pragma omp target teams distribute parallel for map(x)
232   for (i = 0; i < argc; ++i) foo();
233 #pragma omp target teams distribute parallel for map(to: x)
234   for (i = 0; i < argc; ++i) foo();
235 #pragma omp target teams distribute parallel for map(to: to)
236   for (i = 0; i < argc; ++i) foo();
237 #pragma omp target teams distribute parallel for map(to)
238   for (i = 0; i < argc; ++i) foo();
239 #pragma omp target teams distribute parallel for map(to, x)
240   for (i = 0; i < argc; ++i) foo();
241 #pragma omp target teams distribute parallel for map(to x) // expected-error {{expected ',' or ')' in 'map' clause}}
242   for (i = 0; i < argc; ++i) foo();
243 // ge50-error@+3 {{expected addressable lvalue in 'map' clause}}
244 // lt50-error@+2 {{expected expression containing only member accesses and/or array sections based on named variables}}
245 #pragma omp target teams distribute parallel for map(tofrom \
246                                                      : argc > 0 ? argv[1] : argv[2])
247   for (i = 0; i < argc; ++i) foo();
248 #pragma omp target teams distribute parallel for map(argc)
249   for (i = 0; i < argc; ++i) foo();
250 #pragma omp target teams distribute parallel for map(S1) // expected-error {{'S1' does not refer to a value}}
251   for (i = 0; i < argc; ++i) foo();
252 #pragma omp target teams distribute parallel for map(a, b, c, d, f) // expected-error {{incomplete type 'S1' where a complete type is required}}
253   for (i = 0; i < argc; ++i) foo();
254 #pragma omp target teams distribute parallel for map(argv[1])
255   for (i = 0; i < argc; ++i) foo();
256 #pragma omp target teams distribute parallel for map(ba, z)
257   for (i = 0; i < argc; ++i) foo();
258 #pragma omp target teams distribute parallel for map(ca)
259   for (i = 0; i < argc; ++i) foo();
260 #pragma omp target teams distribute parallel for map(da)
261   for (i = 0; i < argc; ++i) foo();
262 #pragma omp target teams distribute parallel for map(S2::S2s)
263   for (i = 0; i < argc; ++i) foo();
264 #pragma omp target teams distribute parallel for map(S2::S2sc)
265   for (i = 0; i < argc; ++i) foo();
266 #pragma omp target teams distribute parallel for map(e, g)
267   for (i = 0; i < argc; ++i) foo();
268 #pragma omp target teams distribute parallel for map(h) // expected-error {{threadprivate variables are not allowed in 'map' clause}}
269   for (i = 0; i < argc; ++i)
270     foo();
271 #pragma omp target teams distribute parallel for map(k), map(k) // lt50-error {{variable already marked as mapped in current construct}} lt50-note {{used here}}
272   for (i = 0; i < argc; ++i)
273     foo();
274 #pragma omp target teams distribute parallel for map(k), map(k[:5]) // lt50-error {{pointer cannot be mapped along with a section derived from itself}} lt50-note {{used here}}
275   for (i = 0; i < argc; ++i) foo();
276 #pragma omp target teams distribute parallel for map(da)
277   for (i = 0; i < argc; ++i) foo();
278 #pragma omp target teams distribute parallel for map(da[:4])
279   for (i = 0; i < argc; ++i)
280     foo();
281 #pragma omp target data map(k, j, l)                        // lt50-note {{used here}}
282 #pragma omp target teams distribute parallel for map(k[:4]) // lt50-error {{pointer cannot be mapped along with a section derived from itself}}
283   for (i = 0; i < argc; ++i) foo();
284 #pragma omp target teams distribute parallel for map(j)
285   for (i = 0; i < argc; ++i)
286     foo();
287 #pragma omp target teams distribute parallel for map(l) map(l[:5]) // lt50-error {{variable already marked as mapped in current construct}} lt50-note {{used here}}
288   for (i = 0; i < argc; ++i)
289     foo();
290 #pragma omp target data map(k[:4], j, l[:5]) // lt50-note {{used here}}
291   {
292 #pragma omp target teams distribute parallel for map(k) // lt50-error {{pointer cannot be mapped along with a section derived from itself}}
293     for (i = 0; i < argc; ++i)
294       foo();
295 #pragma omp target teams distribute parallel for map(j)
296   for (i = 0; i < argc; ++i) foo();
297 #pragma omp target teams distribute parallel for map(l)
298   for (i = 0; i < argc; ++i) foo();
299   }
300 
301 #pragma omp target teams distribute parallel for map(always, tofrom: x)
302   for (i = 0; i < argc; ++i) foo();
303 #pragma omp target teams distribute parallel for map(always: x) // expected-error {{missing map type}}
304   for (i = 0; i < argc; ++i) foo();
305 // ge51-error@+3 {{incorrect map type modifier, expected 'always', 'close', 'mapper', or 'present'}}
306 // lt51-error@+2 {{incorrect map type modifier, expected 'always', 'close', or 'mapper'}}
307 // expected-error@+1 {{missing map type}}
308 #pragma omp target teams distribute parallel for map(tofrom, always: x)
309   for (i = 0; i < argc; ++i) foo();
310 #pragma omp target teams distribute parallel for map(always, tofrom: always, tofrom, x)
311   for (i = 0; i < argc; ++i) foo();
312 #pragma omp target teams distribute parallel for map(tofrom j) // expected-error {{expected ',' or ')' in 'map' clause}}
313   for (i = 0; i < argc; ++i) foo();
314 #pragma omp target teams distribute parallel for map(delete: j) // expected-error {{map type 'delete' is not allowed for '#pragma omp target teams distribute parallel for'}}
315   for (i = 0; i < argc; ++i)
316     foo();
317 #pragma omp target teams distribute parallel for map(release: j) // expected-error {{map type 'release' is not allowed for '#pragma omp target teams distribute parallel for'}}
318   for (i = 0; i < argc; ++i)
319     foo();
320 
321   return tmain<int, 3>(argc)+tmain<from, 4>(argc); // expected-note {{in instantiation of function template specialization 'tmain<int, 3>' requested here}} expected-note {{in instantiation of function template specialization 'tmain<int, 4>' requested here}}
322 }
323 
324