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 parallel for map(tofrom: 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}}
tmain(T argc)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 parallel for map // expected-error {{expected '(' after 'map'}}
81   for (i = 0; i < argc; ++i) foo();
82 #pragma omp target parallel for 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 parallel for map() // expected-error {{expected expression}}
85   for (i = 0; i < argc; ++i) foo();
86 #pragma omp target parallel for map(alloc) // expected-error {{use of undeclared identifier 'alloc'}}
87   for (i = 0; i < argc; ++i) foo();
88 #pragma omp target parallel for 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 parallel for map(to:) // expected-error {{expected expression}}
91   for (i = 0; i < argc; ++i) foo();
92 #pragma omp target parallel for 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 parallel for 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 parallel for 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 parallel for 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 parallel for map(l[true:true])
101   for (i = 0; i < argc; ++i) foo();
102 #pragma omp target parallel for map(x)
103   for (i = 0; i < argc; ++i) foo();
104 #pragma omp target parallel for map(tofrom: t[:I])
105   for (i = 0; i < argc; ++i) foo();
106 #pragma omp target 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}}
107   for (i = 0; i < argc; ++i) foo();
108 #pragma omp target parallel for 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 parallel for map(I)
113   for (i = 0; i < argc; ++i) foo();
114 #pragma omp target parallel for map(S2::S2s)
115   for (i = 0; i < argc; ++i) foo();
116 #pragma omp target parallel for map(S2::S2sc)
117   for (i = 0; i < argc; ++i) foo();
118 #pragma omp target parallel for map(x)
119   for (i = 0; i < argc; ++i) foo();
120 #pragma omp target parallel for map(to: x)
121   for (i = 0; i < argc; ++i) foo();
122 #pragma omp target parallel for map(to: to)
123   for (i = 0; i < argc; ++i) foo();
124 #pragma omp target parallel for map(to)
125   for (i = 0; i < argc; ++i) foo();
126 #pragma omp target parallel for map(to, x)
127   for (i = 0; i < argc; ++i) foo();
128 #pragma omp target parallel for 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 parallel for map(tofrom \
133                                     : argc > 0 ? x : y)
134   for (i = 0; i < argc; ++i) foo();
135 #pragma omp target parallel for map(argc)
136   for (i = 0; i < argc; ++i) foo();
137 #pragma omp target parallel for map(S1) // expected-error {{'S1' does not refer to a value}}
138   for (i = 0; i < argc; ++i) foo();
139 #pragma omp target parallel for 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 parallel for map(ba)
142   for (i = 0; i < argc; ++i) foo();
143 #pragma omp target parallel for map(ca)
144   for (i = 0; i < argc; ++i) foo();
145 #pragma omp target parallel for map(da)
146   for (i = 0; i < argc; ++i) foo();
147 #pragma omp target parallel for map(S2::S2s)
148   for (i = 0; i < argc; ++i) foo();
149 #pragma omp target parallel for map(S2::S2sc)
150   for (i = 0; i < argc; ++i) foo();
151 #pragma omp target parallel for map(e, g)
152   for (i = 0; i < argc; ++i) foo();
153 #pragma omp target parallel for map(h) // expected-error {{threadprivate variables are not allowed in 'map' clause}}
154   for (i = 0; i < argc; ++i) foo();
155 #pragma omp target parallel for map(k), map(k) // expected-error 2 {{variable already marked as mapped in current construct}} expected-note 2 {{used here}}
156   for (i = 0; i < argc; ++i) foo();
157 #pragma omp target parallel for map(k), map(k[:5]) // expected-error 2 {{pointer cannot be mapped along with a section derived from itself}} expected-note 2 {{used here}}
158   for (i = 0; i < argc; ++i) foo();
159 #pragma omp target parallel for map(da)
160   for (i = 0; i < argc; ++i) foo();
161 #pragma omp target parallel for map(da[:4])
162   for (i = 0; i < argc; ++i) foo();
163 #pragma omp target data map(k, j, l) // expected-note 2 {{used here}}
164 #pragma omp target parallel for map(k[:4]) // expected-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 parallel for map(j)
167   for (i = 0; i < argc; ++i) foo();
168 #pragma omp target parallel for map(l) map(l[:5]) // expected-error 2 {{variable already marked as mapped in current construct}} expected-note 2 {{used here}}
169   for (i = 0; i < argc; ++i) foo();
170 #pragma omp target data map(k[:4], j, l[:5]) // expected-note 2 {{used here}}
171 {
172 #pragma omp target parallel for map(k) // expected-error 2 {{pointer cannot be mapped along with a section derived from itself}}
173   for (i = 0; i < argc; ++i) foo();
174 #pragma omp target parallel for map(j)
175   for (i = 0; i < argc; ++i) foo();
176 #pragma omp target parallel for map(l)
177   for (i = 0; i < argc; ++i) foo();
178 }
179 
180 #pragma omp target parallel for map(always, tofrom: x)
181   for (i = 0; i < argc; ++i) foo();
182 #pragma omp target parallel for map(always: x) // expected-error {{missing map type}}
183   for (i = 0; i < argc; ++i) foo();
184 // ge51-error@+3 {{incorrect map type modifier, expected 'always', 'close', 'mapper', or 'present'}}
185 // lt51-error@+2 {{incorrect map type modifier, expected 'always', 'close', or 'mapper'}}
186 // expected-error@+1 {{missing map type}}
187 #pragma omp target parallel for map(tofrom, always: x)
188   for (i = 0; i < argc; ++i) foo();
189 #pragma omp target parallel for map(always, tofrom: always, tofrom, x)
190   for (i = 0; i < argc; ++i) foo();
191 #pragma omp target parallel for map(tofrom j) // expected-error {{expected ',' or ')' in 'map' clause}}
192   for (i = 0; i < argc; ++i) foo();
193 
194   return 0;
195 }
196 
main(int argc,char ** argv)197 int main(int argc, char **argv) {
198   const int d = 5;
199   const int da[5] = { 0 };
200   S4 e(4);
201   S5 g(5);
202   int i;
203   int &j = i;
204   int *k = &j;
205   int x;
206   int y;
207   int to, tofrom, always;
208   const int (&l)[5] = da;
209 
210 #pragma omp target parallel for map // expected-error {{expected '(' after 'map'}}
211   for (i = 0; i < argc; ++i) foo();
212 #pragma omp target parallel for map( // expected-error {{expected ')'}} expected-note {{to match this '('}} expected-error {{expected expression}}
213   for (i = 0; i < argc; ++i) foo();
214 #pragma omp target parallel for map() // expected-error {{expected expression}}
215   for (i = 0; i < argc; ++i) foo();
216 #pragma omp target parallel for map(alloc) // expected-error {{use of undeclared identifier 'alloc'}}
217   for (i = 0; i < argc; ++i) foo();
218 #pragma omp target parallel for map(to argc // expected-error {{expected ')'}} expected-note {{to match this '('}} expected-error {{expected ',' or ')' in 'map' clause}}
219   for (i = 0; i < argc; ++i) foo();
220 #pragma omp target parallel for map(to:) // expected-error {{expected expression}}
221   for (i = 0; i < argc; ++i) foo();
222 #pragma omp target parallel for map(from: argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
223   for (i = 0; i < argc; ++i) foo();
224 #pragma omp target parallel for map(x: y) // expected-error {{incorrect map type, expected one of 'to', 'from', 'tofrom', 'alloc', 'release', or 'delete'}}
225   for (i = 0; i < argc; ++i) foo();
226 #pragma omp target parallel for map(l[-1:]) // expected-error {{array section must be a subset of the original array}}
227   for (i = 0; i < argc; ++i) foo();
228 #pragma omp target parallel for map(l[:-1]) // expected-error {{section length is evaluated to a negative value -1}}
229   for (i = 0; i < argc; ++i) foo();
230 #pragma omp target parallel for map(l[true:true])
231   for (i = 0; i < argc; ++i) foo();
232 #pragma omp target parallel for map(x)
233   for (i = 0; i < argc; ++i) foo();
234 #pragma omp target parallel for map(to: x)
235   for (i = 0; i < argc; ++i) foo();
236 #pragma omp target parallel for map(to: to)
237   for (i = 0; i < argc; ++i) foo();
238 #pragma omp target parallel for map(to)
239   for (i = 0; i < argc; ++i) foo();
240 #pragma omp target parallel for map(to, x)
241   for (i = 0; i < argc; ++i) foo();
242 #pragma omp target parallel for map(to x) // expected-error {{expected ',' or ')' in 'map' clause}}
243   for (i = 0; i < argc; ++i)
244     foo();
245 // ge50-error@+3 {{expected addressable lvalue in 'map' clause}}
246 // lt50-error@+2 {{expected expression containing only member accesses and/or array sections based on named variables}}
247 #pragma omp target parallel for map(tofrom \
248                                     : argc > 0 ? argv[1] : argv[2])
249   for (i = 0; i < argc; ++i) foo();
250 #pragma omp target parallel for map(argc)
251   for (i = 0; i < argc; ++i) foo();
252 #pragma omp target parallel for map(S1) // expected-error {{'S1' does not refer to a value}}
253   for (i = 0; i < argc; ++i) foo();
254 #pragma omp target parallel for map(a, b, c, d, f) // expected-error {{incomplete type 'S1' where a complete type is required}}
255   for (i = 0; i < argc; ++i) foo();
256 #pragma omp target parallel for map(argv[1])
257   for (i = 0; i < argc; ++i) foo();
258 #pragma omp target parallel for map(ba)
259   for (i = 0; i < argc; ++i) foo();
260 #pragma omp target parallel for map(ca)
261   for (i = 0; i < argc; ++i) foo();
262 #pragma omp target parallel for map(da)
263   for (i = 0; i < argc; ++i) foo();
264 #pragma omp target parallel for map(S2::S2s)
265   for (i = 0; i < argc; ++i) foo();
266 #pragma omp target parallel for map(S2::S2sc)
267   for (i = 0; i < argc; ++i) foo();
268 #pragma omp target parallel for map(e, g)
269   for (i = 0; i < argc; ++i) foo();
270 #pragma omp target parallel for map(h) // expected-error {{threadprivate variables are not allowed in 'map' clause}}
271   for (i = 0; i < argc; ++i) foo();
272 #pragma omp target parallel for map(k), map(k) // expected-error {{variable already marked as mapped in current construct}} expected-note {{used here}}
273   for (i = 0; i < argc; ++i) foo();
274 #pragma omp target parallel for map(k), map(k[:5]) // expected-error {{pointer cannot be mapped along with a section derived from itself}} expected-note {{used here}}
275   for (i = 0; i < argc; ++i) foo();
276 #pragma omp target parallel for map(da)
277   for (i = 0; i < argc; ++i) foo();
278 #pragma omp target parallel for map(da[:4])
279   for (i = 0; i < argc; ++i) foo();
280 #pragma omp target data map(k, j, l) // expected-note {{used here}}
281 #pragma omp target parallel for map(k[:4]) // expected-error {{pointer cannot be mapped along with a section derived from itself}}
282   for (i = 0; i < argc; ++i) foo();
283 #pragma omp target parallel for map(j)
284   for (i = 0; i < argc; ++i) foo();
285 #pragma omp target parallel for map(l) map(l[:5]) // expected-error 1 {{variable already marked as mapped in current construct}} expected-note 1 {{used here}}
286   for (i = 0; i < argc; ++i) foo();
287 #pragma omp target data map(k[:4], j, l[:5]) // expected-note {{used here}}
288 {
289 #pragma omp target parallel for map(k) // expected-error {{pointer cannot be mapped along with a section derived from itself}}
290   for (i = 0; i < argc; ++i) foo();
291 #pragma omp target parallel for map(j)
292   for (i = 0; i < argc; ++i) foo();
293 #pragma omp target parallel for map(l)
294   for (i = 0; i < argc; ++i) foo();
295 }
296 
297 #pragma omp target parallel for map(always, tofrom: x)
298   for (i = 0; i < argc; ++i) foo();
299 #pragma omp target parallel for map(always: x) // expected-error {{missing map type}}
300   for (i = 0; i < argc; ++i) foo();
301 // ge51-error@+3 {{incorrect map type modifier, expected 'always', 'close', 'mapper', or 'present'}}
302 // lt51-error@+2 {{incorrect map type modifier, expected 'always', 'close', or 'mapper'}}
303 // expected-error@+1 {{missing map type}}
304 #pragma omp target parallel for map(tofrom, always: x)
305   for (i = 0; i < argc; ++i) foo();
306 #pragma omp target parallel for map(always, tofrom: always, tofrom, x)
307   for (i = 0; i < argc; ++i) foo();
308 #pragma omp target parallel for map(tofrom j) // expected-error {{expected ',' or ')' in 'map' clause}}
309   for (i = 0; i < argc; ++i) foo();
310 #pragma omp target parallel for map(delete: j) // expected-error {{map type 'delete' is not allowed for '#pragma omp target parallel for'}}
311   for (i = 0; i < argc; ++i)
312     foo();
313 #pragma omp target parallel for map(release: j) // expected-error {{map type 'release' is not allowed for '#pragma omp target parallel for'}}
314   for (i = 0; i < argc; ++i)
315     foo();
316 
317   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}}
318 }
319 
320