Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / OpenMP / interop_ast_print.cpp
blob7b9dda577c840364386382a6301e993144fd2309
1 // RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fopenmp \
2 // RUN: -fsyntax-only -verify %s
4 // expected-no-diagnostics
6 // RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fopenmp \
7 // RUN: -ast-print %s | FileCheck %s --check-prefix=PRINT
9 // RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fopenmp \
10 // RUN: -ast-dump %s | FileCheck %s --check-prefix=DUMP
12 // RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fopenmp \
13 // RUN: -emit-pch -o %t %s
15 // RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fopenmp \
16 // RUN: -include-pch %t -ast-dump-all %s | FileCheck %s --check-prefix=DUMP
18 // RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fopenmp \
19 // RUN: -include-pch %t -ast-print %s | FileCheck %s --check-prefix=PRINT
21 #ifndef HEADER
22 #define HEADER
24 typedef void *omp_interop_t;
26 struct S {
27 omp_interop_t o1;
28 omp_interop_t o2;
29 omp_interop_t o3;
30 static omp_interop_t so;
31 void foo();
32 S();
33 ~S();
35 omp_interop_t S::so;
37 struct T {
38 static void static_member_func();
39 static omp_interop_t to;
41 omp_interop_t T::to;
43 void T::static_member_func() {
44 omp_interop_t o1;
45 //PRINT: #pragma omp interop init(target : o1)
46 #pragma omp interop init(target:o1)
48 //PRINT: #pragma omp interop init(target : to)
49 #pragma omp interop init(target: to)
51 //PRINT: #pragma omp interop init(target : T::to)
52 #pragma omp interop init(target: T::to)
54 //PRINT: #pragma omp interop init(target : S::so)
55 #pragma omp interop init(target: S::so)
59 S::S() {
60 //PRINT: #pragma omp interop init(target : this->o1)
61 #pragma omp interop init(target:o1)
62 //PRINT: #pragma omp interop use(this->o1) init(target : this->o2)
63 #pragma omp interop use(o1) init(target:o2)
64 //PRINT: #pragma omp interop use(this->o2) init(target : this->o3)
65 #pragma omp interop use(o2) init(target:o3)
67 S::~S() {
68 //PRINT: #pragma omp interop destroy(this->o1) destroy(this->o2) destroy(this->o3)
69 #pragma omp interop destroy(o1) destroy(o2) destroy(o3)
72 void S::foo() {
73 //PRINT: #pragma omp interop init(target : so)
74 #pragma omp interop init(target:so)
77 //PRINT-LABEL: void foo1(
78 //DUMP-LABEL: FunctionDecl {{.*}} foo1
79 void foo1(int *ap, int dev) {
80 omp_interop_t I;
81 omp_interop_t &IRef = I;
83 //PRINT: #pragma omp interop init(target : I)
84 //DUMP: OMPInteropDirective
85 //DUMP: OMPInitClause
86 //DUMP: DeclRefExpr{{.*}}'omp_interop_t'{{.*}}Var{{.*}}'I'
87 #pragma omp interop init(target:I)
89 //PRINT: #pragma omp interop use(I)
90 //DUMP: OMPInteropDirective
91 //DUMP: OMPUseClause
92 //DUMP: DeclRefExpr{{.*}}'omp_interop_t'{{.*}}Var{{.*}}'I'
93 #pragma omp interop use(I)
95 //PRINT: #pragma omp interop destroy(I)
96 //DUMP: OMPInteropDirective
97 //DUMP: OMPDestroyClause
98 //DUMP: DeclRefExpr{{.*}}'omp_interop_t'{{.*}}Var{{.*}}'I'
99 #pragma omp interop destroy(I)
101 //PRINT: #pragma omp interop init(target : IRef)
102 //DUMP: OMPInteropDirective
103 //DUMP: OMPInitClause
104 //DUMP: DeclRefExpr{{.*}}'omp_interop_t'{{.*}}Var{{.*}}'IRef'
105 #pragma omp interop init(target:IRef)
107 //PRINT: #pragma omp interop use(IRef)
108 //DUMP: OMPInteropDirective
109 //DUMP: OMPUseClause
110 //DUMP: DeclRefExpr{{.*}}'omp_interop_t'{{.*}}Var{{.*}}'IRef'
111 #pragma omp interop use(IRef)
113 //PRINT: #pragma omp interop destroy(IRef)
114 //DUMP: OMPInteropDirective
115 //DUMP: OMPDestroyClause
116 //DUMP: DeclRefExpr{{.*}}'omp_interop_t'{{.*}}Var{{.*}}'IRef'
117 #pragma omp interop destroy(IRef)
119 const omp_interop_t CI = (omp_interop_t)0;
120 //PRINT: #pragma omp interop use(CI)
121 //DUMP: OMPInteropDirective
122 //DUMP: OMPUseClause
123 //DUMP: DeclRefExpr{{.*}}'const omp_interop_t'{{.*}}Var{{.*}}'CI'
124 #pragma omp interop use(CI)
126 //PRINT: #pragma omp interop device(dev) depend(inout : ap) init(targetsync : I)
127 //DUMP: OMPInteropDirective
128 //DUMP: OMPDeviceClause
129 //DUMP: DeclRefExpr{{.*}}'dev' 'int'
130 //DUMP: OMPDependClause
131 //DUMP: DeclRefExpr{{.*}}'ap' 'int *'
132 //DUMP: OMPInitClause
133 //DUMP: DeclRefExpr{{.*}}'omp_interop_t'{{.*}}Var{{.*}}'I'
134 #pragma omp interop device(dev) depend(inout:ap) init(targetsync:I)
136 //PRINT: #pragma omp interop device(dev) depend(inout : ap) use(I)
137 //DUMP: OMPInteropDirective
138 //DUMP: OMPDeviceClause
139 //DUMP: DeclRefExpr{{.*}}'dev' 'int'
140 //DUMP: OMPDependClause
141 //DUMP: DeclRefExpr{{.*}}'ap' 'int *'
142 //DUMP: OMPUseClause
143 //DUMP: DeclRefExpr{{.*}}'omp_interop_t'{{.*}}Var{{.*}}'I'
144 #pragma omp interop device(dev) depend(inout:ap) use(I)
146 //PRINT: #pragma omp interop device(dev) depend(inout : ap) destroy(I)
147 //DUMP: OMPInteropDirective
148 //DUMP: OMPDeviceClause
149 //DUMP: DeclRefExpr{{.*}}'dev' 'int'
150 //DUMP: OMPDependClause
151 //DUMP: DeclRefExpr{{.*}}'ap' 'int *'
152 //DUMP: OMPDestroyClause
153 //DUMP: DeclRefExpr{{.*}}'omp_interop_t'{{.*}}Var{{.*}}'I'
154 #pragma omp interop device(dev) depend(inout:ap) destroy(I)
156 //PRINT: #pragma omp interop init(prefer_type(1,2,3,4,5,6), targetsync : I)
157 //DUMP: OMPInteropDirective
158 //DUMP: OMPInitClause
159 //DUMP: DeclRefExpr{{.*}}'omp_interop_t'{{.*}}Var{{.*}}'I'
160 //DUMP: IntegerLiteral{{.*}}1
161 //DUMP: IntegerLiteral{{.*}}2
162 //DUMP: IntegerLiteral{{.*}}3
163 //DUMP: IntegerLiteral{{.*}}4
164 //DUMP: IntegerLiteral{{.*}}5
165 //DUMP: IntegerLiteral{{.*}}6
166 #pragma omp interop init(prefer_type(1,2,3,4,5,6),targetsync:I)
168 //PRINT: #pragma omp interop init(prefer_type(2,4,6,1), targetsync : I)
169 //DUMP: OMPInteropDirective
170 //DUMP: OMPInitClause
171 //DUMP: DeclRefExpr{{.*}}'omp_interop_t'{{.*}}Var{{.*}}'I'
172 //DUMP: IntegerLiteral{{.*}}2
173 //DUMP: IntegerLiteral{{.*}}4
174 //DUMP: IntegerLiteral{{.*}}6
175 //DUMP: IntegerLiteral{{.*}}1
176 #pragma omp interop init(prefer_type(2,4,6,1),targetsync:I)
178 //PRINT: #pragma omp interop init(prefer_type("cuda","cuda_driver","opencl","sycl","hip","level_zero"), targetsync : I)
179 //DUMP: OMPInteropDirective
180 //DUMP: OMPInitClause
181 //DUMP: DeclRefExpr{{.*}}'omp_interop_t'{{.*}}Var{{.*}}'I'
182 //DUMP: StringLiteral{{.*}}"cuda"
183 //DUMP: StringLiteral{{.*}}"cuda_driver"
184 //DUMP: StringLiteral{{.*}}"opencl"
185 //DUMP: StringLiteral{{.*}}"sycl"
186 //DUMP: StringLiteral{{.*}}"hip"
187 //DUMP: StringLiteral{{.*}}"level_zero"
188 #pragma omp interop init( \
189 prefer_type("cuda","cuda_driver","opencl","sycl","hip","level_zero"), \
190 targetsync:I)
192 //PRINT: #pragma omp interop init(prefer_type("level_zero",2,4), targetsync : I)
193 //DUMP: OMPInteropDirective
194 //DUMP: OMPInitClause
195 //DUMP: DeclRefExpr{{.*}}'omp_interop_t'{{.*}}Var{{.*}}'I'
196 //DUMP: StringLiteral{{.*}}"level_zero"
197 //DUMP: IntegerLiteral{{.*}}2
198 //DUMP: IntegerLiteral{{.*}}4
199 #pragma omp interop init(prefer_type("level_zero",2,4),targetsync:I)
201 omp_interop_t J;
203 //PRINT: #pragma omp interop init(target : I) init(targetsync : J)
204 //DUMP: OMPInteropDirective
205 //DUMP: OMPInitClause
206 //DUMP: DeclRefExpr{{.*}}'omp_interop_t'{{.*}}Var{{.*}}'I'
207 //DUMP: OMPInitClause
208 //DUMP: DeclRefExpr{{.*}}'omp_interop_t'{{.*}}Var{{.*}}'J'
209 #pragma omp interop init(target:I) init(targetsync:J)
211 //PRINT: #pragma omp interop init(target : I) use(J)
212 //DUMP: OMPInteropDirective
213 //DUMP: OMPInitClause
214 //DUMP: DeclRefExpr{{.*}}'omp_interop_t'{{.*}}Var{{.*}}'I'
215 //DUMP: OMPUseClause
216 //DUMP: DeclRefExpr{{.*}}'omp_interop_t'{{.*}}Var{{.*}}'J'
217 #pragma omp interop init(target:I) use(J)
219 //PRINT: #pragma omp interop use(I) use(J)
220 //DUMP: OMPInteropDirective
221 //DUMP: OMPUseClause
222 //DUMP: DeclRefExpr{{.*}}'omp_interop_t'{{.*}}Var{{.*}}'I'
223 //DUMP: OMPUseClause
224 //DUMP: DeclRefExpr{{.*}}'omp_interop_t'{{.*}}Var{{.*}}'J'
225 #pragma omp interop use(I) use(J)
227 //PRINT: #pragma omp interop destroy(I) destroy(J)
228 //DUMP: OMPInteropDirective
229 //DUMP: OMPDestroyClause
230 //DUMP: DeclRefExpr{{.*}}'omp_interop_t'{{.*}}Var{{.*}}'I'
231 //DUMP: OMPDestroyClause
232 //DUMP: DeclRefExpr{{.*}}'omp_interop_t'{{.*}}Var{{.*}}'J'
233 #pragma omp interop destroy(I) destroy(J)
235 //PRINT: #pragma omp interop init(target : I) destroy(J)
236 //DUMP: OMPInteropDirective
237 //DUMP: OMPInitClause
238 //DUMP: DeclRefExpr{{.*}}'omp_interop_t'{{.*}}Var{{.*}}'I'
239 //DUMP: OMPDestroyClause
240 //DUMP: DeclRefExpr{{.*}}'omp_interop_t'{{.*}}Var{{.*}}'J'
241 #pragma omp interop init(target:I) destroy(J)
243 //PRINT: #pragma omp interop destroy(I) use(J)
244 //DUMP: OMPInteropDirective
245 //DUMP: OMPDestroyClause
246 //DUMP: DeclRefExpr{{.*}}'omp_interop_t'{{.*}}Var{{.*}}'I'
247 //DUMP: OMPUseClause
248 //DUMP: DeclRefExpr{{.*}}'omp_interop_t'{{.*}}Var{{.*}}'J'
249 #pragma omp interop destroy(I) use(J)
251 //PRINT: #pragma omp interop init(target : S::so)
252 #pragma omp interop init(target: S::so)
255 //DUMP: FunctionTemplateDecl{{.*}}fooTemp
256 //DUMP-NEXT: NonTypeTemplateParmDecl{{.*}}'int{{.*}}I
257 template <int I>
258 void fooTemp() {
259 omp_interop_t interop_var;
260 //PRINT: #pragma omp interop init(prefer_type(I,4,"level_one"), target : interop_var)
261 //DUMP: FunctionDecl{{.*}}fooTemp
262 //DUMP: OMPInteropDirective
263 //DUMP: OMPInitClause
264 //DUMP: DeclRefExpr{{.*}}'omp_interop_t'{{.*}}'interop_var'
265 //DUMP: DeclRefExpr{{.*}}NonTypeTemplateParm{{.*}}'I' 'int'
266 //DUMP: IntegerLiteral{{.*}}'int' 4
267 //DUMP: StringLiteral{{.*}}"level_one"
269 //PRINT: #pragma omp interop init(prefer_type(3,4,"level_one"), target : interop_var)
270 //DUMP: FunctionDecl{{.*}}fooTemp
271 //DUMP: TemplateArgument integral 3
272 //DUMP: OMPInteropDirective
273 //DUMP: OMPInitClause
274 //DUMP: DeclRefExpr{{.*}}'omp_interop_t'{{.*}}'interop_var'
275 //DUMP: SubstNonTypeTemplateParmExpr{{.*}}'int'
276 //DUMP: NonTypeTemplateParmDecl{{.*}}'int'{{.*}}I
277 //DUMP: IntegerLiteral{{.*}}'int' 3
278 //DUMP: IntegerLiteral{{.*}}'int' 4
279 //DUMP: StringLiteral{{.*}}"level_one"
280 #pragma omp interop init(prefer_type(I,4,"level_one"), target: interop_var)
283 //DUMP: FunctionTemplateDecl{{.*}}barTemp
284 //DUMP-NEXT: TemplateTypeParmDecl{{.*}}typename{{.*}}T
285 template <typename T>
286 void barTemp(T t) {
287 //PRINT: #pragma omp interop init(prefer_type(4,"level_one"), target : t)
288 //DUMP: FunctionDecl{{.*}}barTemp 'void (T)'
289 //DUMP: ParmVarDecl{{.*}}t 'T'
290 //DUMP: OMPInteropDirective
291 //DUMP: OMPInitClause
292 //DUMP: DeclRefExpr{{.*}}ParmVar{{.*}}'t' 'T'
293 //DUMP: IntegerLiteral{{.*}}'int' 4
294 //DUMP: StringLiteral{{.*}}"level_one"
295 #pragma omp interop init(prefer_type(4,"level_one"), target: t)
297 //PRINT: #pragma omp interop use(t)
298 //DUMP: OMPInteropDirective
299 //DUMP: OMPUseClause
300 //DUMP: DeclRefExpr{{.*}}ParmVar{{.*}}'t' 'T'
301 #pragma omp interop use(t)
303 //PRINT: #pragma omp interop destroy(t)
304 //DUMP: OMPInteropDirective
305 //DUMP: OMPDestroyClause
306 //DUMP: DeclRefExpr{{.*}}ParmVar{{.*}}'t' 'T'
307 #pragma omp interop destroy(t)
309 //DUMP: FunctionDecl{{.*}}barTemp 'void (void *)'
310 //DUMP: TemplateArgument type 'void *'
311 //DUMP: ParmVarDecl{{.*}}t 'void *'
312 //DUMP: OMPInteropDirective
313 //DUMP: OMPInitClause
314 //DUMP: DeclRefExpr{{.*}}ParmVar{{.*}}'t' 'void *'
315 //PRINT: #pragma omp interop init(prefer_type(4,"level_one"), target : t)
316 //DUMP: OMPInteropDirective
317 //DUMP: OMPUseClause
318 //DUMP: DeclRefExpr{{.*}}ParmVar{{.*}}'t' 'void *'
319 //PRINT: #pragma omp interop use(t)
320 //DUMP: OMPInteropDirective
321 //DUMP: OMPDestroyClause
322 //DUMP: DeclRefExpr{{.*}}ParmVar{{.*}}'t' 'void *'
323 //PRINT: #pragma omp interop destroy(t)
326 void bar()
328 fooTemp<3>();
329 omp_interop_t Ivar;
330 barTemp(Ivar);
331 S s;
334 #endif // HEADER