From: Rafael Espindola Date: Wed, 14 Mar 2018 18:14:46 +0000 (+0000) Subject: Set dso_local on external rtti GVs. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ac11dcec21c6ff3761acdcf844e1cd6f377169ee;p=clang Set dso_local on external rtti GVs. In this particular case it would be possible to just add an else with CGM.setDSOLocal(GV), but it seems better to have as many callers as possible just call setGVProperties so that we can centralize the logic there. This patch then makes setGVProperties able to handle null Decls. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@327543 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp index de3810554f..e75780a0a9 100644 --- a/lib/CodeGen/CodeGenModule.cpp +++ b/lib/CodeGen/CodeGenModule.cpp @@ -707,7 +707,8 @@ void CodeGenModule::setGlobalVisibility(llvm::GlobalValue *GV, GV->setVisibility(llvm::GlobalValue::DefaultVisibility); return; } - + if (!D) + return; // Set visibility for definitions. LinkageInfo LV = D->getLinkageAndVisibility(); if (LV.isVisibilityExplicit() || !GV->isDeclarationForLinker()) @@ -797,7 +798,7 @@ void CodeGenModule::setDLLImportDLLExport(llvm::GlobalValue *GV, void CodeGenModule::setDLLImportDLLExport(llvm::GlobalValue *GV, const NamedDecl *D) const { - if (D->isExternallyVisible()) { + if (D && D->isExternallyVisible()) { if (D->hasAttr()) GV->setDLLStorageClass(llvm::GlobalVariable::DLLImportStorageClass); else if (D->hasAttr() && !GV->isDeclarationForLinker()) diff --git a/lib/CodeGen/ItaniumCXXABI.cpp b/lib/CodeGen/ItaniumCXXABI.cpp index 21223ea23d..3862b58a49 100644 --- a/lib/CodeGen/ItaniumCXXABI.cpp +++ b/lib/CodeGen/ItaniumCXXABI.cpp @@ -2616,10 +2616,8 @@ ItaniumRTTIBuilder::GetAddrOfExternalRTTIDescriptor(QualType Ty) { /*Constant=*/true, llvm::GlobalValue::ExternalLinkage, nullptr, Name); - if (const RecordType *RecordTy = dyn_cast(Ty)) { - const CXXRecordDecl *RD = cast(RecordTy->getDecl()); - CGM.setGVProperties(GV, RD); - } + const CXXRecordDecl *RD = Ty->getAsCXXRecordDecl(); + CGM.setGVProperties(GV, RD); } return llvm::ConstantExpr::getBitCast(GV, CGM.Int8PtrTy); diff --git a/test/CodeGenCXX/windows-itanium-exceptions.cpp b/test/CodeGenCXX/windows-itanium-exceptions.cpp index b2c8707efc..1bca4e8917 100644 --- a/test/CodeGenCXX/windows-itanium-exceptions.cpp +++ b/test/CodeGenCXX/windows-itanium-exceptions.cpp @@ -10,7 +10,7 @@ void attempt() { try { except(); } catch (...) { } } -// CHECK: @_ZTIi = external constant i8* +// CHECK: @_ZTIi = external dso_local constant i8* // CHECK: define {{.*}}void @_Z6exceptv() {{.*}} { // CHECK: %exception = call {{.*}}i8* @__cxa_allocate_exception(i32 4)