aboutsummaryrefslogtreecommitdiff
path: root/lib/CodeGen/CodeGenModule.cpp
diff options
context:
space:
mode:
authorJohn McCall <rjmccall@apple.com>2010-10-29 22:22:43 +0000
committerJohn McCall <rjmccall@apple.com>2010-10-29 22:22:43 +0000
commit110e8e56af30363072c140285961592b0107f789 (patch)
treec8649da41998db0ac401c3e8872361feb6929fcf /lib/CodeGen/CodeGenModule.cpp
parentfa5fa97a1428e95540cbe95138e781a59bff7e39 (diff)
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
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());
}