From 907c828b080332854826a87451e838930f4be788 Mon Sep 17 00:00:00 2001 From: Anders Carlsson Date: Sat, 29 Jan 2011 22:10:32 +0000 Subject: [PATCH] When emitting RTTI for a non-class type, compute the visibility of the RTTI data based on the explicit visibility of the type. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@124553 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGRTTI.cpp | 25 +++++++++++++++---------- test/CodeGenCXX/rtti-linkage.cpp | 2 +- test/CodeGenCXX/rtti-visibility.cpp | 2 +- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/lib/CodeGen/CGRTTI.cpp b/lib/CodeGen/CGRTTI.cpp index b2129489bb..957b21893c 100644 --- a/lib/CodeGen/CGRTTI.cpp +++ b/lib/CodeGen/CGRTTI.cpp @@ -570,11 +570,7 @@ llvm::Constant *RTTIBuilder::BuildTypeInfo(QualType Ty, bool Force) { llvm::GlobalVariable *TypeName = GetAddrOfTypeName(Ty, Linkage); const llvm::Type *Int8PtrTy = llvm::Type::getInt8PtrTy(VMContext); - llvm::Constant *TypeNameAsInt8Ptr = - llvm::ConstantExpr::getBitCast(TypeName, Int8PtrTy); - - bool Hidden = DecideHidden(Ty); - Fields.push_back(TypeNameAsInt8Ptr); + Fields.push_back(llvm::ConstantExpr::getBitCast(TypeName, Int8PtrTy)); switch (Ty->getTypeClass()) { #define TYPE(Class, Base) @@ -677,12 +673,21 @@ llvm::Constant *RTTIBuilder::BuildTypeInfo(QualType Ty, bool Force) { CGM.setTypeVisibility(GV, RD, CodeGenModule::TVK_ForRTTI); CGM.setTypeVisibility(TypeName, RD, CodeGenModule::TVK_ForRTTIName); - - } else if (Hidden || - (CGM.getCodeGenOpts().HiddenWeakVTables && - Linkage == llvm::GlobalValue::LinkOnceODRLinkage)) { - GV->setVisibility(llvm::GlobalValue::HiddenVisibility); + } else { + Visibility TypeInfoVisibility = DefaultVisibility; + if (CGM.getCodeGenOpts().HiddenWeakVTables && + Linkage == llvm::GlobalValue::LinkOnceODRLinkage) + TypeInfoVisibility = HiddenVisibility; + + // The type name should have the same visibility as the type itself. + Visibility ExplicitVisibility = Ty->getVisibility(); + TypeName->setVisibility(CodeGenModule:: + GetLLVMVisibility(ExplicitVisibility)); + + TypeInfoVisibility = minVisibility(TypeInfoVisibility, Ty->getVisibility()); + GV->setVisibility(CodeGenModule::GetLLVMVisibility(TypeInfoVisibility)); } + GV->setUnnamedAddr(true); return llvm::ConstantExpr::getBitCast(GV, Int8PtrTy); diff --git a/test/CodeGenCXX/rtti-linkage.cpp b/test/CodeGenCXX/rtti-linkage.cpp index 6f73757039..42fe435234 100644 --- a/test/CodeGenCXX/rtti-linkage.cpp +++ b/test/CodeGenCXX/rtti-linkage.cpp @@ -4,7 +4,7 @@ #include // CHECK-WITH-HIDDEN: _ZTSFN12_GLOBAL__N_11DEvE = internal constant -// CHECK-WITH-HIDDEN: @_ZTSPK2T4 = linkonce_odr constant +// CHECK-WITH-HIDDEN: @_ZTSPK2T4 = linkonce_odr hidden constant // CHECK-WITH-HIDDEN: @_ZTS2T4 = linkonce_odr hidden constant // CHECK-WITH-HIDDEN: @_ZTI2T4 = linkonce_odr hidden unnamed_addr constant // CHECK-WITH-HIDDEN: @_ZTIPK2T4 = linkonce_odr hidden unnamed_addr constant diff --git a/test/CodeGenCXX/rtti-visibility.cpp b/test/CodeGenCXX/rtti-visibility.cpp index 249331dc42..4b3f6b2d1c 100644 --- a/test/CodeGenCXX/rtti-visibility.cpp +++ b/test/CodeGenCXX/rtti-visibility.cpp @@ -10,7 +10,7 @@ namespace Test1 { // A is explicitly marked hidden, so all RTTI data should also be marked hidden. // CHECK-TEST1: @_ZTSN5Test11AE = linkonce_odr hidden constant // CHECK-TEST1: @_ZTIN5Test11AE = linkonce_odr hidden unnamed_addr constant - // CHECK-TEST1: @_ZTSPN5Test11AE = linkonce_odr constant + // CHECK-TEST1: @_ZTSPN5Test11AE = linkonce_odr hidden constant // CHECK-TEST1: @_ZTIPN5Test11AE = linkonce_odr hidden unnamed_addr constant struct __attribute__((visibility("hidden"))) A { }; -- 2.40.0