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
10 // CHECK: template <typename T> T foofoo() {
11 // CHECK-NEXT: return T();
14 T
foofoo() { return T(); }
16 // CHECK: template<> int foofoo<int>() {
17 // CHECK-NEXT: return int();
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})
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
>
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>();
64 return barbar
<int, 3>();
67 // CHECK: template <class C> void h_ref(C *hp, C *hp2, C *hq, C *lin) {
69 // CHECK-NEXT: template<> void h_ref<double>(double *hp, double *hp2, double *hq, double *lin) {
71 // CHECK-NEXT: template<> void h_ref<float>(float *hp, float *hp2, float *hq, float *lin)
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) {
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)})
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) {
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);
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)})
99 void h(double *hp
, double *hp2
, double *hq
, double *lin
) {
100 h((float *)hp
, (float *)hp2
, (float *)hq
, (float *)lin
);
105 // CHECK: 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)})
115 // CHECK: int fn_deduced_variant() {
116 // CHECK-NEXT: return 0;
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)})
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;
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() {
142 // CHECK-NEXT: SpecialFuncs();
143 // CHECK-NEXT: ~SpecialFuncs() noexcept;
144 // CHECK-NEXT: void baz() {
146 // CHECK-NEXT: void bar() {
148 // CHECK-NEXT: void bar(int) {
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() {
154 // CHECK-NEXT: #pragma omp declare variant(SpecialFuncs::baz) match(implementation={vendor(unknown)}, device={kind(cpu, host)})
155 // CHECK-NEXT: void xxx();
157 struct SpecialFuncs
{
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)})
170 #pragma omp declare variant(SpecialFuncs::baz) match(implementation = {vendor(unknown)}, device = {kind(cpu, host)})
174 // CHECK: #pragma omp declare variant(SpecialFuncs::baz) match(implementation={vendor(unknown)}, device={kind(cpu, host)})
175 // CHECK-NEXT: void SpecialFuncs::xxx() {
177 void SpecialFuncs::xxx() {}
179 // CHECK: static void static_f_variant() {
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() {
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();
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();
205 int fn_linkage_variant();
207 #pragma omp declare variant(fn_linkage_variant) match(implementation = {vendor(ti)}, device = {kind(cpu, host)})
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)})