Skip to content

Commit 3b598b9

Browse files
committed
Reland: Dead Virtual Function Elimination
Remove dead virtual functions from vtables with replaceNonMetadataUsesWith, so that CGProfile metadata gets cleaned up correctly. Original commit message: Currently, it is hard for the compiler to remove unused C++ virtual functions, because they are all referenced from vtables, which are referenced by constructors. This means that if the constructor is called from any live code, then we keep every virtual function in the final link, even if there are no call sites which can use it. This patch allows unused virtual functions to be removed during LTO (and regular compilation in limited circumstances) by using type metadata to match virtual function call sites to the vtable slots they might load from. This information can then be used in the global dead code elimination pass instead of the references from vtables to virtual functions, to more accurately determine which functions are reachable. To make this transformation safe, I have changed clang's code-generation to always load virtual function pointers using the llvm.type.checked.load intrinsic, instead of regular load instructions. I originally tried writing this using clang's existing code-generation, which uses the llvm.type.test and llvm.assume intrinsics after doing a normal load. However, it is possible for optimisations to obscure the relationship between the GEP, load and llvm.type.test, causing GlobalDCE to fail to find virtual function call sites. The existing linkage and visibility types don't accurately describe the scope in which a virtual call could be made which uses a given vtable. This is wider than the visibility of the type itself, because a virtual function call could be made using a more-visible base class. I've added a new !vcall_visibility metadata type to represent this, described in TypeMetadata.rst. The internalization pass and libLTO have been updated to change this metadata when linking is performed. This doesn't currently work with ThinLTO, because it needs to see every call to llvm.type.checked.load in the linkage unit. It might be possible to extend this optimisation to be able to use the ThinLTO summary, as was done for devirtualization, but until then that combination is rejected in the clang driver. To test this, I've written a fuzzer which generates random C++ programs with complex class inheritance graphs, and virtual functions called through object and function pointers of different types. The programs are spread across multiple translation units and DSOs to test the different visibility restrictions. I've also tried doing bootstrap builds of LLVM to test this. This isn't ideal, because only classes in anonymous namespaces can be optimised with -fvisibility=default, and some parts of LLVM (plugins and bugpoint) do not work correctly with -fvisibility=hidden. However, there are only 12 test failures when building with -fvisibility=hidden (and an unmodified compiler), and this change does not cause any new failures for either value of -fvisibility. On the 7 C++ sub-benchmarks of SPEC2006, this gives a geomean code-size reduction of ~6%, over a baseline compiled with "-O2 -flto -fvisibility=hidden -fwhole-program-vtables". The best cases are reductions of ~14% in 450.soplex and 483.xalancbmk, and there are no code size increases. I've also run this on a set of 8 mbed-os examples compiled for Armv7M, which show a geomean size reduction of ~3%, again with no size increases. I had hoped that this would have no effect on performance, which would allow it to awlays be enabled (when using -fwhole-program-vtables). However, the changes in clang to use the llvm.type.checked.load intrinsic are causing ~1% performance regression in the C++ parts of SPEC2006. It should be possible to recover some of this perf loss by teaching optimisations about the llvm.type.checked.load intrinsic, which would make it worth turning this on by default (though it's still dependent on -fwhole-program-vtables). Differential revision: https://reviews.llvm.org/D63932 llvm-svn: 375094
1 parent 77cad0b commit 3b598b9

34 files changed

+1428
-83
lines changed

clang/include/clang/Basic/CodeGenOptions.def

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,10 @@ CODEGENOPT(EmitLLVMUseLists, 1, 0) ///< Control whether to serialize use-lists.
278278
CODEGENOPT(WholeProgramVTables, 1, 0) ///< Whether to apply whole-program
279279
/// vtable optimization.
280280

281+
CODEGENOPT(VirtualFunctionElimination, 1, 0) ///< Whether to apply the dead
282+
/// virtual function elimination
283+
/// optimization.
284+
281285
/// Whether to use public LTO visibility for entities in std and stdext
282286
/// namespaces. This is enabled by clang-cl's /MT and /MTd flags.
283287
CODEGENOPT(LTOVisibilityPublicStd, 1, 0)

