[clang] Handle __declspec() attributes in using
[llvm-project.git] / clang / test / CodeGenCXX / vcall-visibility-metadata.cpp
blob1ad09ad0039a27bb5d57fb373f44a9da8e9f19ad
1 // RUN: %clang_cc1 -flto -flto-unit -triple x86_64-unknown-linux -emit-llvm -fvirtual-function-elimination -fwhole-program-vtables -o - %s | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-VFE
2 // RUN: %clang_cc1 -flto -flto-unit -triple x86_64-unknown-linux -emit-llvm -fwhole-program-vtables -o - %s | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-NOVFE
3 // RUN: %clang_cc1 -flto -flto-unit -triple x86_64-pc-windows-msvc -emit-llvm -fwhole-program-vtables -o - %s | FileCheck %s --check-prefix=CHECK-MS --check-prefix=CHECK-NOVFE
5 // Check that in ThinLTO we also get vcall_visibility summary entries in the bitcode
6 // RUN: %clang_cc1 -flto=thin -flto-unit -triple x86_64-unknown-linux -emit-llvm-bc -fwhole-program-vtables -o - %s | llvm-dis -o - | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-NOVFE --check-prefix=CHECK-SUMMARY
9 // Anonymous namespace.
10 namespace {
11 // CHECK: @_ZTVN12_GLOBAL__N_11AE = {{.*}} !vcall_visibility [[VIS_TU:![0-9]+]]
12 // CHECK-MS: @anon.{{.*}} = private unnamed_addr constant {{.*}}@"??_R4A@?A{{.*}}@@6B@"{{.*}} !vcall_visibility [[VIS_TU:![0-9]+]]
13 struct A {
14 A() {}
15 virtual int f() { return 1; }
18 void *construct_A() {
19 return new A();
23 // Hidden visibility.
24 // CHECK: @_ZTV1B = {{.*}} !vcall_visibility [[VIS_DSO:![0-9]+]]
25 // CHECK-MS: @anon.{{.*}} = private unnamed_addr constant {{.*}}@"??_R4B@@6B@"{{.*}} !vcall_visibility [[VIS_DSO:![0-9]+]]
26 struct __attribute__((visibility("hidden"))) B {
27 B() {}
28 virtual int f() { return 1; }
30 B *construct_B() {
31 return new B();
35 // Default visibility.
36 // CHECK-NOT: @_ZTV1C = {{.*}} !vcall_visibility
37 // On MS default is hidden
38 // CHECK-MS: @anon.{{.*}} = private unnamed_addr constant {{.*}}@"??_R4C@@6B@"{{.*}} !vcall_visibility [[VIS_DSO]]
39 struct __attribute__((visibility("default"))) C {
40 C() {}
41 virtual int f() { return 1; }
43 C *construct_C() {
44 return new C();
48 // Hidden visibility, public LTO visibility.
49 // CHECK-NOT: @_ZTV1D = {{.*}} !vcall_visibility
50 // CHECK-MS-NOT: @anon.{{.*}} = private unnamed_addr constant {{.*}}@"??_R4D@@6B@"{{.*}} !vcall_visibility
51 struct __attribute__((visibility("hidden"))) [[clang::lto_visibility_public]] D {
52 D() {}
53 virtual int f() { return 1; }
55 D *construct_D() {
56 return new D();
60 // Hidden visibility, but inherits from class with default visibility.
61 // CHECK-NOT: @_ZTV1E = {{.*}} !vcall_visibility
62 // On MS default is hidden
63 // CHECK-MS: @anon.{{.*}} = private unnamed_addr constant {{.*}}@"??_R4E@@6B@"{{.*}} !vcall_visibility [[VIS_DSO]]
64 struct __attribute__((visibility("hidden"))) E : C {
65 E() {}
66 virtual int f() { return 1; }
68 E *construct_E() {
69 return new E();
73 // Anonymous namespace, but inherits from class with default visibility.
74 // CHECK-NOT: @_ZTVN12_GLOBAL__N_11FE = {{.*}} !vcall_visibility
75 // On MS default is hidden
76 // CHECK-MS: @anon.{{.*}} = private unnamed_addr constant {{.*}}@"??_R4F@?A{{.*}}@@6B@"{{.*}} !vcall_visibility [[VIS_DSO]]
77 namespace {
78 struct __attribute__((visibility("hidden"))) F : C {
79 F() {}
80 virtual int f() { return 1; }
83 void *construct_F() {
84 return new F();
88 // Anonymous namespace, but inherits from class with hidden visibility.
89 // CHECK: @_ZTVN12_GLOBAL__N_11GE = {{.*}} !vcall_visibility [[VIS_DSO:![0-9]+]]
90 // CHECK-MS: @anon.{{.*}} = private unnamed_addr constant {{.*}}@"??_R4G@?A{{.*}}@@6B@"{{.*}} !vcall_visibility [[VIS_DSO]]
91 namespace {
92 struct __attribute__((visibility("hidden"))) G : B {
93 G() {}
94 virtual int f() { return 1; }
97 void *construct_G() {
98 return new G();
101 // CHECK-MS-DAG: [[VIS_DSO]] = !{i64 1}
102 // CHECK-MS-DAG: [[VIS_TU]] = !{i64 2}
103 // CHECK-DAG: [[VIS_DSO]] = !{i64 1}
104 // CHECK-DAG: [[VIS_TU]] = !{i64 2}
105 // CHECK-VFE-DAG: !{i32 1, !"Virtual Function Elim", i32 1}
106 // CHECK-NOVFE-DAG: !{i32 1, !"Virtual Function Elim", i32 0}
108 // CHECK-SUMMARY-DAG: gv: (name: "_ZTV1B", {{.*}} vcall_visibility: 1
109 // CHECK-SUMMARY-DAG: gv: (name: "_ZTVN12_GLOBAL__N_11FE", {{.*}} vcall_visibility: 0
110 // CHECK-SUMMARY-DAG: gv: (name: "_ZTV1D", {{.*}} vcall_visibility: 0
111 // CHECK-SUMMARY-DAG: gv: (name: "_ZTV1C", {{.*}} vcall_visibility: 0
112 // CHECK-SUMMARY-DAG: gv: (name: "_ZTV1E", {{.*}} vcall_visibility: 0
113 // CHECK-SUMMARY-DAG: gv: (name: "_ZTVN12_GLOBAL__N_11AE", {{.*}} vcall_visibility: 2
114 // CHECK-SUMMARY-DAG: gv: (name: "_ZTVN12_GLOBAL__N_11GE", {{.*}} vcall_visibility: 1