[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / OpenMP / declare_variant_ast_print.cpp
blobdae753f4efce4dcbd3761ca74f494a3a8fc137cf
1 // RUN: %clang_cc1 -verify -fopenmp -x c++ -std=c++14 -fexceptions -fcxx-exceptions %s -ast-print -o - -Wno-source-uses-openmp -Wno-openmp-clauses | FileCheck %s
3 // RUN: %clang_cc1 -verify -fopenmp-simd -x c++ -std=c++14 -fexceptions -fcxx-exceptions %s -ast-print -o - -Wno-source-uses-openmp -Wno-openmp-clauses | FileCheck %s
5 // expected-no-diagnostics
7 // CHECK: int foo();
8 int foo();
10 // CHECK: template <typename T> T foofoo() {
11 // CHECK-NEXT: return T();
12 // CHECK-NEXT: }
13 template <typename T>
14 T foofoo() { return T(); }
16 // CHECK: template<> int foofoo<int>() {
17 // CHECK-NEXT: return int();
18 // CHECK-NEXT: }
20 // CHECK: #pragma omp declare variant(foofoo<int>) match(construct={target})
21 // CHECK-NEXT: #pragma omp declare variant(foofoo<int>) match(construct={simd})
22 // CHECK-NEXT: #pragma omp declare variant(foofoo<int>) match(implementation={vendor(score(5): ibm)}, device={kind(fpga)})
23 // CHECK-NEXT: #pragma omp declare variant(foofoo<int>) match(implementation={vendor(unknown)})
24 // CHECK-NEXT: #pragma omp declare variant(foofoo<int>) match(implementation={vendor(score(0): llvm)}, device={kind(cpu)})
25 // CHECK-NEXT: int bar();
26 #pragma omp declare variant(foofoo <int>) match(xxx = {})
27 #pragma omp declare variant(foofoo <int>) match(xxx = {vvv})
28 #pragma omp declare variant(foofoo <int>) match(implementation = {vendor(score(0): "llvm"), xxx}, device = {kind(cpu)})
29 #pragma omp declare variant(foofoo <int>) match(implementation = {vendor("unknown")})
30 #pragma omp declare variant(foofoo <int>) match(implementation = {vendor(score(5): ibm)}, device = {kind(fpga)})
31 #pragma omp declare variant(foofoo <int>) match(construct = {simd})
32 #pragma omp declare variant(foofoo <int>) match(construct = {target})
33 int bar();
35 // CHECK: #pragma omp declare variant(foofoo<T>) match(implementation={vendor(score(C + 5): ibm)}, device={kind(cpu, host)})
36 // CHECK-NEXT: #pragma omp declare variant(foofoo<T>) match(implementation={vendor(unknown)})
37 // CHECK-NEXT: #pragma omp declare variant(foofoo<T>) match(implementation={vendor(llvm)}, device={kind(cpu)})
38 // CHECK-NEXT: #pragma omp declare variant(foofoo<T>) match(user={condition(false)})
39 // CHECK-NEXT: #pragma omp declare variant(foofoo<T>) match(user={condition(true)})
40 // CHECK-NEXT: template <typename T, int C> T barbar();
41 #pragma omp declare variant(foofoo <T>) match(xxx = {})
42 #pragma omp declare variant(foofoo <T>) match(xxx = {vvv})
43 #pragma omp declare variant(foofoo <T>) match(user = {score(1 * 1 + 1) : condition(100 > 10 + 2)})
44 #pragma omp declare variant(foofoo <T>) match(user = {score(0) : condition(0)})
45 #pragma omp declare variant(foofoo <T>) match(user = {condition(true)})
46 #pragma omp declare variant(foofoo <T>) match(user = {condition(false)})
47 #pragma omp declare variant(foofoo <T>) match(implementation = {vendor(llvm)}, device = {kind(cpu)})
48 #pragma omp declare variant(foofoo <T>) match(implementation={vendor(unknown)})
49 #pragma omp declare variant(foofoo <T>) match(implementation={vendor(score(C+5): ibm, xxx, ibm)},device={kind(cpu,host)})
50 template <typename T, int C>
51 T barbar();
53 // CHECK: #pragma omp declare variant(foofoo<int>) match(implementation={vendor(score(3 + 5): ibm)}, device={kind(cpu, host)})
54 // CHECK-NEXT: #pragma omp declare variant(foofoo<int>) match(implementation={vendor(unknown)})
55 // CHECK-NEXT: #pragma omp declare variant(foofoo<int>) match(implementation={vendor(llvm)}, device={kind(cpu)})
56 // CHECK-NEXT: #pragma omp declare variant(foofoo<int>) match(user={condition(false)})
57 // CHECK-NEXT: #pragma omp declare variant(foofoo<int>) match(user={condition(true)})
58 // CHECK-NEXT: template<> int barbar<int, 3>();
60 // CHECK-NEXT: int baz() {
61 // CHECK-NEXT: return barbar<int, 3>();
62 // CHECK-NEXT: }
63 int baz() {
64 return barbar<int, 3>();
67 // CHECK: template <class C> void h_ref(C *hp, C *hp2, C *hq, C *lin) {
68 // CHECK-NEXT: }
69 // CHECK-NEXT: template<> void h_ref<double>(double *hp, double *hp2, double *hq, double *lin) {
70 // CHECK-NEXT: }
71 // CHECK-NEXT: template<> void h_ref<float>(float *hp, float *hp2, float *hq, float *lin)
72 template <class C>
73 void h_ref(C *hp, C *hp2, C *hq, C *lin) {
76 // CHECK: #pragma omp declare variant(h_ref<C>) match(implementation={vendor(unknown)}, device={kind(nohost)})
77 // CHECK-NEXT: #pragma omp declare variant(h_ref<C>) match(implementation={vendor(llvm)}, device={kind(gpu)})
78 // CHECK-NEXT: template <class C> void h(C *hp, C *hp2, C *hq, C *lin) {
79 // CHECK-NEXT: }
80 #pragma omp declare variant(h_ref <C>) match(xxx = {})
81 #pragma omp declare variant(h_ref <C>) match(implementation = {vendor(llvm)}, device = {kind(gpu)})
82 #pragma omp declare variant(h_ref <C>) match(implementation = {vendor(unknown)}, device = {kind(nohost)})
83 template <class C>
84 void h(C *hp, C *hp2, C *hq, C *lin) {
87 // CHECK: #pragma omp declare variant(h_ref<float>) match(implementation={vendor(unknown)}, device={kind(nohost)})
88 // CHECK-NEXT: #pragma omp declare variant(h_ref<float>) match(implementation={vendor(llvm)}, device={kind(gpu)})
89 // CHECK-NEXT: template<> void h<float>(float *hp, float *hp2, float *hq, float *lin) {
90 // CHECK-NEXT: }
92 // CHECK-NEXT: template<> void h<double>(double *hp, double *hp2, double *hq, double *lin) {
93 // CHECK-NEXT: h((float *)hp, (float *)hp2, (float *)hq, (float *)lin);
94 // CHECK-NEXT: }
95 #pragma omp declare variant(h_ref <double>) match(xxx = {})
96 #pragma omp declare variant(h_ref <double>) match(implementation = {vendor(ibm)}, device = {kind(cpu, gpu)})
97 #pragma omp declare variant(h_ref <double>) match(implementation={vendor(unknown)})
98 template <>
99 void h(double *hp, double *hp2, double *hq, double *lin) {
100 h((float *)hp, (float *)hp2, (float *)hq, (float *)lin);
103 // CHECK: int fn();
104 int fn();
105 // CHECK: int fn(int);
106 int fn(int);
107 // CHECK: #pragma omp declare variant(fn) match(implementation={vendor(unknown)}, device={kind(cpu, gpu)})
108 // CHECK-NEXT: #pragma omp declare variant(fn) match(implementation={vendor(llvm)})
109 // CHECK-NEXT: int overload();
110 #pragma omp declare variant(fn) match(xxx = {})
111 #pragma omp declare variant(fn) match(implementation={vendor(llvm)})
112 #pragma omp declare variant(fn) match(implementation = {vendor(unknown)}, device = {kind(cpu, gpu)})
113 int overload(void);
115 // CHECK: int fn_deduced_variant() {
116 // CHECK-NEXT: return 0;
117 // CHECK-NEXT: }
118 auto fn_deduced_variant() { return 0; }
119 // CHECK: #pragma omp declare variant(fn_deduced_variant) match(implementation={vendor(unknown)}, device={kind(gpu, nohost)})
120 // CHECK-NEXT: #pragma omp declare variant(fn_deduced_variant) match(implementation={vendor(llvm)}, device={kind(cpu, host)})
121 // CHECK-NEXT: int fn_deduced();
122 #pragma omp declare variant(fn_deduced_variant) match(xxx = {})
123 #pragma omp declare variant(fn_deduced_variant) match(implementation = {vendor(llvm)}, device = {kind(cpu, host)})
124 #pragma omp declare variant(fn_deduced_variant) match(implementation = {vendor(unknown)}, device = {kind(gpu, nohost)})
125 int fn_deduced();
127 // CHECK: int fn_deduced_variant1();
128 int fn_deduced_variant1();
129 // CHECK: #pragma omp declare variant(fn_deduced_variant1) match(implementation={vendor(unknown)}, device={kind(cpu, host)})
130 // CHECK-NEXT: #pragma omp declare variant(fn_deduced_variant1) match(implementation={vendor(ibm)}, device={kind(gpu, nohost)})
131 // CHECK-NEXT: int fn_deduced1() {
132 // CHECK-NEXT: return 0;
133 // CHECK-NEXT: }
134 #pragma omp declare variant(fn_deduced_variant1) match(xxx = {})
135 #pragma omp declare variant(fn_deduced_variant1) match(implementation = {vendor(ibm)}, device = {kind(gpu, nohost)})
136 #pragma omp declare variant(fn_deduced_variant1) match(implementation = {vendor(unknown)}, device = {kind(cpu, host)})
137 auto fn_deduced1() { return 0; }
139 // CHECK: struct SpecialFuncs {
140 // CHECK-NEXT: void vd() {
141 // CHECK-NEXT: }
142 // CHECK-NEXT: SpecialFuncs();
143 // CHECK-NEXT: ~SpecialFuncs() noexcept;
144 // CHECK-NEXT: void baz() {
145 // CHECK-NEXT: }
146 // CHECK-NEXT: void bar() {
147 // CHECK-NEXT: }
148 // CHECK-NEXT: void bar(int) {
149 // CHECK-NEXT: }
150 // CHECK-NEXT: #pragma omp declare variant(SpecialFuncs::baz) match(implementation={vendor(unknown)}, device={kind(nohost)})
151 // CHECK-NEXT: #pragma omp declare variant(SpecialFuncs::bar) match(implementation={vendor(ibm)}, device={kind(cpu)})
152 // CHECK-NEXT: void foo1() {
153 // CHECK-NEXT: }
154 // CHECK-NEXT: #pragma omp declare variant(SpecialFuncs::baz) match(implementation={vendor(unknown)}, device={kind(cpu, host)})
155 // CHECK-NEXT: void xxx();
156 // CHECK-NEXT: } s;
157 struct SpecialFuncs {
158 void vd() {}
159 SpecialFuncs();
160 ~SpecialFuncs();
162 void baz() {}
163 void bar() {}
164 void bar(int) {}
165 #pragma omp declare variant(SpecialFuncs::baz) match(xxx = {})
166 #pragma omp declare variant(SpecialFuncs::bar) match(xxx = {})
167 #pragma omp declare variant(SpecialFuncs::bar) match(implementation = {vendor(ibm)}, device = {kind(cpu)})
168 #pragma omp declare variant(SpecialFuncs::baz) match(implementation = {vendor(unknown)}, device = {kind(nohost)})
169 void foo1() {}
170 #pragma omp declare variant(SpecialFuncs::baz) match(implementation = {vendor(unknown)}, device = {kind(cpu, host)})
171 void xxx();
172 } s;
174 // CHECK: #pragma omp declare variant(SpecialFuncs::baz) match(implementation={vendor(unknown)}, device={kind(cpu, host)})
175 // CHECK-NEXT: void SpecialFuncs::xxx() {
176 // CHECK-NEXT: }
177 void SpecialFuncs::xxx() {}
179 // CHECK: static void static_f_variant() {
180 // CHECK-NEXT: }
181 static void static_f_variant() {}
182 // CHECK: #pragma omp declare variant(static_f_variant) match(implementation={vendor(unknown)})
183 // CHECK-NEXT: #pragma omp declare variant(static_f_variant) match(implementation={vendor(llvm)}, device={kind(fpga)})
184 // CHECK-NEXT: static void static_f() {
185 // CHECK-NEXT: }
186 #pragma omp declare variant(static_f_variant) match(xxx = {})
187 #pragma omp declare variant(static_f_variant) match(implementation = {vendor(llvm)}, device = {kind(fpga)})
188 #pragma omp declare variant(static_f_variant) match(implementation={vendor(unknown)})
189 static void static_f() {}
191 // CHECK: void bazzzz() {
192 // CHECK-NEXT: s.foo1();
193 // CHECK-NEXT: static_f();
194 // CHECK-NEXT: }
195 void bazzzz() {
196 s.foo1();
197 static_f();
200 // CHECK: int fn_linkage_variant();
201 // CHECK: extern "C" {
202 // CHECK: #pragma omp declare variant(fn_linkage_variant) match(implementation={vendor(ti)}, device={kind(cpu, host)})
203 // CHECK: int fn_linkage();
204 // CHECK: }
205 int fn_linkage_variant();
206 extern "C" {
207 #pragma omp declare variant(fn_linkage_variant) match(implementation = {vendor(ti)}, device = {kind(cpu, host)})
208 int fn_linkage();
211 // CHECK: extern "C" int fn_linkage_variant1()
212 // CHECK: #pragma omp declare variant(fn_linkage_variant1) match(implementation={vendor(gnu)}, device={kind(cpu, host)})
213 // CHECK: int fn_linkage1();
214 extern "C" int fn_linkage_variant1();
215 #pragma omp declare variant(fn_linkage_variant1) match(implementation = {vendor(gnu)}, device = {kind(cpu, host)})
216 int fn_linkage1();