Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / OpenMP / target_update_messages.cpp
blob2bf0ade9fe919c8b7b906e2bc6e1ba06926e85a1
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
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
9 // RUN: %clang_cc1 -verify=expected,ge50,ge51,cxx23 -fopenmp -fopenmp-simd -x c++ -std=c++23 %s -Wuninitialized
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}}
17 static int y;
18 #pragma omp declare target(y)
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.}}
24 int __attribute__((visibility("hidden"))) z;
25 #pragma omp declare target(z)
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.}}
31 void foo() {
34 bool foobool(int argc) {
35 return argc;
38 struct S1; // Aexpected-note {{declared here}}
40 template <class T, class S> // Aexpected-note {{declared here}}
41 int tmain(T argc, S **argv) {
42 int n;
43 return 0;
46 struct S {
47 int i;
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}}
59 #pragma omp declare mapper(id: S s) map(s.i)
60 S s;
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(,:)
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:)
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@+3 {{use of undeclared identifier 'present'}}
117 // lt51-error@+2 {{use of undeclared identifier 'id'}}
118 // lt51-error@+1 {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
119 #pragma omp target update to(present, mapper(id): s)
120 // lt51-warning@+1 {{missing ':' after ) - ignoring}}
121 #pragma omp target update to(mapper(id) present: s)
122 // lt51-error@+2 {{use of undeclared identifier 'present'}}
123 // lt51-error@+1 {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
124 #pragma omp target update to(present mapper(id): s)
126 // Check parsing with unnecessary commas.
127 // lt51-warning@+1 {{missing ':' after ) - ignoring}}
128 #pragma omp target update to(mapper(id),: s)
129 // lt51-error@+3 {{use of undeclared identifier 'present'}}
130 // lt51-error@+2 {{expected expression}}
131 // lt51-error@+1 {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
132 #pragma omp target update to(present , : s)
133 // ge51-warning@+2 {{missing ':' after motion modifier - ignoring}}
134 // lt51-warning@+1 {{missing ':' after ) - ignoring}}
135 #pragma omp target update to(mapper(id),,: s)
136 // ge51-warning@+5 {{missing ':' after motion modifier - ignoring}}
137 // lt51-error@+4 {{use of undeclared identifier 'present'}}
138 // lt51-error@+3 {{expected expression}}
139 // lt51-error@+2 {{expected expression}}
140 // lt51-error@+1 {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
141 #pragma omp target update to(present,,: s)
142 // lt51-warning@+1 {{missing ':' after ) - ignoring}}
143 #pragma omp target update to(mapper(id), present,: s)
144 // lt51-error@+4 {{use of undeclared identifier 'present'}}
145 // lt51-error@+3 {{use of undeclared identifier 'id'}}
146 // lt51-error@+2 {{expected expression}}
147 // lt51-error@+1 {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
148 #pragma omp target update to(present, mapper(id),: s)
150 #pragma omp target update from(m) allocate(m) // expected-error {{unexpected OpenMP clause 'allocate' in directive '#pragma omp target update'}}
152 foo();
155 double marr[10][5][10];
156 #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 #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 #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 #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 int arr[4][3][2][1];
165 #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 #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 double ***dptr;
170 #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 #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 int iarr[5][5];
175 // ge50-error@+4 {{section stride is evaluated to a non-positive value -1}}
176 // lt50-error@+3 {{expected ']'}}
177 // lt50-note@+2 {{to match this '['}}
178 // expected-error@+1 {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
179 #pragma omp target update to(iarr[0:][1:2:-1])
181 // ge50-error@+4 {{section stride is evaluated to a non-positive value -1}}
182 // lt50-error@+3 {{expected ']'}}
183 // lt50-note@+2 {{to match this '['}}
184 // expected-error@+1 {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
185 #pragma omp target update from(iarr[0:][1:2:-1])
187 // lt50-error@+5 {{expected expression}}
188 // ge50-error@+4 {{array section does not specify length for outermost dimension}}
189 // lt50-error@+3 {{expected ']'}}
190 // lt50-note@+2 {{to match this '['}}
191 // lt50-error@+1 {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
192 #pragma omp target update to(iarr[0: :2][1:2])
194 // lt50-error@+5 {{expected expression}}
195 // ge50-error@+4 {{array section does not specify length for outermost dimension}}
196 // lt50-error@+3 {{expected ']'}}
197 // lt50-note@+2 {{to match this '['}}
198 // lt50-error@+1 {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
199 #pragma omp target update from(iarr[0: :2][1:2])
202 return tmain(argc, argv);
205 template<typename _Tp, int _Nm> struct array {
206 _Tp & operator[](int __n) noexcept;
209 #pragma omp declare target
210 extern array<double, 4> arr;
211 #pragma omp end declare target
213 void copy_host_to_device()
215 #pragma omp target update from(arr) // expected-no-error
216 arr[0] = 0;
219 struct FOO; // expected-note {{forward declaration of 'FOO'}}
220 extern FOO a;
221 template <typename T, int I>
222 struct bar {
223 void func() {
224 #pragma omp target map(to: a) // expected-error {{incomplete type 'FOO' where a complete type is required}}
225 foo();
229 #if defined(__cplusplus) && __cplusplus >= 202101L
231 namespace cxx23 {
233 struct S {
234 int operator[](auto...);
237 void f() {
239 int test[10];
241 #pragma omp target update to(test[1])
243 #pragma omp target update to(test[1, 2]) // cxx23-error {{type 'int[10]' does not provide a subscript operator}} \
244 // cxx23-error {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
246 #pragma omp target update to(test [1:1:1])
248 #pragma omp target update to(test [1, 2:1:1]) // cxx23-error {{expected ']'}} // expected-note {{'['}} \
249 // cxx23-error {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
251 #pragma omp target update to(test [1, 2:]) // cxx23-error {{expected ']'}} // expected-note {{'['}} \
252 // cxx23-error {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
254 #pragma omp target update to(test[1, 2 ::]) // cxx23-error {{expected ']'}} // expected-note {{'['}} \
255 // cxx23-error {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
257 #pragma omp target update to(test[]) // cxx23-error {{type 'int[10]' does not provide a subscript operator}} \
258 // cxx23-error {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
259 S s;
260 (void)s[0];
261 (void)s[];
262 (void)s[1, 2];
267 #endif