summaryrefslogtreecommitdiff
path: root/lib/CodeGen/CodeGenModule.cpp
diff options
context:
space:
mode:
authorJohn McCall <rjmccall@apple.com>2010-10-29 07:49:41 +0000
committerJohn McCall <rjmccall@apple.com>2010-10-29 07:49:41 +0000
commit87a4ed905e2febe64021dcdfcdc7f00b27e92f32 (patch)
tree3fd087ba5308fab6b1ccdfb03a009f779c2b0bd6 /lib/CodeGen/CodeGenModule.cpp
parent4ba72a0b28135209c435630682febe1f854ccfa6 (diff)
downloadclang-87a4ed905e2febe64021dcdfcdc7f00b27e92f32.tar.gz
clang-87a4ed905e2febe64021dcdfcdc7f00b27e92f32.tar.bz2
clang-87a4ed905e2febe64021dcdfcdc7f00b27e92f32.tar.xz
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@117644 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CodeGenModule.cpp')
-rw-r--r--lib/CodeGen/CodeGenModule.cpp40
1 files changed, 23 insertions, 17 deletions
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<Linkage,Visibility> LV = D->getLinkageAndVisibility();
+ if (LV.first != ExternalLinkage) {
+ GV->setLinkage(llvm::GlobalValue::InternalLinkage);
+ } else {
+ if (D->hasAttr<DLLImportAttr>())
+ GV->setLinkage(llvm::GlobalValue::DLLImportLinkage);
+ else if (D->hasAttr<WeakAttr>() || D->hasAttr<WeakImportAttr>())
+ GV->setLinkage(llvm::GlobalValue::ExternalWeakLinkage);
- if (D->hasAttr<DLLImportAttr>())
- GV->setLinkage(llvm::GlobalValue::DLLImportLinkage);
- else if (D->hasAttr<WeakAttr>() ||
- D->hasAttr<WeakImportAttr>())
- GV->setLinkage(llvm::GlobalValue::ExternalWeakLinkage);
+ GV->setVisibility(GetLLVMVisibility(LV.second));
+ }
GV->setThreadLocal(D->isThreadSpecified());
}