clang/include/clang/Driver/Options.td

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1885,6 +1885,13 @@ def fforce_emit_vtables : Flag<["-"], "fforce-emit-vtables">, Group<f_Group>,
18851885
HelpText<"Emits more virtual tables to improve devirtualization">;
18861886
def fno_force_emit_vtables : Flag<["-"], "fno-force-emit-vtables">, Group<f_Group>,
18871887
Flags<[CoreOption]>;
1888+
1889+
def fvirtual_function_elimination : Flag<["-"], "fvirtual-function-elimination">, Group<f_Group>,
1890+
Flags<[CoreOption, CC1Option]>,
1891+
HelpText<"Enables dead virtual function elimination optimization. Requires -flto=full">;
1892+
def fno_virtual_function_elimination : Flag<["-"], "fno-virtual-function_elimination">, Group<f_Group>,
1893+
Flags<[CoreOption]>;
1894+
18881895
def fwrapv : Flag<["-"], "fwrapv">, Group<f_Group>, Flags<[CC1Option]>,
18891896
HelpText<"Treat signed integer overflow as two's complement">;
18901897
def fwritable_strings : Flag<["-"], "fwritable-strings">, Group<f_Group>, Flags<[CC1Option]>,

clang/lib/CodeGen/CGClass.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2784,11 +2784,16 @@ void CodeGenFunction::EmitVTablePtrCheck(const CXXRecordDecl *RD,
27842784

27852785
bool CodeGenFunction::ShouldEmitVTableTypeCheckedLoad(const CXXRecordDecl *RD) {
27862786
if (!CGM.getCodeGenOpts().WholeProgramVTables ||
2787-
!SanOpts.has(SanitizerKind::CFIVCall) ||
2788-
!CGM.getCodeGenOpts().SanitizeTrap.has(SanitizerKind::CFIVCall) ||
27892787
!CGM.HasHiddenLTOVisibility(RD))
27902788
return false;
27912789

2790+
if (CGM.getCodeGenOpts().VirtualFunctionElimination)
2791+
return true;
2792+
2793+
if (!SanOpts.has(SanitizerKind::CFIVCall) ||
2794+
!CGM.getCodeGenOpts().SanitizeTrap.has(SanitizerKind::CFIVCall))
2795+
return false;
2796+
27922797
std::string TypeName = RD->getQualifiedNameAsString();
27932798
return !getContext().getSanitizerBlacklist().isBlacklistedType(
27942799
SanitizerKind::CFIVCall, TypeName);
@@ -2811,8 +2816,13 @@ llvm::Value *CodeGenFunction::EmitVTableTypeCheckedLoad(
28112816
TypeId});
28122817
llvm::Value *CheckResult = Builder.CreateExtractValue(CheckedLoad, 1);
28132818

2814-
EmitCheck(std::make_pair(CheckResult, SanitizerKind::CFIVCall),
2815-
SanitizerHandler::CFICheckFail, nullptr, nullptr);
2819+
std::string TypeName = RD->getQualifiedNameAsString();
2820+
if (SanOpts.has(SanitizerKind::CFIVCall) &&
2821+
!getContext().getSanitizerBlacklist().isBlacklistedType(
2822+
SanitizerKind::CFIVCall, TypeName)) {
2823+
EmitCheck(std::make_pair(CheckResult, SanitizerKind::CFIVCall),
2824+
SanitizerHandler::CFICheckFail, {}, {});
2825+
}
28162826

28172827
return Builder.CreateBitCast(
28182828
Builder.CreateExtractValue(CheckedLoad, 0),

clang/lib/CodeGen/CGVTables.cpp

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -808,7 +808,7 @@ CodeGenVTables::GenerateConstructionVTable(const CXXRecordDecl *RD,
808808
assert(!VTable->isDeclaration() && "Shouldn't set properties on declaration");
809809
CGM.setGVProperties(VTable, RD);
810810

811-
CGM.EmitVTableTypeMetadata(VTable, *VTLayout.get());
811+
CGM.EmitVTableTypeMetadata(RD, VTable, *VTLayout.get());
812812

813813
return VTable;
814814
}
@@ -1039,7 +1039,32 @@ bool CodeGenModule::HasHiddenLTOVisibility(const CXXRecordDecl *RD) {
10391039
return true;
10401040
}
10411041

1042-
void CodeGenModule::EmitVTableTypeMetadata(llvm::GlobalVariable *VTable,
1042+
llvm::GlobalObject::VCallVisibility
1043+
CodeGenModule::GetVCallVisibilityLevel(const CXXRecordDecl *RD) {
1044+
LinkageInfo LV = RD->getLinkageAndVisibility();
1045+
llvm::GlobalObject::VCallVisibility TypeVis;
1046+
if (!isExternallyVisible(LV.getLinkage()))
1047+
TypeVis = llvm::GlobalObject::VCallVisibilityTranslationUnit;
1048+
else if (HasHiddenLTOVisibility(RD))
1049+
TypeVis = llvm::GlobalObject::VCallVisibilityLinkageUnit;
1050+
else
1051+
TypeVis = llvm::GlobalObject::VCallVisibilityPublic;
1052+
1053+
for (auto B : RD->bases())
1054+
if (B.getType()->getAsCXXRecordDecl()->isDynamicClass())
1055+
TypeVis = std::min(TypeVis,
1056+
GetVCallVisibilityLevel(B.getType()->getAsCXXRecordDecl()));
1057+
1058+
for (auto B : RD->vbases())
1059+
if (B.getType()->getAsCXXRecordDecl()->isDynamicClass())
1060+
TypeVis = std::min(TypeVis,
1061+
GetVCallVisibilityLevel(B.getType()->getAsCXXRecordDecl()));
1062+
1063+
return TypeVis;
1064+
}
1065+
1066+
void CodeGenModule::EmitVTableTypeMetadata(const CXXRecordDecl *RD,
1067+
llvm::GlobalVariable *VTable,
10431068
const VTableLayout &VTLayout) {
10441069
if (!getCodeGenOpts().LTOUnit)
10451070
return;
@@ -1099,4 +1124,10 @@ void CodeGenModule::EmitVTableTypeMetadata(llvm::GlobalVariable *VTable,
10991124
VTable->addTypeMetadata((PointerWidth * I).getQuantity(), MD);
11001125
}
11011126
}
1127+
1128+
if (getCodeGenOpts().VirtualFunctionElimination) {
1129+
llvm::GlobalObject::VCallVisibility TypeVis = GetVCallVisibilityLevel(RD);
1130+
if (TypeVis != llvm::GlobalObject::VCallVisibilityPublic)
1131+
VTable->addVCallVisibilityMetadata(TypeVis);
1132+
}
11021133
}

clang/lib/CodeGen/CodeGenModule.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1280,8 +1280,16 @@ class CodeGenModule : public CodeGenTypeCache {
12801280
/// optimization.
12811281
bool HasHiddenLTOVisibility(const CXXRecordDecl *RD);
12821282

1283+
/// Returns the vcall visibility of the given type. This is the scope in which
1284+
/// a virtual function call could be made which ends up being dispatched to a
1285+
/// member function of this class. This scope can be wider than the visibility
1286+
/// of the class itself when the class has a more-visible dynamic base class.
1287+
llvm::GlobalObject::VCallVisibility
1288+
GetVCallVisibilityLevel(const CXXRecordDecl *RD);
1289+
12831290
/// Emit type metadata for the given vtable using the given layout.
1284-
void EmitVTableTypeMetadata(llvm::GlobalVariable *VTable,
1291+
void EmitVTableTypeMetadata(const CXXRecordDecl *RD,
1292+
llvm::GlobalVariable *VTable,
12851293
const VTableLayout &VTLayout);
12861294

12871295
/// Generate a cross-DSO type identifier for MD.

clang/lib/CodeGen/ItaniumCXXABI.cpp

Lines changed: 70 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -644,53 +644,88 @@ CGCallee ItaniumCXXABI::EmitLoadOfMemberFunctionPointer(
644644
VTableOffset = Builder.CreateTrunc(VTableOffset, CGF.Int32Ty);
645645
VTableOffset = Builder.CreateZExt(VTableOffset, CGM.PtrDiffTy);
646646
}
647-
// Compute the address of the virtual function pointer.
648-
llvm::Value *VFPAddr = Builder.CreateGEP(VTable, VTableOffset);
649647

650648
// Check the address of the function pointer if CFI on member function
651649
// pointers is enabled.
652650
llvm::Constant *CheckSourceLocation;
653651
llvm::Constant *CheckTypeDesc;
654652
bool ShouldEmitCFICheck = CGF.SanOpts.has(SanitizerKind::CFIMFCall) &&
655653
CGM.HasHiddenLTOVisibility(RD);
656-
if (ShouldEmitCFICheck) {
657-
CodeGenFunction::SanitizerScope SanScope(&CGF);
658-
659-
CheckSourceLocation = CGF.EmitCheckSourceLocation(E->getBeginLoc());
660-
CheckTypeDesc = CGF.EmitCheckTypeDescriptor(QualType(MPT, 0));
661-
llvm::Constant *StaticData[] = {
662-
llvm::ConstantInt::get(CGF.Int8Ty, CodeGenFunction::CFITCK_VMFCall),
663-
CheckSourceLocation,
664-
CheckTypeDesc,
665-
};
666-
667-
llvm::Metadata *MD =
668-
CGM.CreateMetadataIdentifierForVirtualMemPtrType(QualType(MPT, 0));
669-
llvm::Value *TypeId = llvm::MetadataAsValue::get(CGF.getLLVMContext(), MD);
654+
bool ShouldEmitVFEInfo = CGM.getCodeGenOpts().VirtualFunctionElimination &&
655+
CGM.HasHiddenLTOVisibility(RD);
656+
llvm::Value *VirtualFn = nullptr;
670657

671-
llvm::Value *TypeTest = Builder.CreateCall(
672-
CGM.getIntrinsic(llvm::Intrinsic::type_test), {VFPAddr, TypeId});
658+
{
659+
CodeGenFunction::SanitizerScope SanScope(&CGF);
660+
llvm::Value *TypeId = nullptr;
661+
llvm::Value *CheckResult = nullptr;
662+
663+
if (ShouldEmitCFICheck || ShouldEmitVFEInfo) {
664+
// If doing CFI or VFE, we will need the metadata node to check against.
665+
llvm::Metadata *MD =
666+
CGM.CreateMetadataIdentifierForVirtualMemPtrType(QualType(MPT, 0));
667+
TypeId = llvm::MetadataAsValue::get(CGF.getLLVMContext(), MD);
668+
}
673669

674-
if (CGM.getCodeGenOpts().SanitizeTrap.has(SanitizerKind::CFIMFCall)) {
675-
CGF.EmitTrapCheck(TypeTest);
670+
llvm::Value *VFPAddr = Builder.CreateGEP(VTable, VTableOffset);
671+
672+
if (ShouldEmitVFEInfo) {
673+
// If doing VFE, load from the vtable with a type.checked.load intrinsic
674+
// call. Note that we use the GEP to calculate the address to load from
675+
// and pass 0 as the offset to the intrinsic. This is because every
676+
// vtable slot of the correct type is marked with matching metadata, and
677+
// we know that the load must be from one of these slots.
678+
llvm::Value *CheckedLoad = Builder.CreateCall(
679+
CGM.getIntrinsic(llvm::Intrinsic::type_checked_load),
680+
{VFPAddr, llvm::ConstantInt::get(CGM.Int32Ty, 0), TypeId});
681+
CheckResult = Builder.CreateExtractValue(CheckedLoad, 1);
682+
VirtualFn = Builder.CreateExtractValue(CheckedLoad, 0);
683+
VirtualFn = Builder.CreateBitCast(VirtualFn, FTy->getPointerTo(),
684+
"memptr.virtualfn");
676685
} else {
677-
llvm::Value *AllVtables = llvm::MetadataAsValue::get(
678-
CGM.getLLVMContext(),
679-
llvm::MDString::get(CGM.getLLVMContext(), "all-vtables"));
680-
llvm::Value *ValidVtable = Builder.CreateCall(
681-
CGM.getIntrinsic(llvm::Intrinsic::type_test), {VTable, AllVtables});
682-
CGF.EmitCheck(std::make_pair(TypeTest, SanitizerKind::CFIMFCall),
683-
SanitizerHandler::CFICheckFail, StaticData,
684-
{VTable, ValidVtable});
686+
// When not doing VFE, emit a normal load, as it allows more
687+
// optimisations than type.checked.load.
688+
if (ShouldEmitCFICheck) {
689+
CheckResult = Builder.CreateCall(
690+
CGM.getIntrinsic(llvm::Intrinsic::type_test),
691+
{Builder.CreateBitCast(VFPAddr, CGF.Int8PtrTy), TypeId});
692+
}
693+
VFPAddr =
694+
Builder.CreateBitCast(VFPAddr, FTy->getPointerTo()->getPointerTo());
695+
VirtualFn = Builder.CreateAlignedLoad(VFPAddr, CGF.getPointerAlign(),
696+
"memptr.virtualfn");
685697
}
698+
assert(VirtualFn && "Virtual fuction pointer not created!");
699+
assert((!ShouldEmitCFICheck || !ShouldEmitVFEInfo || CheckResult) &&
700+
"Check result required but not created!");
701+
702+
if (ShouldEmitCFICheck) {
703+
// If doing CFI, emit the check.
704+
CheckSourceLocation = CGF.EmitCheckSourceLocation(E->getBeginLoc());
705+
CheckTypeDesc = CGF.EmitCheckTypeDescriptor(QualType(MPT, 0));
706+
llvm::Constant *StaticData[] = {
707+
llvm::ConstantInt::get(CGF.Int8Ty, CodeGenFunction::CFITCK_VMFCall),
708+
CheckSourceLocation,
709+
CheckTypeDesc,
710+
};
686711

687-
FnVirtual = Builder.GetInsertBlock();
688-
}
712+
if (CGM.getCodeGenOpts().SanitizeTrap.has(SanitizerKind::CFIMFCall)) {
713+
CGF.EmitTrapCheck(CheckResult);
714+
} else {
715+
llvm::Value *AllVtables = llvm::MetadataAsValue::get(
716+
CGM.getLLVMContext(),
717+
llvm::MDString::get(CGM.getLLVMContext(), "all-vtables"));
718+
llvm::Value *ValidVtable = Builder.CreateCall(
719+
CGM.getIntrinsic(llvm::Intrinsic::type_test), {VTable, AllVtables});
720+
CGF.EmitCheck(std::make_pair(CheckResult, SanitizerKind::CFIMFCall),
721+
SanitizerHandler::CFICheckFail, StaticData,
722+
{VTable, ValidVtable});
723+
}
724+
725+
FnVirtual = Builder.GetInsertBlock();
726+
}
727+
} // End of sanitizer scope
689728

690-
// Load the virtual function to call.
691-
VFPAddr = Builder.CreateBitCast(VFPAddr, FTy->getPointerTo()->getPointerTo());
692-
llvm::Value *VirtualFn = Builder.CreateAlignedLoad(
693-
VFPAddr, CGF.getPointerAlign(), "memptr.virtualfn");
694729
CGF.EmitBranch(FnEnd);
695730

696731
// In the non-virtual path, the function pointer is actually a
@@ -1634,7 +1669,7 @@ void ItaniumCXXABI::emitVTableDefinitions(CodeGenVTables &CGVT,
16341669
EmitFundamentalRTTIDescriptors(RD);
16351670

16361671
if (!VTable->isDeclarationForLinker())
1637-
CGM.EmitVTableTypeMetadata(VTable, VTLayout);
1672+
CGM.EmitVTableTypeMetadata(RD, VTable, VTLayout);
16381673
}
16391674

16401675
bool ItaniumCXXABI::isVirtualOffsetNeededForVTableField(

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5369,9 +5369,30 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
53695369
CmdArgs.push_back(Args.MakeArgString(TargetInfo.str()));
53705370
}
53715371

5372-
bool WholeProgramVTables =
5373-
Args.hasFlag(options::OPT_fwhole_program_vtables,
5374-
options::OPT_fno_whole_program_vtables, false);
5372+
bool VirtualFunctionElimination =
5373+
Args.hasFlag(options::OPT_fvirtual_function_elimination,
5374+
options::OPT_fno_virtual_function_elimination, false);
5375+
if (VirtualFunctionElimination) {
5376+
// VFE requires full LTO (currently, this might be relaxed to allow ThinLTO
5377+
// in the future).
5378+
if (D.getLTOMode() != LTOK_Full)
5379+
D.Diag(diag::err_drv_argument_only_allowed_with)
5380+
<< "-fvirtual-function-elimination"
5381+
<< "-flto=full";
5382+
5383+
CmdArgs.push_back("-fvirtual-function-elimination");
5384+
}
5385+
5386+
// VFE requires whole-program-vtables, and enables it by default.
5387+
bool WholeProgramVTables = Args.hasFlag(
5388+
options::OPT_fwhole_program_vtables,
5389+
options::OPT_fno_whole_program_vtables, VirtualFunctionElimination);
5390+
if (VirtualFunctionElimination && !WholeProgramVTables) {
5391+
D.Diag(diag::err_drv_argument_not_allowed_with)
5392+
<< "-fno-whole-program-vtables"
5393+
<< "-fvirtual-function-elimination";
5394+
}
5395+
53755396
if (WholeProgramVTables) {
53765397
if (!D.isUsingLTO())
53775398
D.Diag(diag::err_drv_argument_only_allowed_with)

clang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -758,6 +758,8 @@ static bool ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, InputKind IK,
758758
Opts.CodeViewGHash = Args.hasArg(OPT_gcodeview_ghash);
759759
Opts.MacroDebugInfo = Args.hasArg(OPT_debug_info_macro);
760760
Opts.WholeProgramVTables = Args.hasArg(OPT_fwhole_program_vtables);
761+
Opts.VirtualFunctionElimination =
762+
Args.hasArg(OPT_fvirtual_function_elimination);
761763
Opts.LTOVisibilityPublicStd = Args.hasArg(OPT_flto_visibility_public_std);
762764
Opts.SplitDwarfFile = Args.getLastArgValue(OPT_split_dwarf_file);
763765
Opts.SplitDwarfOutput = Args.getLastArgValue(OPT_split_dwarf_output);
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
// RUN: %clang_cc1 -flto -flto-unit -triple x86_64-unknown-linux -emit-llvm -fvirtual-function-elimination -fwhole-program-vtables -o - %s | FileCheck %s
2+
3+
4+
// Anonymous namespace.
5+
namespace {
6+
// CHECK: @_ZTVN12_GLOBAL__N_11AE = {{.*}} !vcall_visibility [[VIS_TU:![0-9]+]]
7+
struct A {
8+
A() {}
9+
virtual int f() { return 1; }
10+
};
11+
}
12+
void *construct_A() {
13+
return new A();
14+
}
15+
16+
17+
// Hidden visibility.
18+
// CHECK: @_ZTV1B = {{.*}} !vcall_visibility [[VIS_DSO:![0-9]+]]
19+
struct __attribute__((visibility("hidden"))) B {
20+
B() {}
21+
virtual int f() { return 1; }
22+
};
23+
B *construct_B() {
24+
return new B();
25+
}
26+
27+
28+
// Default visibility.
29+
// CHECK-NOT: @_ZTV1C = {{.*}} !vcall_visibility
30+
struct __attribute__((visibility("default"))) C {
31+
C() {}
32+
virtual int f() { return 1; }
33+
};
34+
C *construct_C() {
35+
return new C();
36+
}
37+
38+
39+
// Hidden visibility, public LTO visibility.
40+
// CHECK-NOT: @_ZTV1D = {{.*}} !vcall_visibility
41+
struct __attribute__((visibility("hidden"))) [[clang::lto_visibility_public]] D {
42+
D() {}
43+
virtual int f() { return 1; }
44+
};
45+
D *construct_D() {
46+
return new D();
47+
}
48+
49+
50+
// Hidden visibility, but inherits from class with default visibility.
51+
// CHECK-NOT: @_ZTV1E = {{.*}} !vcall_visibility
52+
struct __attribute__((visibility("hidden"))) E : C {
53+
E() {}
54+
virtual int f() { return 1; }
55+
};
56+
E *construct_E() {
57+
return new E();
58+
}
59+
60+
61+
// Anonymous namespace, but inherits from class with default visibility.
62+
// CHECK-NOT: @_ZTVN12_GLOBAL__N_11FE = {{.*}} !vcall_visibility
63+
namespace {
64+
struct __attribute__((visibility("hidden"))) F : C {
65+
F() {}
66+
virtual int f() { return 1; }
67+
};
68+
}
69+
void *construct_F() {
70+
return new F();
71+
}
72+
73+
74+
// Anonymous namespace, but inherits from class with hidden visibility.
75+
// CHECK: @_ZTVN12_GLOBAL__N_11GE = {{.*}} !vcall_visibility [[VIS_DSO:![0-9]+]]
76+
namespace {
77+
struct __attribute__((visibility("hidden"))) G : B {
78+
G() {}
79+
virtual int f() { return 1; }
80+
};
81+
}
82+
void *construct_G() {
83+
return new G();
84+
}
85+
86+
87+
// CHECK-DAG: [[VIS_DSO]] = !{i64 1}
88+
// CHECK-DAG: [[VIS_TU]] = !{i64 2}

0 commit comments

Comments
 (0)