Index: lib/CodeGen/ItaniumCXXABI.cpp =================================================================== --- lib/CodeGen/ItaniumCXXABI.cpp +++ lib/CodeGen/ItaniumCXXABI.cpp @@ -31,6 +31,7 @@ #include "clang/AST/StmtCXX.h" #include "llvm/IR/CallSite.h" #include "llvm/IR/DataLayout.h" +#include "llvm/IR/GlobalValue.h" #include "llvm/IR/Instructions.h" #include "llvm/IR/Intrinsics.h" #include "llvm/IR/Value.h" @@ -40,6 +41,11 @@ using namespace CodeGen; namespace { +struct TypeInfoOptions { + bool DLLExport; + llvm::GlobalValue::VisibilityTypes Visibility; +}; + class ItaniumCXXABI : public CodeGen::CGCXXABI { /// VTables - All the vtables which have been defined. llvm::DenseMap VTables; @@ -181,8 +187,9 @@ emitTerminateForUnexpectedException(CodeGenFunction &CGF, llvm::Value *Exn) override; - void EmitFundamentalRTTIDescriptor(QualType Type, bool DLLExport); - void EmitFundamentalRTTIDescriptors(bool DLLExport); + void EmitFundamentalRTTIDescriptor(QualType Type, + const TypeInfoOptions *Options); + void EmitFundamentalRTTIDescriptors(const TypeInfoOptions *Options); llvm::Constant *getAddrOfRTTIDescriptor(QualType Ty) override; CatchTypeInfo getAddrOfCXXCatchHandlerType(QualType Ty, @@ -1612,8 +1619,21 @@ RD->getIdentifier()->isStr("__fundamental_type_info") && isa(DC) && cast(DC)->getIdentifier() && cast(DC)->getIdentifier()->isStr("__cxxabiv1") && - DC->getParent()->isTranslationUnit()) - EmitFundamentalRTTIDescriptors(RD->hasAttr()); + DC->getParent()->isTranslationUnit()) { + TypeInfoOptions options; + options.DLLExport = RD->hasAttr(); + switch(RD->getVisibility()) { + case HiddenVisibility: + options.Visibility = llvm::GlobalValue::HiddenVisibility; + break; + case ProtectedVisibility: + options.Visibility = llvm::GlobalValue::ProtectedVisibility; + break; + default: + options.Visibility = llvm::GlobalValue::DefaultVisibility; + } + EmitFundamentalRTTIDescriptors(&options); + } if (!VTable->isDeclarationForLinker()) CGM.EmitVTableTypeMetadata(VTable, VTLayout); @@ -2701,9 +2721,10 @@ /// BuildTypeInfo - Build the RTTI type info struct for the given type. /// /// \param Force - true to force the creation of this RTTI value - /// \param DLLExport - true to mark the RTTI value as DLLExport - llvm::Constant *BuildTypeInfo(QualType Ty, bool Force = false, - bool DLLExport = false); + /// \param Options - options for the generated type info + llvm::Constant *BuildTypeInfo(QualType Ty, + bool Force = false, + const TypeInfoOptions *Options = nullptr); }; } @@ -3172,8 +3193,8 @@ llvm_unreachable("Invalid linkage!"); } -llvm::Constant *ItaniumRTTIBuilder::BuildTypeInfo(QualType Ty, bool Force, - bool DLLExport) { +llvm::Constant *ItaniumRTTIBuilder::BuildTypeInfo( + QualType Ty, bool Force, const TypeInfoOptions *Options) { // We want to operate on the canonical type. Ty = Ty.getCanonicalType(); @@ -3358,6 +3379,9 @@ else llvmVisibility = CodeGenModule::GetLLVMVisibility(Ty->getVisibility()); + if (Options) + llvmVisibility = Options->Visibility; + TypeName->setVisibility(llvmVisibility); CGM.setDSOLocal(TypeName); @@ -3366,7 +3390,8 @@ if (CGM.getTriple().isWindowsItaniumEnvironment()) { auto RD = Ty->getAsCXXRecordDecl(); - if (DLLExport || (RD && RD->hasAttr())) { + if ((Options && Options->DLLExport) || + (RD && RD->hasAttr())) { TypeName->setDLLStorageClass(llvm::GlobalValue::DLLExportStorageClass); GV->setDLLStorageClass(llvm::GlobalValue::DLLExportStorageClass); } else if (RD && RD->hasAttr() && @@ -3655,18 +3680,18 @@ return ItaniumRTTIBuilder(*this).BuildTypeInfo(Ty); } -void ItaniumCXXABI::EmitFundamentalRTTIDescriptor(QualType Type, - bool DLLExport) { +void ItaniumCXXABI::EmitFundamentalRTTIDescriptor( + QualType Type, const TypeInfoOptions *Options) { QualType PointerType = getContext().getPointerType(Type); QualType PointerTypeConst = getContext().getPointerType(Type.withConst()); - ItaniumRTTIBuilder(*this).BuildTypeInfo(Type, /*Force=*/true, DLLExport); - ItaniumRTTIBuilder(*this).BuildTypeInfo(PointerType, /*Force=*/true, - DLLExport); + ItaniumRTTIBuilder(*this).BuildTypeInfo(Type, /*Force=*/true, Options); + ItaniumRTTIBuilder(*this).BuildTypeInfo(PointerType, /*Force=*/true, Options); ItaniumRTTIBuilder(*this).BuildTypeInfo(PointerTypeConst, /*Force=*/true, - DLLExport); + Options); } -void ItaniumCXXABI::EmitFundamentalRTTIDescriptors(bool DLLExport) { +void ItaniumCXXABI::EmitFundamentalRTTIDescriptors( + const TypeInfoOptions* Options) { // Types added here must also be added to TypeInfoIsInStandardLibrary. QualType FundamentalTypes[] = { getContext().VoidTy, getContext().NullPtrTy, @@ -3684,7 +3709,7 @@ getContext().Char32Ty }; for (const QualType &FundamentalType : FundamentalTypes) - EmitFundamentalRTTIDescriptor(FundamentalType, DLLExport); + EmitFundamentalRTTIDescriptor(FundamentalType, Options); } /// What sort of uniqueness rules should we use for the RTTI for the