Debian Codegraph @

clang/test/OpenMP/declare_target_ast_print.cpp

raw
1 // RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -I %S/Inputs -emit-pch -o %t %s
2 // RUN: %clang_cc1 -fopenmp -std=c++11 -include-pch %t -I %S/Inputs -verify %s -ast-print | FileCheck %s
3
4 // RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=50 -I %S/Inputs -ast-print %s | FileCheck %s --check-prefix=CHECK --check-prefix=OMP50
5 // RUN: %clang_cc1 -verify -fopenmp -I %S/Inputs -ast-print %s | FileCheck %s --check-prefix=CHECK --check-prefix=OMP51
6 // RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=52 -I %S/Inputs -ast-print %s | FileCheck %s --check-prefix=CHECK --check-prefix=OMP52
7 // RUN: %clang_cc1 -fopenmp -fopenmp-version=50 -x c++ -std=c++11 -I %S/Inputs -emit-pch -o %t %s
8 // RUN: %clang_cc1 -fopenmp -fopenmp-version=50 -std=c++11 -include-pch %t -I %S/Inputs -verify %s -ast-print | FileCheck %s --check-prefix=CHECK --check-prefix=OMP50
9 // RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -I %S/Inputs -emit-pch -o %t %s
10 // RUN: %clang_cc1 -fopenmp -std=c++11 -include-pch %t -I %S/Inputs -verify %s -ast-print | FileCheck %s --check-prefix=CHECK --check-prefix=OMP51
11 // RUN: %clang_cc1 -fopenmp -fopenmp-version=52 -x c++ -std=c++11 -I %S/Inputs -emit-pch -o %t %s
12 // RUN: %clang_cc1 -fopenmp -fopenmp-version=52 -std=c++11 -include-pch %t -I %S/Inputs -verify %s -ast-print | FileCheck %s --check-prefix=CHECK --check-prefix=OMP52
13
14 // RUN: %clang_cc1 -verify -fopenmp-simd -I %S/Inputs -ast-print %s | FileCheck %s
15 // RUN: %clang_cc1 -fopenmp-simd -x c++ -std=c++11 -I %S/Inputs -emit-pch -o %t %s
16 // RUN: %clang_cc1 -fopenmp-simd -std=c++11 -include-pch %t -I %S/Inputs -verify %s -ast-print | FileCheck %s
17 // expected-no-diagnostics
18
19 #ifndef HEADER
20 #define HEADER
21
22 #if _OPENMP == 201811
23 void bar();
24 #pragma omp declare target to(bar) device_type(any)
25 // OMP50: #pragma omp declare target{{$}}
26 // OMP50: void bar();
27 // OMP50: #pragma omp end declare target{{$}}
28 void baz();
29 #pragma omp declare target to(baz) device_type(nohost)
30 // OMP50: #pragma omp declare target device_type(nohost){{$}}
31 // OMP50: void baz();
32 // OMP50: #pragma omp end declare target{{$}}
33 void bazz();
34 #pragma omp declare target to(bazz) device_type(host)
35 // OMP50: #pragma omp declare target device_type(host){{$}}
36 // OMP50: void bazz();
37 // OMP50: #pragma omp end declare target{{$}}
38 #endif // _OPENMP
39
40 #if _OPENMP == 202011
41 extern "C" {
42 void boo_c() {}
43 #pragma omp declare target to(boo_c) indirect
44 // OMP51: #pragma omp declare target indirect
45 // OMP51: void boo_c() {
46 // OMP51: }
47 // OMP51: #pragma omp end declare target
48 #pragma omp declare target indirect
49 void yoo(){}
50 #pragma omp end declare target
51 // OMP51: #pragma omp declare target indirect
52 // OMP51: void yoo() {
53 // OMP51: }
54 // OMP51: #pragma omp end declare target
55 }
56 extern "C++" {
57 void boo_cpp() {}
58 #pragma omp declare target to(boo_cpp) indirect
59 // OMP51: #pragma omp declare target indirect
60 // OMP51: void boo_cpp() {
61 // OMP51: }
62 // OMP51: #pragma omp end declare target
63
64 constexpr bool f() {return false;}
65 #pragma omp begin declare target indirect(f())
66 void zoo() {}
67 void xoo();
68 #pragma omp end declare target
69 #pragma omp declare target to(zoo) indirect(false)
70 // OMP51: #pragma omp declare target indirect(f())
71 // OMP51: #pragma omp declare target indirect(false)
72 // OMP51: void zoo() {
73 // OMP51: }
74 // OMP51: #pragma omp end declare target
75 // OMP51: #pragma omp declare target indirect(f())
76 // OMP51: void xoo();
77 // OMP51: #pragma omp end declare target
78
79 }
80 #endif // _OPENMP
81
82 #if _OPENMP == 202111
83 extern "C" {
84 void boo_c() {}
85 #pragma omp declare target enter(boo_c) indirect
86 // OMP52: #pragma omp declare target indirect
87 // OMP52: void boo_c() {
88 // OMP52: }
89 // OMP52: #pragma omp end declare target
90 #pragma omp declare target indirect
91 void yoo(){}
92 #pragma omp end declare target
93 // OMP52: #pragma omp declare target indirect
94 // OMP52: void yoo() {
95 // OMP52: }
96 // OMP52: #pragma omp end declare target
97 }
98 extern "C++" {
99 void boo_cpp() {}
100 #pragma omp declare target enter(boo_cpp) indirect
101 // OMP52: #pragma omp declare target indirect
102 // OMP52: void boo_cpp() {
103 // OMP52: }
104 // OMP52: #pragma omp end declare target
105
106 constexpr bool f() {return false;}
107 #pragma omp begin declare target indirect(f())
108 void zoo() {}
109 void xoo();
110 #pragma omp end declare target
111 #pragma omp declare target enter(zoo) indirect(false)
112 // OMP52: #pragma omp declare target indirect(f())
113 // OMP52: #pragma omp declare target indirect(false)
114 // OMP52: void zoo() {
115 // OMP52: }
116 // OMP52: #pragma omp end declare target
117 // OMP52: #pragma omp declare target indirect(f())
118 // OMP52: void xoo();
119 // OMP52: #pragma omp end declare target
120
121 }
122 #endif // _OPENMP
123
124 int out_decl_target = 0;
125 #pragma omp declare target (out_decl_target)
126
127 // CHECK: #pragma omp declare target{{$}}
128 // CHECK: int out_decl_target = 0;
129 // CHECK: #pragma omp end declare target{{$}}
130 // CHECK: #pragma omp declare target{{$}}
131 // CHECK: void lambda()
132 // CHECK: #pragma omp end declare target{{$}}
133
134 #pragma omp declare target
135 void lambda () {
136 #ifdef __cpp_lambdas
137 (void)[&] { ++out_decl_target; };
138 #else
139 #pragma clang __debug captured
140 (void)out_decl_target;
141 #endif
142 };
143 #pragma omp end declare target
144
145 #pragma omp declare target
146 // CHECK: #pragma omp declare target{{$}}
147 void foo() {}
148 // CHECK-NEXT: void foo()
149 #pragma omp end declare target
150 // CHECK: #pragma omp end declare target{{$}}
151
152 extern "C" {
153 #pragma omp declare target
154 // CHECK: #pragma omp declare target
155 void foo_c() {}
156 // CHECK-NEXT: void foo_c()
157 #pragma omp end declare target
158 // CHECK: #pragma omp end declare target
159 }
160
161 extern "C++" {
162 #pragma omp declare target
163 // CHECK: #pragma omp declare target
164 void foo_cpp() {}
165 // CHECK-NEXT: void foo_cpp()
166 #pragma omp end declare target
167 // CHECK: #pragma omp end declare target
168 }
169
170 #pragma omp declare target
171 template <class T>
172 struct C {
173 // CHECK: template <class T> struct C {
174 // CHECK: #pragma omp declare target
175 // CHECK-NEXT: static T ts;
176 // CHECK-NEXT: #pragma omp end declare target
177
178 // CHECK: template<> struct C<int>
179 T t;
180 // CHECK-NEXT: int t;
181 static T ts;
182 // CHECK-NEXT: #pragma omp declare target
183 // CHECK-NEXT: static int ts;
184 // CHECK: #pragma omp end declare target
185
186 C(T t) : t(t) {
187 }
188 // CHECK: #pragma omp declare target
189 // CHECK-NEXT: C(int t) : t(t) {
190 // CHECK-NEXT: }
191 // CHECK: #pragma omp end declare target
192
193 T foo() {
194 return t;
195 }
196 // CHECK: #pragma omp declare target
197 // CHECK-NEXT: int foo() {
198 // CHECK-NEXT: return this->t;
199 // CHECK-NEXT: }
200 // CHECK: #pragma omp end declare target
201 };
202
203 template<class T>
204 T C<T>::ts = 1;
205 // CHECK: #pragma omp declare target
206 // CHECK: T ts = 1;
207 // CHECK: #pragma omp end declare target
208
209 // CHECK: #pragma omp declare target
210 // CHECK: int test1()
211 int test1() {
212 C<int> c(1);
213 return c.foo() + c.ts;
214 }
215 #pragma omp end declare target
216 // CHECK: #pragma omp end declare target
217
218 int a1;
219 void f1() {
220 }
221 #pragma omp declare target (a1, f1)
222 // CHECK: #pragma omp declare target{{$}}
223 // CHECK: int a1;
224 // CHECK: #pragma omp end declare target{{$}}
225 // CHECK: #pragma omp declare target{{$}}
226 // CHECK: void f1()
227 // CHECK: #pragma omp end declare target{{$}}
228
229 int b1, b2, b3;
230 void f2() {
231 }
232 #if _OPENMP == 202111
233 #pragma omp declare target enter(b1) enter(b2), enter(b3, f2)
234 #else
235 #pragma omp declare target to(b1) to(b2), to(b3, f2)
236 #endif // _OPENMP == 202111
237 // CHECK: #pragma omp declare target{{$}}
238 // CHECK: int b1;
239 // CHECK: #pragma omp end declare target{{$}}
240 // CHECK: #pragma omp declare target{{$}}
241 // CHECK: int b2;
242 // CHECK: #pragma omp end declare target{{$}}
243 // CHECK: #pragma omp declare target{{$}}
244 // CHECK: int b3;
245 // CHECK: #pragma omp end declare target{{$}}
246 // CHECK: #pragma omp declare target{{$}}
247 // CHECK: void f2()
248 // CHECK: #pragma omp end declare target{{$}}
249
250 int c1, c2, c3;
251 #pragma omp declare target link(c1) link(c2), link(c3)
252 // CHECK: #pragma omp declare target link{{$}}
253 // CHECK: int c1;
254 // CHECK: #pragma omp end declare target{{$}}
255 // CHECK: #pragma omp declare target link{{$}}
256 // CHECK: int c2;
257 // CHECK: #pragma omp end declare target{{$}}
258 // CHECK: #pragma omp declare target link{{$}}
259 // CHECK: int c3;
260 // CHECK: #pragma omp end declare target{{$}}
261
262 struct SSSt {
263 #pragma omp declare target
264 static int a;
265 int b;
266 #pragma omp end declare target
267 };
268
269 // CHECK: struct SSSt {
270 // CHECK: #pragma omp declare target
271 // CHECK: static int a;
272 // CHECK: #pragma omp end declare target
273 // CHECK: int b;
274
275 template <class T>
276 struct SSSTt {
277 #pragma omp declare target
278 static T a;
279 int b;
280 #pragma omp end declare target
281 };
282
283 // CHECK: template <class T> struct SSSTt {
284 // CHECK: #pragma omp declare target
285 // CHECK: static T a;
286 // CHECK: #pragma omp end declare target
287 // CHECK: int b;
288
289 #pragma omp declare target
290 template <typename T>
291 T baz() { return T(); }
292 #pragma omp end declare target
293
294 template <>
295 int baz() { return 1; }
296
297 // CHECK: #pragma omp declare target
298 // CHECK: template <typename T> T baz() {
299 // CHECK: return T();
300 // CHECK: }
301 // CHECK: #pragma omp end declare target
302 // CHECK: #pragma omp declare target
303 // CHECK: template<> float baz<float>() {
304 // CHECK: return float();
305 // CHECK: }
306 // CHECK: template<> int baz<int>() {
307 // CHECK: return 1;
308 // CHECK: }
309 // CHECK: #pragma omp end declare target
310
311 #pragma omp declare target
312 #include "declare_target_include.h"
313 void xyz();
314 #pragma omp end declare target
315
316 // CHECK: #pragma omp declare target
317 // CHECK: void zyx();
318 // CHECK: #pragma omp end declare target
319 // CHECK: #pragma omp declare target
320 // CHECK: void xyz();
321 // CHECK: #pragma omp end declare target
322
323 #pragma omp declare target
324 #pragma omp declare target
325 void abc();
326 #pragma omp end declare target
327 void cba();
328 #pragma omp end declare target
329
330 // CHECK: #pragma omp declare target
331 // CHECK: void abc();
332 // CHECK: #pragma omp end declare target
333 // CHECK: #pragma omp declare target
334 // CHECK: void cba();
335 // CHECK: #pragma omp end declare target
336
337 #pragma omp declare target
338 int abc1() { return 1; }
339 #if _OPENMP == 202111
340 #pragma omp declare target enter(abc1) device_type(nohost)
341 #else
342 #pragma omp declare target to(abc1) device_type(nohost)
343 #endif // _OPENMP == 202111
344 #pragma omp end declare target
345
346 // CHECK-NEXT: #pragma omp declare target
347 // CHECK-NEXT: #pragma omp declare target device_type(nohost)
348 // CHECK-NEXT: int abc1() {
349 // CHECK-NEXT: return 1;
350 // CHECK-NEXT: }
351 // CHECK-NEXT: #pragma omp end declare target
352
353 #pragma omp declare target
354 int inner_link;
355 #pragma omp declare target link(inner_link)
356 #pragma omp end declare target
357
358 // CHECK-NEXT: #pragma omp declare target
359 // CHECK-NEXT: #pragma omp declare target link
360 // CHECK-NEXT: int inner_link;
361 // CHECK-NEXT: #pragma omp end declare target
362
363 void foo2() { return ;}
364 // CHECK: #pragma omp declare target
365 // CHECK-NEXT: void foo2() {
366 // CHECK-NEXT: return;
367 // CHECK-NEXT: }
368
369 int x;
370 // CHECK: #pragma omp declare target link
371 // CHECK-NEXT: int x;
372 // CHECK-NEXT: #pragma omp end declare target
373
374 int main (int argc, char **argv) {
375 foo();
376 foo_c();
377 foo_cpp();
378 test1();
379 baz<float>();
380 baz<int>();
381
382 #if _OPENMP == 202111
383 #pragma omp declare target enter(foo2)
384 #else
385 #pragma omp declare target to (foo2)
386 #endif
387
388 #pragma omp declare target link(x)
389 return (0);
390 }
391
392 // CHECK: #pragma omp declare target
393 // CHECK-NEXT: int ts = 1;
394 // CHECK-NEXT: #pragma omp end declare target
395
396 // Do not expect anything here since the region is empty.
397 #pragma omp declare target
398 #pragma omp end declare target
399
400 #endif