1 // Visibility hidden is not currently implemented on AIX.
2 // XFAIL: aix
3 
4 // RUN: %clang_cc1 -verify=expected,lt50,lt51 -fopenmp -fopenmp-version=45 -ferror-limit 100 -o - -std=c++11 %s -Wuninitialized
5 // RUN: %clang_cc1 -verify=expected,ge50,lt51 -fopenmp -fopenmp-version=50 -ferror-limit 100 -o - -std=c++11 %s -Wuninitialized
6 // RUN: %clang_cc1 -verify=expected,ge50,ge51 -fopenmp -fopenmp-version=51 -ferror-limit 100 -o - -std=c++11 %s -Wuninitialized
7 
8 // RUN: %clang_cc1 -verify=expected,lt50,lt51 -fopenmp-simd -fopenmp-version=45 -ferror-limit 100 -o - -std=c++11 %s -Wuninitialized
9 // RUN: %clang_cc1 -verify=expected,ge50,lt51 -fopenmp-simd -fopenmp-version=50 -ferror-limit 100 -o - -std=c++11 %s -Wuninitialized
10 // RUN: %clang_cc1 -verify=expected,ge50,ge51 -fopenmp-simd -fopenmp-version=51 -ferror-limit 100 -o - -std=c++11 %s -Wuninitialized
11 
12 // RUN: %clang_cc1 -verify=expected,ge50,ge51,cxx2b -fopenmp -fopenmp-simd -fopenmp-version=51 -x c++ -std=c++2b %s -Wuninitialized
13 
14 void xxx(int argc) {
15   int x; // expected-note {{initialize the variable 'x' to silence this warning}}
16 #pragma omp target update to(x)
17   argc = x; // expected-warning {{variable 'x' is uninitialized when used here}}
18 }
19 
20 static int y;
21 #pragma omp declare target(y)
22 
23 void yyy() {
24 #pragma omp target update to(y) // expected-error {{the host cannot update a declare target variable that is not externally visible.}}
25 }
26 
27 int __attribute__((visibility("hidden"))) z;
28 #pragma omp declare target(z)
29 
30 void zzz() {
31 #pragma omp target update from(z) // expected-error {{the host cannot update a declare target variable that is not externally visible.}}
32 }
33 
34 void foo() {
35 }
36 
37 bool foobool(int argc) {
38   return argc;
39 }
40 
41 struct S1; // Aexpected-note {{declared here}}
42 
43 template <class T, class S> // Aexpected-note {{declared here}}
44 int tmain(T argc, S **argv) {
45   int n;
46   return 0;
47 }
48 
49 struct S {
50   int i;
51 };
52 
53 int main(int argc, char **argv) {
54   int m;
55   #pragma omp target update // expected-error {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
56   #pragma omp target update to(m) { // expected-warning {{extra tokens at the end of '#pragma omp target update' are ignored}}
57   #pragma omp target update to(m) ( // expected-warning {{extra tokens at the end of '#pragma omp target update' are ignored}}
58   #pragma omp target update to(m) [ // expected-warning {{extra tokens at the end of '#pragma omp target update' are ignored}}
59   #pragma omp target update to(m) ] // expected-warning {{extra tokens at the end of '#pragma omp target update' are ignored}}
60   #pragma omp target update to(m) ) // expected-warning {{extra tokens at the end of '#pragma omp target update' are ignored}}
61 
62   #pragma omp declare mapper(id: S s) map(s.i)
63   S s;
64 
65   // Check parsing with no modifiers.
66   // lt51-error@+2 {{expected expression}}
67   // lt51-error@+1 {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
68   #pragma omp target update to(: s)
69   // expected-error@+2 {{expected expression}}
70   // expected-error@+1 {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
71   #pragma omp target update to(:)
72   // expected-error@+2 2 {{expected expression}}
73   // expected-error@+1 {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
74   #pragma omp target update to(,:)
75 
76   // Check parsing with one modifier.
77   // expected-error@+2 {{use of undeclared identifier 'foobar'}}
78   // expected-error@+1 {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
79   #pragma omp target update to(foobar: s)
80   // expected-error@+3 {{expected ',' or ')' in 'to' clause}}
81   // expected-error@+2 {{expected ')'}}
82   // expected-note@+1 {{to match this '('}}
83   #pragma omp target update to(m: s)
84   #pragma omp target update to(mapper(id): s)
85   // lt51-error@+2 {{use of undeclared identifier 'present'}}
86   // lt51-error@+1 {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
87   #pragma omp target update to(present: s)
88   // ge51-warning@+4 {{missing ':' after motion modifier - ignoring}}
89   // lt51-warning@+3 {{missing ':' after ) - ignoring}}
90   // expected-error@+2 {{expected expression}}
91   // expected-error@+1 {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
92   #pragma omp target update to(mapper(id) s)
93   // ge51-warning@+4 {{missing ':' after motion modifier - ignoring}}
94   // ge51-error@+3 {{expected expression}}
95   // lt51-error@+2 {{use of undeclared identifier 'present'}}
96   // expected-error@+1 {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
97   #pragma omp target update to(present s)
98   // ge51-warning@+4 {{missing ':' after motion modifier - ignoring}}
99   // lt51-warning@+3 {{missing ':' after ) - ignoring}}
100   // expected-error@+2 {{expected expression}}
101   // expected-error@+1 {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
102   #pragma omp target update to(mapper(id))
103   // ge51-warning@+4 {{missing ':' after motion modifier - ignoring}}
104   // ge51-error@+3 {{expected expression}}
105   // lt51-error@+2 {{use of undeclared identifier 'present'}}
106   // expected-error@+1 {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
107   #pragma omp target update to(present)
108   // expected-error@+2 {{expected expression}}
109   // expected-error@+1 {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
110   #pragma omp target update to(mapper(id):)
111   // ge51-error@+3 {{expected expression}}
112   // lt51-error@+2 {{use of undeclared identifier 'present'}}
113   // expected-error@+1 {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
114   #pragma omp target update to(present:)
115 
116   // Check parsing with two modifiers.
117   // lt51-warning@+1 {{missing ':' after ) - ignoring}}
118   #pragma omp target update to(mapper(id), present: s)
119   // lt51-error@+3 {{use of undeclared identifier 'present'}}
120   // lt51-error@+2 {{use of undeclared identifier 'id'}}
121   // lt51-error@+1 {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
122   #pragma omp target update to(present, mapper(id): s)
123   // lt51-warning@+1 {{missing ':' after ) - ignoring}}
124   #pragma omp target update to(mapper(id) present: s)
125   // lt51-error@+2 {{use of undeclared identifier 'present'}}
126   // lt51-error@+1 {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
127   #pragma omp target update to(present mapper(id): s)
128 
129   // Check parsing with unnecessary commas.
130   // lt51-warning@+1 {{missing ':' after ) - ignoring}}
131   #pragma omp target update to(mapper(id),: s)
132   // lt51-error@+3 {{use of undeclared identifier 'present'}}
133   // lt51-error@+2 {{expected expression}}
134   // lt51-error@+1 {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
135   #pragma omp target update to(present , : s)
136   // ge51-warning@+2 {{missing ':' after motion modifier - ignoring}}
137   // lt51-warning@+1 {{missing ':' after ) - ignoring}}
138   #pragma omp target update to(mapper(id),,: s)
139   // ge51-warning@+5 {{missing ':' after motion modifier - ignoring}}
140   // lt51-error@+4 {{use of undeclared identifier 'present'}}
141   // lt51-error@+3 {{expected expression}}
142   // lt51-error@+2 {{expected expression}}
143   // lt51-error@+1 {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
144   #pragma omp target update to(present,,: s)
145   // lt51-warning@+1 {{missing ':' after ) - ignoring}}
146   #pragma omp target update to(mapper(id), present,: s)
147   // lt51-error@+4 {{use of undeclared identifier 'present'}}
148   // lt51-error@+3 {{use of undeclared identifier 'id'}}
149   // lt51-error@+2 {{expected expression}}
150   // lt51-error@+1 {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
151   #pragma omp target update to(present, mapper(id),: s)
152 
153   #pragma omp target update from(m) allocate(m) // expected-error {{unexpected OpenMP clause 'allocate' in directive '#pragma omp target update'}}
154   {
155     foo();
156   }
157 
158   double marr[10][5][10];
159 #pragma omp target update to(marr[0:2][2:4][1:2]) // lt50-error {{array section does not specify contiguous storage}} lt50-error {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
160   {}
161 #pragma omp target update from(marr[0:2][2:4][1:2]) // lt50-error {{array section does not specify contiguous storage}} lt50-error {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
162 
163 #pragma omp target update to(marr[0:][1:2:2][1:2]) // ge50-error {{array section does not specify length for outermost dimension}} lt50-error {{expected ']'}} lt50-note {{to match this '['}} lt50-error {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
164   {}
165 #pragma omp target update from(marr[0:][1:2:2][1:2]) // ge50-error {{array section does not specify length for outermost dimension}} lt50-error {{expected ']'}} lt50-note {{to match this '['}} lt50-error {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
166 
167   int arr[4][3][2][1];
168 #pragma omp target update to(arr[0:2][2:4][:2][1]) // lt50-error {{array section does not specify contiguous storage}} lt50-error {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
169   {}
170 #pragma omp target update from(arr[0:2][2:4][:2][1]) // lt50-error {{array section does not specify contiguous storage}} lt50-error {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
171 
172   double ***dptr;
173 #pragma omp target update to(dptr[0:2][2:4][1:2]) // lt50-error {{array section does not specify contiguous storage}} ge50-error 2 {{section length is unspecified and cannot be inferred because subscripted value is an array of unknown bound}} lt50-error {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
174   {}
175 #pragma omp target update from(dptr[0:2][2:4][1:2]) // lt50-error {{array section does not specify contiguous storage}} ge50-error 2 {{section length is unspecified and cannot be inferred because subscripted value is an array of unknown bound}} lt50-error {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
176 
177   int iarr[5][5];
178 // ge50-error@+4 {{section stride is evaluated to a non-positive value -1}}
179 // lt50-error@+3 {{expected ']'}}
180 // lt50-note@+2 {{to match this '['}}
181 // expected-error@+1 {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
182 #pragma omp target update to(iarr[0:][1:2:-1])
183   {}
184 // ge50-error@+4 {{section stride is evaluated to a non-positive value -1}}
185 // lt50-error@+3 {{expected ']'}}
186 // lt50-note@+2 {{to match this '['}}
187 // expected-error@+1 {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
188 #pragma omp target update from(iarr[0:][1:2:-1])
189   {}
190 // lt50-error@+5 {{expected expression}}
191 // ge50-error@+4 {{array section does not specify length for outermost dimension}}
192 // lt50-error@+3 {{expected ']'}}
193 // lt50-note@+2 {{to match this '['}}
194 // lt50-error@+1 {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
195 #pragma omp target update to(iarr[0: :2][1:2])
196   {}
197 // lt50-error@+5 {{expected expression}}
198 // ge50-error@+4 {{array section does not specify length for outermost dimension}}
199 // lt50-error@+3 {{expected ']'}}
200 // lt50-note@+2 {{to match this '['}}
201 // lt50-error@+1 {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
202 #pragma omp target update from(iarr[0: :2][1:2])
203   {}
204 
205   return tmain(argc, argv);
206 }
207 
208 template<typename _Tp, int _Nm> struct array {
209   _Tp & operator[](int __n) noexcept;
210 };
211 
212 #pragma omp declare target
213 extern array<double, 4> arr;
214 #pragma omp end declare target
215 
216 void copy_host_to_device()
217 {
218   #pragma omp target update from(arr)  // expected-no-error
219   arr[0] = 0;
220 }
221 
222 struct FOO; // expected-note {{forward declaration of 'FOO'}}
223 extern FOO a;
224 template <typename T, int I>
225 struct bar {
226   void func() {
227     #pragma omp target map(to: a) // expected-error {{incomplete type 'FOO' where a complete type is required}}
228     foo();
229   }
230 };
231 
232 #if defined(__cplusplus) && __cplusplus >= 202101L
233 
234 namespace cxx2b {
235 
236 struct S {
237   int operator[](auto...);
238 };
239 
240 void f() {
241 
242   int test[10];
243 
244 #pragma omp target update to(test[1])
245 
246 #pragma omp target update to(test[1, 2]) // cxx2b-error {{type 'int[10]' does not provide a subscript operator}} \
247                                          // cxx2b-error {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
248 
249 #pragma omp target update to(test [1:1:1])
250 
251 #pragma omp target update to(test [1, 2:1:1]) // cxx2b-error {{expected ']'}} // expected-note {{'['}} \
252                                             // cxx2b-error {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
253 
254 #pragma omp target update to(test [1, 2:]) // cxx2b-error {{expected ']'}} // expected-note {{'['}} \
255                                             // cxx2b-error {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
256 
257 #pragma omp target update to(test[1, 2 ::]) // cxx2b-error {{expected ']'}} // expected-note {{'['}} \
258                                             // cxx2b-error {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
259 
260 #pragma omp target update to(test[]) // cxx2b-error {{type 'int[10]' does not provide a subscript operator}} \
261                                             // cxx2b-error {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
262   S s;
263   (void)s[0];
264   (void)s[];
265   (void)s[1, 2];
266 }
267 
268 }
269 
270 #endif
271