Skip to content

Commit

Permalink
[clang codegen] Add dso_local/hidden/etc. markings to VTT declarations
Browse files Browse the repository at this point in the history
We were marking definitions, but not declarations. Marking declarations
makes computing the address more efficient.

Fixes issue reported at https://discourse.llvm.org/t/63090

Differential Revision: https://reviews.llvm.org/D128482
  • Loading branch information
efriedma-quic committed Jun 24, 2022
1 parent 5fa4629 commit e11bf8d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
4 changes: 1 addition & 3 deletions clang/lib/CodeGen/CGVTT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,6 @@ CodeGenVTables::EmitVTTDefinition(llvm::GlobalVariable *VTT,

if (CGM.supportsCOMDAT() && VTT->isWeakForLinker())
VTT->setComdat(CGM.getModule().getOrInsertComdat(VTT->getName()));

// Set the right visibility.
CGM.setGVProperties(VTT, RD);
}

llvm::GlobalVariable *CodeGenVTables::GetAddrOfVTT(const CXXRecordDecl *RD) {
Expand All @@ -122,6 +119,7 @@ llvm::GlobalVariable *CodeGenVTables::GetAddrOfVTT(const CXXRecordDecl *RD) {
llvm::GlobalVariable *GV = CGM.CreateOrReplaceCXXRuntimeVariable(
Name, ArrayType, llvm::GlobalValue::ExternalLinkage, Align);
GV->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
CGM.setGVProperties(GV, RD);
return GV;
}

Expand Down
15 changes: 15 additions & 0 deletions clang/test/CodeGenCXX/visibility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ namespace test48 {
// CHECK-HIDDEN: @_ZN6Test143varE = external global
// CHECK: @_ZN6Test154TempINS_1AEE5Inner6bufferE = external global [0 x i8]
// CHECK-HIDDEN: @_ZN6Test154TempINS_1AEE5Inner6bufferE = external global [0 x i8]
// CHECK: @_ZTVN6test701BE = external hidden unnamed_addr constant { [5 x ptr] }, align 8
// CHECK: @_ZTTN6test701BE = external hidden unnamed_addr constant [2 x ptr], align 8

namespace test27 {
template<typename T>
Expand Down Expand Up @@ -1317,3 +1319,16 @@ namespace test69 {
// CHECK-LABEL: define void @_ZN6test693foo1fEv
// CHECK-HIDDEN-LABEL: define hidden void @_ZN6test693foo1fEv
}

namespace test70 {
// Make sure both the vtable and VTT declarations are marked "hidden"
class HIDDEN A {
virtual void a();
};
class HIDDEN B : virtual A {
void a() override;
~B();
};
B::~B() {}
// Check lines at top of file.
}

0 comments on commit e11bf8d

Please sign in to comment.