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 4 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 7 8 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 {{.*}}struct.(anonymous namespace)::A{{.*}} !vcall_visibility [[VIS_TU:![0-9]+]] 13 struct A { 14 A() {} 15 virtual int f() { return 1; } 16 }; 17 } 18 void *construct_A() { 19 return new A(); 20 } 21 22 23 // Hidden visibility. 24 // CHECK: @_ZTV1B = {{.*}} !vcall_visibility [[VIS_DSO:![0-9]+]] 25 // CHECK-MS: @anon.{{.*}} = private unnamed_addr constant {{.*}}struct.B{{.*}} !vcall_visibility [[VIS_DSO:![0-9]+]] 26 struct __attribute__((visibility("hidden"))) B { 27 B() {} 28 virtual int f() { return 1; } 29 }; 30 B *construct_B() { 31 return new B(); 32 } 33 34 35 // Default visibility. 36 // CHECK-NOT: @_ZTV1C = {{.*}} !vcall_visibility 37 // On MS default is hidden 38 // CHECK-MS: @anon.{{.*}} = private unnamed_addr constant {{.*}}struct.C{{.*}} !vcall_visibility [[VIS_DSO]] 39 struct __attribute__((visibility("default"))) C { 40 C() {} 41 virtual int f() { return 1; } 42 }; 43 C *construct_C() { 44 return new C(); 45 } 46 47 48 // Hidden visibility, public LTO visibility. 49 // CHECK-NOT: @_ZTV1D = {{.*}} !vcall_visibility 50 // CHECK-MS-NOT: @anon.{{.*}} = private unnamed_addr constant {{.*}}struct.D{{.*}} !vcall_visibility 51 struct __attribute__((visibility("hidden"))) [[clang::lto_visibility_public]] D { 52 D() {} 53 virtual int f() { return 1; } 54 }; 55 D *construct_D() { 56 return new D(); 57 } 58 59 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 {{.*}}struct.E{{.*}} !vcall_visibility [[VIS_DSO]] 64 struct __attribute__((visibility("hidden"))) E : C { 65 E() {} 66 virtual int f() { return 1; } 67 }; 68 E *construct_E() { 69 return new E(); 70 } 71 72 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 {{.*}}struct.(anonymous namespace)::F{{.*}} !vcall_visibility [[VIS_DSO]] 77 namespace { 78 struct __attribute__((visibility("hidden"))) F : C { 79 F() {} 80 virtual int f() { return 1; } 81 }; 82 } 83 void *construct_F() { 84 return new F(); 85 } 86 87 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 {{.*}}struct.(anonymous namespace)::G{{.*}} !vcall_visibility [[VIS_DSO]] 91 namespace { 92 struct __attribute__((visibility("hidden"))) G : B { 93 G() {} 94 virtual int f() { return 1; } 95 }; 96 } 97 void *construct_G() { 98 return new G(); 99 } 100 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} 107 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 115