Debian Codegraph @

clang/test/OpenMP/target_update_messages.cpp

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