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