[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / OpenMP / dispatch_ast_print.cpp
blob6065f4f6e68ca9c0e682d012b22233bf413b2db2
1 // RUN: %clang_cc1 -triple=x86_64-pc-win32 -fopenmp \
2 // RUN: -fsyntax-only -verify %s
4 // RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fopenmp \
5 // RUN: -fsyntax-only -verify %s
7 // expected-no-diagnostics
9 // RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fopenmp \
10 // RUN: -ast-print %s | FileCheck %s --check-prefix=PRINT
12 // RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fopenmp \
13 // RUN: -ast-dump %s | FileCheck %s --check-prefix=DUMP
15 // RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fopenmp \
16 // RUN: -emit-pch -o %t %s
18 // RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fopenmp \
19 // RUN: -include-pch %t -ast-dump-all %s | FileCheck %s --check-prefix=DUMP
21 // RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fopenmp \
22 // RUN: -include-pch %t -ast-print %s | FileCheck %s --check-prefix=PRINT
24 #ifndef HEADER
25 #define HEADER
27 int foo_gpu(int A, int *B) { return 0;}
28 //PRINT: #pragma omp declare variant(foo_gpu)
29 //DUMP: FunctionDecl{{.*}} foo
30 //DUMP: OMPDeclareVariantAttr {{.*}}Implicit construct{{.*}}
31 #pragma omp declare variant(foo_gpu) \
32 match(construct={dispatch}, device={arch(arm)})
33 int foo(int, int*);
35 template <typename T, typename TP>
36 void fooTemp() {
37 T a;
38 TP b;
39 //PRINT: #pragma omp dispatch nowait
40 //DUMP: OMPDispatchDirective
41 //DUMP: OMPNowaitClause
42 #pragma omp dispatch nowait
43 foo(a, b);
46 int *get_device_ptr();
47 int get_device();
48 int other();
50 //DUMP: FunctionDecl{{.*}} test_one
51 void test_one()
53 int aaa, bbb, var;
54 //PRINT: #pragma omp dispatch depend(in : var) nowait novariants(aaa > 5) nocontext(bbb > 5)
55 //DUMP: OMPDispatchDirective
56 //DUMP: OMPDependClause
57 //DUMP: OMPNowaitClause
58 //DUMP: OMPNovariantsClause
59 //DUMP: DeclRefExpr {{.*}} 'bool' lvalue OMPCapturedExpr
60 //DUMP: OMPNocontextClause
61 //DUMP: DeclRefExpr {{.*}} 'bool' lvalue OMPCapturedExpr
62 #pragma omp dispatch depend(in:var) nowait novariants(aaa > 5) nocontext(bbb > 5)
63 foo(aaa, &bbb);
65 int *dp = get_device_ptr();
66 int dev = get_device();
67 //PRINT: #pragma omp dispatch device(dev) is_device_ptr(dp) novariants(dev > 10) nocontext(dev > 5)
68 //DUMP: OMPDispatchDirective
69 //DUMP: OMPDeviceClause
70 //DUMP: OMPIs_device_ptrClause
71 //DUMP: OMPNovariantsClause
72 //DUMP: DeclRefExpr {{.*}} 'bool' lvalue OMPCapturedExpr
73 //DUMP: OMPNocontextClause
74 //DUMP: DeclRefExpr {{.*}} 'bool' lvalue OMPCapturedExpr
75 #pragma omp dispatch device(dev) is_device_ptr(dp) novariants(dev > 10) nocontext(dev > 5)
76 foo(aaa, dp);
78 //PRINT: #pragma omp dispatch
79 //PRINT: foo(other(), &bbb);
80 //DUMP: OMPDispatchDirective
81 #pragma omp dispatch
82 foo(other(), &bbb);
84 fooTemp<int, int*>();
87 struct Obj {
88 Obj();
89 ~Obj();
90 int disp_method_variant1();
91 #pragma omp declare variant(disp_method_variant1) \
92 match(construct={dispatch}, device={arch(arm)})
93 int disp_method1();
95 static int disp_method_variant2() { return 1; }
96 #pragma omp declare variant(disp_method_variant2) \
97 match(construct={dispatch}, device={arch(arm)})
98 static int disp_method2() { return 2; }
101 Obj foo_vari();
102 #pragma omp declare variant(foo_vari) \
103 match(construct={dispatch}, device={arch(arm)})
104 Obj foo_obj();
106 //DUMP: FunctionDecl{{.*}} test_two
107 void test_two(Obj o1, Obj &o2, Obj *o3)
109 //PRINT: #pragma omp dispatch
110 //PRINT: o1.disp_method1();
111 //DUMP: OMPDispatchDirective
112 #pragma omp dispatch
113 o1.disp_method1();
115 //PRINT: #pragma omp dispatch
116 //PRINT: o2.disp_method1();
117 //DUMP: OMPDispatchDirective
118 #pragma omp dispatch
119 o2.disp_method1();
121 //PRINT: #pragma omp dispatch
122 //PRINT: o3->disp_method1();
123 //DUMP: OMPDispatchDirective
124 #pragma omp dispatch
125 o3->disp_method1();
127 //PRINT: #pragma omp dispatch
128 //PRINT: Obj::disp_method2();
129 //DUMP: OMPDispatchDirective
130 #pragma omp dispatch
131 Obj::disp_method2();
133 int ret;
134 //PRINT: #pragma omp dispatch
135 //PRINT: ret = o1.disp_method1();
136 //DUMP: OMPDispatchDirective
137 #pragma omp dispatch
138 ret = o1.disp_method1();
140 //PRINT: #pragma omp dispatch
141 //PRINT: ret = o2.disp_method1();
142 //DUMP: OMPDispatchDirective
143 #pragma omp dispatch
144 ret = o2.disp_method1();
146 //PRINT: #pragma omp dispatch
147 //PRINT: ret = o3->disp_method1();
148 //DUMP: OMPDispatchDirective
149 #pragma omp dispatch
150 ret = o3->disp_method1();
152 //PRINT: #pragma omp dispatch
153 //PRINT: ret = Obj::disp_method2();
154 //DUMP: OMPDispatchDirective
155 #pragma omp dispatch
156 ret = Obj::disp_method2();
158 //PRINT: #pragma omp dispatch
159 //PRINT: (void)Obj::disp_method2();
160 //DUMP: OMPDispatchDirective
161 #pragma omp dispatch
162 (void)Obj::disp_method2();
164 // Full C++ operator= case with temps and EH.
165 Obj o;
166 //PRINT: #pragma omp dispatch
167 //PRINT: o = foo_obj();
168 //DUMP: OMPDispatchDirective
169 #pragma omp dispatch
170 o = foo_obj();
173 struct A {
174 A& disp_operator(A other);
175 #pragma omp declare variant(disp_operator) \
176 match(construct={dispatch}, device={arch(arm)})
177 A& operator=(A other);
180 struct Obj2 {
181 A xx;
182 Obj2& disp_operator(Obj2 other);
183 #pragma omp declare variant(disp_operator) \
184 match(construct={dispatch}, device={arch(arm)})
185 Obj2& operator=(Obj2 other);
187 void foo() {
188 Obj2 z;
189 //PRINT: #pragma omp dispatch
190 //PRINT: z = z;
191 //DUMP: OMPDispatchDirective
192 #pragma omp dispatch
193 z = z;
194 //PRINT: #pragma omp dispatch
195 //PRINT: z.operator=(z);
196 //DUMP: OMPDispatchDirective
197 #pragma omp dispatch
198 z.operator=(z);
200 void bar() {
201 Obj2 j;
202 //PRINT: #pragma omp dispatch
203 //PRINT: j = {this->xx};
204 //DUMP: OMPDispatchDirective
205 #pragma omp dispatch
206 j = {this->xx};
207 //PRINT: #pragma omp dispatch
208 //PRINT: j.operator=({this->xx});
209 //DUMP: OMPDispatchDirective
210 #pragma omp dispatch
211 j.operator=({this->xx});
215 void test_three()
217 Obj2 z1, z;
218 #pragma omp dispatch
219 z1 = z;
220 #pragma omp dispatch
221 z1.operator=(z);
223 #endif // HEADER