From 110e8e56af30363072c140285961592b0107f789 Mon Sep 17 00:00:00 2001 From: John McCall Date: Fri, 29 Oct 2010 22:22:43 +0000 Subject: Restore r117644, this time properly ignoring -fvisibility and type visibility for namespace-scope variable declarations. Apply visibility in IR gen to variables that are merely declared and never defined. We were previously emitting these with default visibility unless they were declared with private_extern. Ignore global visibility settings when computing visibility for a declaration's context, and key several conditions on whether a visibility attribute exists anywhere in the hierarchy as opposed to whether it exists at the current level. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@117729 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CodeGenModule.cpp | 40 +++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 17 deletions(-) (limited to 'lib/CodeGen/CodeGenModule.cpp') diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp index efcdce70a0..558a8a3cf8 100644 --- a/lib/CodeGen/CodeGenModule.cpp +++ b/lib/CodeGen/CodeGenModule.cpp @@ -164,6 +164,17 @@ void CodeGenModule::ErrorUnsupported(const Decl *D, const char *Type, getDiags().Report(Context.getFullLoc(D->getLocation()), DiagID) << Msg; } +static llvm::GlobalValue::VisibilityTypes GetLLVMVisibility(Visibility V) { + switch (V) { + case DefaultVisibility: return llvm::GlobalValue::DefaultVisibility; + case HiddenVisibility: return llvm::GlobalValue::HiddenVisibility; + case ProtectedVisibility: return llvm::GlobalValue::ProtectedVisibility; + } + llvm_unreachable("unknown visibility!"); + return llvm::GlobalValue::DefaultVisibility; +} + + void CodeGenModule::setGlobalVisibility(llvm::GlobalValue *GV, const NamedDecl *D) const { // Internal definitions always have default visibility. @@ -172,15 +183,7 @@ void CodeGenModule::setGlobalVisibility(llvm::GlobalValue *GV, return; } - switch (D->getVisibility()) { - case DefaultVisibility: - return GV->setVisibility(llvm::GlobalValue::DefaultVisibility); - case HiddenVisibility: - return GV->setVisibility(llvm::GlobalValue::HiddenVisibility); - case ProtectedVisibility: - return GV->setVisibility(llvm::GlobalValue::ProtectedVisibility); - } - llvm_unreachable("unknown visibility!"); + GV->setVisibility(GetLLVMVisibility(D->getVisibility())); } /// Set the symbol visibility of type information (vtable and RTTI) @@ -934,15 +937,18 @@ CodeGenModule::GetOrCreateLLVMGlobal(llvm::StringRef MangledName, // handling. GV->setConstant(DeclIsConstantGlobal(Context, D)); - // FIXME: Merge with other attribute handling code. - if (D->getStorageClass() == SC_PrivateExtern) - GV->setVisibility(llvm::GlobalValue::HiddenVisibility); + // Set linkage and visibility in case we never see a definition. + std::pair LV = D->getLinkageAndVisibility(); + if (LV.first != ExternalLinkage) { + GV->setLinkage(llvm::GlobalValue::InternalLinkage); + } else { + if (D->hasAttr()) + GV->setLinkage(llvm::GlobalValue::DLLImportLinkage); + else if (D->hasAttr() || D->hasAttr()) + GV->setLinkage(llvm::GlobalValue::ExternalWeakLinkage); - if (D->hasAttr()) - GV->setLinkage(llvm::GlobalValue::DLLImportLinkage); - else if (D->hasAttr() || - D->hasAttr()) - GV->setLinkage(llvm::GlobalValue::ExternalWeakLinkage); + GV->setVisibility(GetLLVMVisibility(LV.second)); + } GV->setThreadLocal(D->isThreadSpecified()); } -- cgit v1.2.3-18-g5258