14e8231b5SAlexey Bataev // RUN: %clang_cc1 -verify -fopenmp -x c++ -triple x86_64-unknown-linux -emit-llvm %s -fexceptions -fcxx-exceptions -o - -fsanitize-address-use-after-scope -DHOST | FileCheck %s
24e8231b5SAlexey Bataev // RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -triple x86_64-unknown-linux -fexceptions -fcxx-exceptions -emit-pch -o %t -fopenmp-version=50 %s -DHOST
34e8231b5SAlexey Bataev // RUN: %clang_cc1 -fopenmp -x c++ -triple x86_64-unknown-linux -fexceptions -fcxx-exceptions -std=c++11 -include-pch %t -verify %s -emit-llvm -o - -fopenmp-version=50 -DHOST | FileCheck %s
44e8231b5SAlexey Bataev // RUN: %clang_cc1 -verify -fopenmp -x c++ -triple aarch64-unknown-linux -emit-llvm %s -fexceptions -fcxx-exceptions -o - -fsanitize-address-use-after-scope -DHOST | FileCheck %s
54e8231b5SAlexey Bataev // RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -triple aarch64-unknown-linux -fexceptions -fcxx-exceptions -emit-pch -o %t -fopenmp-version=50 %s -DHOST
64e8231b5SAlexey Bataev // RUN: %clang_cc1 -fopenmp -x c++ -triple aarch64-unknown-linux -fexceptions -fcxx-exceptions -std=c++11 -include-pch %t -verify %s -emit-llvm -o - -fopenmp-version=50 -DHOST | FileCheck %s
74e8231b5SAlexey Bataev // RUN: %clang_cc1 -verify -fopenmp -x c++ -triple ppc64le-unknown-linux -emit-llvm %s -fexceptions -fcxx-exceptions -o - -fsanitize-address-use-after-scope -DHOST | FileCheck %s
84e8231b5SAlexey Bataev // RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -triple ppc64le-unknown-linux -fexceptions -fcxx-exceptions -emit-pch -o %t -fopenmp-version=50 %s -DHOST
94e8231b5SAlexey Bataev // RUN: %clang_cc1 -fopenmp -x c++ -triple ppc64le-unknown-linux -fexceptions -fcxx-exceptions -std=c++11 -include-pch %t -verify %s -emit-llvm -o - -fopenmp-version=50 -DHOST | FileCheck %s
104e8231b5SAlexey Bataev 
114e8231b5SAlexey Bataev // RUN: %clang_cc1 -verify -fopenmp -x c++ -triple x86_64-unknown-linux -emit-llvm %s -fexceptions -fcxx-exceptions -o - -fsanitize-address-use-after-scope -DCPU | FileCheck %s
124e8231b5SAlexey Bataev // RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -triple x86_64-unknown-linux -fexceptions -fcxx-exceptions -emit-pch -o %t -fopenmp-version=50 %s -DCPU
134e8231b5SAlexey Bataev // RUN: %clang_cc1 -fopenmp -x c++ -triple x86_64-unknown-linux -fexceptions -fcxx-exceptions -std=c++11 -include-pch %t -verify %s -emit-llvm -o - -fopenmp-version=50 -DCPU | FileCheck %s
144e8231b5SAlexey Bataev // RUN: %clang_cc1 -verify -fopenmp -x c++ -triple aarch64-unknown-linux -emit-llvm %s -fexceptions -fcxx-exceptions -o - -fsanitize-address-use-after-scope -DCPU | FileCheck %s
154e8231b5SAlexey Bataev // RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -triple aarch64-unknown-linux -fexceptions -fcxx-exceptions -emit-pch -o %t -fopenmp-version=50 %s -DCPU
164e8231b5SAlexey Bataev // RUN: %clang_cc1 -fopenmp -x c++ -triple aarch64-unknown-linux -fexceptions -fcxx-exceptions -std=c++11 -include-pch %t -verify %s -emit-llvm -o - -fopenmp-version=50 -DCPU | FileCheck %s
174e8231b5SAlexey Bataev // RUN: %clang_cc1 -verify -fopenmp -x c++ -triple ppc64le-unknown-linux -emit-llvm %s -fexceptions -fcxx-exceptions -o - -fsanitize-address-use-after-scope -DCPU | FileCheck %s
184e8231b5SAlexey Bataev // RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -triple ppc64le-unknown-linux -fexceptions -fcxx-exceptions -emit-pch -o %t -fopenmp-version=50 %s -DCPU
194e8231b5SAlexey Bataev // RUN: %clang_cc1 -fopenmp -x c++ -triple ppc64le-unknown-linux -fexceptions -fcxx-exceptions -std=c++11 -include-pch %t -verify %s -emit-llvm -o - -fopenmp-version=50 -DCPU | FileCheck %s
204e8231b5SAlexey Bataev 
214e8231b5SAlexey Bataev // RUN: %clang_cc1 -verify -fopenmp -x c++ -triple x86_64-unknown-linux -fopenmp-targets=x86_64-unknown-linux -emit-llvm-bc %s -o %t-host.bc -DCPU
224e8231b5SAlexey Bataev // RUN: %clang_cc1 -verify -fopenmp -x c++ -triple x86_64-unknown-linux -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-host.bc -o - -DCPU | FileCheck %s
234e8231b5SAlexey Bataev // RUN: %clang_cc1 -verify -fopenmp -x c++ -triple x86_64-unknown-linux -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-host.bc -emit-pch -o %t -DCPU
244e8231b5SAlexey Bataev // RUN: %clang_cc1 -verify -fopenmp -x c++ -triple x86_64-unknown-linux -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-host.bc -include-pch %t -o - -DCPU | FileCheck %s
254e8231b5SAlexey Bataev 
264e8231b5SAlexey Bataev // RUN: %clang_cc1 -verify -fopenmp -x c++ -triple ppc64le-unknown-linux -fopenmp-targets=ppc64le-unknown-linux -emit-llvm-bc %s -o %t-host.bc -DCPU
274e8231b5SAlexey Bataev // RUN: %clang_cc1 -verify -fopenmp -x c++ -triple ppc64le-unknown-linux -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-host.bc -o - -DCPU | FileCheck %s
284e8231b5SAlexey Bataev // RUN: %clang_cc1 -verify -fopenmp -x c++ -triple ppc64le-unknown-linux -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-host.bc -emit-pch -o %t -DCPU
294e8231b5SAlexey Bataev // RUN: %clang_cc1 -verify -fopenmp -x c++ -triple ppc64le-unknown-linux -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-host.bc -include-pch %t -o - -DCPU | FileCheck %s
304e8231b5SAlexey Bataev 
314e8231b5SAlexey Bataev // RUN: %clang_cc1 -verify -fopenmp -x c++ -triple x86_64-unknown-linux -fopenmp-targets=x86_64-unknown-linux -emit-llvm-bc %s -o %t-host.bc -DNOHOST
324e8231b5SAlexey Bataev // RUN: %clang_cc1 -verify -fopenmp -x c++ -triple x86_64-unknown-linux -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-host.bc -o - -DNOHOST | FileCheck %s
334e8231b5SAlexey Bataev // RUN: %clang_cc1 -verify -fopenmp -x c++ -triple x86_64-unknown-linux -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-host.bc -emit-pch -o %t -DNOHOST
344e8231b5SAlexey Bataev // RUN: %clang_cc1 -verify -fopenmp -x c++ -triple x86_64-unknown-linux -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-host.bc -include-pch %t -o - -DNOHOST | FileCheck %s
354e8231b5SAlexey Bataev 
364e8231b5SAlexey Bataev // RUN: %clang_cc1 -verify -fopenmp -x c++ -triple ppc64le-unknown-linux -fopenmp-targets=ppc64le-unknown-linux -emit-llvm-bc %s -o %t-host.bc -DNOHOST
374e8231b5SAlexey Bataev // RUN: %clang_cc1 -verify -fopenmp -x c++ -triple ppc64le-unknown-linux -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-host.bc -o - -DNOHOST | FileCheck %s
384e8231b5SAlexey Bataev // RUN: %clang_cc1 -verify -fopenmp -x c++ -triple ppc64le-unknown-linux -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-host.bc -emit-pch -o %t -DNOHOST
394e8231b5SAlexey Bataev // RUN: %clang_cc1 -verify -fopenmp -x c++ -triple ppc64le-unknown-linux -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-host.bc -include-pch %t -o - -DNOHOST | FileCheck %s
404e8231b5SAlexey Bataev 
414e8231b5SAlexey Bataev // expected-no-diagnostics
424e8231b5SAlexey Bataev 
434e8231b5SAlexey Bataev // CHECK-NOT: ret i32 {{1|4|81|84}}
444e8231b5SAlexey Bataev // CHECK-DAG: @_Z3barv = {{.*}}alias i32 (), i32 ()* @_Z3foov
454e8231b5SAlexey Bataev // CHECK-DAG: @_ZN16SpecSpecialFuncs6MethodEv = {{.*}}alias i32 (%struct.SpecSpecialFuncs*), i32 (%struct.SpecSpecialFuncs*)* @_ZN16SpecSpecialFuncs7method_Ev
464e8231b5SAlexey Bataev // CHECK-DAG: @_ZN16SpecSpecialFuncs6methodEv = linkonce_odr {{.*}}alias i32 (%struct.SpecSpecialFuncs*), i32 (%struct.SpecSpecialFuncs*)* @_ZN16SpecSpecialFuncs7method_Ev
474e8231b5SAlexey Bataev // CHECK-DAG: @_ZN12SpecialFuncs6methodEv = linkonce_odr {{.*}}alias i32 (%struct.SpecialFuncs*), i32 (%struct.SpecialFuncs*)* @_ZN12SpecialFuncs7method_Ev
484e8231b5SAlexey Bataev // CHECK-DAG: @_Z5prio_v = {{.*}}alias i32 (), i32 ()* @_Z5prio1v
494e8231b5SAlexey Bataev // CHECK-DAG: @_ZL6prio1_v = internal alias i32 (), i32 ()* @_ZL5prio2v
504e8231b5SAlexey Bataev // CHECK-DAG: @_Z4callv = {{.*}}alias i32 (), i32 ()* @_Z4testv
514e8231b5SAlexey Bataev // CHECK-DAG: @_ZL9stat_usedv = internal alias i32 (), i32 ()* @_ZL10stat_used_v
524e8231b5SAlexey Bataev // CHECK-DAG: @_ZN12SpecialFuncs6MethodEv = {{.*}}alias i32 (%struct.SpecialFuncs*), i32 (%struct.SpecialFuncs*)* @_ZN12SpecialFuncs7method_Ev
534e8231b5SAlexey Bataev // CHECK-DAG: @fn_linkage = {{.*}}alias i32 (), i32 ()* @_Z18fn_linkage_variantv
544e8231b5SAlexey Bataev // CHECK-DAG: @_Z11fn_linkage1v = {{.*}}alias i32 (), i32 ()* @fn_linkage_variant1
554e8231b5SAlexey Bataev // CHECK-DAG: declare {{.*}}i32 @_Z5bazzzv()
564e8231b5SAlexey Bataev // CHECK-DAG: declare {{.*}}i32 @_Z3bazv()
574e8231b5SAlexey Bataev // CHECK-DAG: ret i32 2
584e8231b5SAlexey Bataev // CHECK-DAG: ret i32 3
594e8231b5SAlexey Bataev // CHECK-DAG: ret i32 5
604e8231b5SAlexey Bataev // CHECK-DAG: ret i32 6
614e8231b5SAlexey Bataev // CHECK-DAG: ret i32 7
624e8231b5SAlexey Bataev // CHECK-DAG: ret i32 82
634e8231b5SAlexey Bataev // CHECK-DAG: ret i32 83
644e8231b5SAlexey Bataev // CHECK-DAG: ret i32 85
654e8231b5SAlexey Bataev // CHECK-DAG: ret i32 86
664e8231b5SAlexey Bataev // CHECK-DAG: ret i32 87
674e8231b5SAlexey Bataev // CHECK-NOT: ret i32 {{1|4|81|84}}
684e8231b5SAlexey Bataev 
694e8231b5SAlexey Bataev #ifndef HEADER
704e8231b5SAlexey Bataev #define HEADER
714e8231b5SAlexey Bataev 
724e8231b5SAlexey Bataev #pragma omp declare target
734e8231b5SAlexey Bataev #ifdef HOST
74*1228d42dSJohannes Doerfert #define SUBSET host
75*1228d42dSJohannes Doerfert #define CORRECT host, cpu
764e8231b5SAlexey Bataev #define WRONG host, nohost
774e8231b5SAlexey Bataev #endif // HOST
784e8231b5SAlexey Bataev #ifdef CPU
79*1228d42dSJohannes Doerfert #define SUBSET cpu
80*1228d42dSJohannes Doerfert #define CORRECT cpu, any
814e8231b5SAlexey Bataev #define WRONG cpu, gpu
824e8231b5SAlexey Bataev #endif // CPU
834e8231b5SAlexey Bataev #ifdef NOHOST
84*1228d42dSJohannes Doerfert #define SUBSET nohost
85*1228d42dSJohannes Doerfert #define CORRECT nohost, cpu
864e8231b5SAlexey Bataev #define WRONG nohost, host
874e8231b5SAlexey Bataev #endif // NOHOST
884e8231b5SAlexey Bataev 
894e8231b5SAlexey Bataev int foo() { return 2; }
904e8231b5SAlexey Bataev 
914e8231b5SAlexey Bataev #pragma omp declare variant(foo) match(device = {kind(CORRECT)})
924e8231b5SAlexey Bataev int bar() { return 1; }
934e8231b5SAlexey Bataev 
944e8231b5SAlexey Bataev int bazzz();
954e8231b5SAlexey Bataev #pragma omp declare variant(bazzz) match(device = {kind(CORRECT)})
964e8231b5SAlexey Bataev int baz() { return 1; }
974e8231b5SAlexey Bataev 
984e8231b5SAlexey Bataev int test();
994e8231b5SAlexey Bataev #pragma omp declare variant(test) match(device = {kind(CORRECT)})
1004e8231b5SAlexey Bataev int call() { return 1; }
1014e8231b5SAlexey Bataev 
1024e8231b5SAlexey Bataev static int stat_unused_();
1034e8231b5SAlexey Bataev #pragma omp declare variant(stat_unused_) match(device = {kind(CORRECT)})
1044e8231b5SAlexey Bataev static int stat_unused() { return 1; }
1054e8231b5SAlexey Bataev 
1064e8231b5SAlexey Bataev static int stat_used_();
1074e8231b5SAlexey Bataev #pragma omp declare variant(stat_used_) match(device = {kind(CORRECT)})
1084e8231b5SAlexey Bataev static int stat_used() { return 1; }
1094e8231b5SAlexey Bataev 
1104e8231b5SAlexey Bataev int main() { return bar() + baz() + call() + stat_used(); }
1114e8231b5SAlexey Bataev 
1124e8231b5SAlexey Bataev int test() { return 3; }
1134e8231b5SAlexey Bataev static int stat_unused_() { return 4; }
1144e8231b5SAlexey Bataev static int stat_used_() { return 5; }
1154e8231b5SAlexey Bataev 
1164e8231b5SAlexey Bataev struct SpecialFuncs {
1174e8231b5SAlexey Bataev   void vd() {}
1184e8231b5SAlexey Bataev   SpecialFuncs();
1194e8231b5SAlexey Bataev   ~SpecialFuncs();
1204e8231b5SAlexey Bataev 
1214e8231b5SAlexey Bataev   int method_() { return 6; }
1224e8231b5SAlexey Bataev #pragma omp declare variant(SpecialFuncs::method_) \
1234e8231b5SAlexey Bataev     match(device = {kind(CORRECT)})
1244e8231b5SAlexey Bataev   int method() { return 1; }
1254e8231b5SAlexey Bataev #pragma omp declare variant(SpecialFuncs::method_) \
1264e8231b5SAlexey Bataev     match(device = {kind(CORRECT)})
1274e8231b5SAlexey Bataev   int Method();
1284e8231b5SAlexey Bataev } s;
1294e8231b5SAlexey Bataev 
1304e8231b5SAlexey Bataev int SpecialFuncs::Method() { return 1; }
1314e8231b5SAlexey Bataev 
1324e8231b5SAlexey Bataev struct SpecSpecialFuncs {
1334e8231b5SAlexey Bataev   void vd() {}
1344e8231b5SAlexey Bataev   SpecSpecialFuncs();
1354e8231b5SAlexey Bataev   ~SpecSpecialFuncs();
1364e8231b5SAlexey Bataev 
1374e8231b5SAlexey Bataev   int method_();
1384e8231b5SAlexey Bataev #pragma omp declare variant(SpecSpecialFuncs::method_) \
1394e8231b5SAlexey Bataev     match(device = {kind(CORRECT)})
1404e8231b5SAlexey Bataev   int method() { return 1; }
1414e8231b5SAlexey Bataev #pragma omp declare variant(SpecSpecialFuncs::method_) \
1424e8231b5SAlexey Bataev     match(device = {kind(CORRECT)})
1434e8231b5SAlexey Bataev   int Method();
1444e8231b5SAlexey Bataev } s1;
1454e8231b5SAlexey Bataev 
1464e8231b5SAlexey Bataev int SpecSpecialFuncs::method_() { return 7; }
1474e8231b5SAlexey Bataev int SpecSpecialFuncs::Method() { return 1; }
1484e8231b5SAlexey Bataev 
1494e8231b5SAlexey Bataev void xxx() {
1504e8231b5SAlexey Bataev   (void)s.method();
1514e8231b5SAlexey Bataev   (void)s1.method();
1524e8231b5SAlexey Bataev }
1534e8231b5SAlexey Bataev 
1544e8231b5SAlexey Bataev int prio() { return 81; }
1554e8231b5SAlexey Bataev int prio1() { return 82; }
1564e8231b5SAlexey Bataev 
1574e8231b5SAlexey Bataev #pragma omp declare variant(prio) match(device = {kind(SUBSET)})
1584e8231b5SAlexey Bataev #pragma omp declare variant(prio1) match(device = {kind(CORRECT)})
1594e8231b5SAlexey Bataev int prio_() { return 1; }
1604e8231b5SAlexey Bataev 
1614e8231b5SAlexey Bataev static int prio2() { return 83; }
1624e8231b5SAlexey Bataev static int prio3() { return 84; }
1634e8231b5SAlexey Bataev static int prio4() { return 84; }
1644e8231b5SAlexey Bataev 
1654e8231b5SAlexey Bataev #pragma omp declare variant(prio4) match(device = {kind(SUBSET)})
1664e8231b5SAlexey Bataev #pragma omp declare variant(prio2) match(device = {kind(CORRECT)})
1674e8231b5SAlexey Bataev #pragma omp declare variant(prio3) match(device = {kind(SUBSET)})
1684e8231b5SAlexey Bataev static int prio1_() { return 1; }
1694e8231b5SAlexey Bataev 
1704e8231b5SAlexey Bataev int int_fn() { return prio1_(); }
1714e8231b5SAlexey Bataev 
1724e8231b5SAlexey Bataev int fn_linkage_variant() { return 85; }
1734e8231b5SAlexey Bataev extern "C" {
1744e8231b5SAlexey Bataev #pragma omp declare variant(fn_linkage_variant) match(device = {kind(CORRECT)})
1754e8231b5SAlexey Bataev int fn_linkage() { return 1; }
1764e8231b5SAlexey Bataev }
1774e8231b5SAlexey Bataev 
1784e8231b5SAlexey Bataev extern "C" int fn_linkage_variant1() { return 86; }
1794e8231b5SAlexey Bataev #pragma omp declare variant(fn_linkage_variant1) match(device = {kind(CORRECT)})
1804e8231b5SAlexey Bataev int fn_linkage1() { return 1; }
1814e8231b5SAlexey Bataev 
1824e8231b5SAlexey Bataev int fn_variant2() { return 1; }
1834e8231b5SAlexey Bataev #pragma omp declare variant(fn_variant2) match(device = {kind(WRONG)})
1844e8231b5SAlexey Bataev int fn2() { return 87; }
1854e8231b5SAlexey Bataev 
1864e8231b5SAlexey Bataev #pragma omp end declare target
1874e8231b5SAlexey Bataev #endif // HEADER
188