summaryrefslogtreecommitdiffstats
path: root/clang/lib/CodeGen/CodeGenModule.cpp
diff options
context:
space:
mode:
authorFariborz Jahanian <fjahanian@apple.com>2010-10-27 16:21:54 +0000
committerFariborz Jahanian <fjahanian@apple.com>2010-10-27 16:21:54 +0000
commit1518a5eca74a85fe25516e7ddf4f35c2fc3e2e69 (patch)
tree2c3bfa40fc63177e96c142d051736ab9dbff54bf /clang/lib/CodeGen/CodeGenModule.cpp
parentcc1b168ef6745994b32b1fabb49a0f7962ae1646 (diff)
downloadbcm5719-llvm-1518a5eca74a85fe25516e7ddf4f35c2fc3e2e69.tar.gz
bcm5719-llvm-1518a5eca74a85fe25516e7ddf4f35c2fc3e2e69.zip
Do the guarding of instantiated static data members
on if its linkage is weak. Currently this is the case but may change in the future. (part of radar 8562966). llvm-svn: 117452
Diffstat (limited to 'clang/lib/CodeGen/CodeGenModule.cpp')
-rw-r--r--clang/lib/CodeGen/CodeGenModule.cpp47
1 files changed, 28 insertions, 19 deletions
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp
index d35965e2c4e..efcdce70a05 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -1154,42 +1154,51 @@ void CodeGenModule::EmitGlobalVarDefinition(const VarDecl *D) {
GV->setConstant(true);
GV->setAlignment(getContext().getDeclAlign(D).getQuantity());
-
+
// Set the llvm linkage type as appropriate.
+ llvm::GlobalValue::LinkageTypes Linkage =
+ GetLLVMLinkageVarDefinition(D, GV);
+ GV->setLinkage(Linkage);
+ if (Linkage == llvm::GlobalVariable::CommonLinkage)
+ // common vars aren't constant even if declared const.
+ GV->setConstant(false);
+
+ SetCommonAttributes(D, GV);
+
+ // Emit global variable debug information.
+ if (CGDebugInfo *DI = getDebugInfo()) {
+ DI->setLocation(D->getLocation());
+ DI->EmitGlobalVariable(GV, D);
+ }
+}
+
+llvm::GlobalValue::LinkageTypes
+CodeGenModule::GetLLVMLinkageVarDefinition(const VarDecl *D,
+ llvm::GlobalVariable *GV) {
GVALinkage Linkage = getContext().GetGVALinkageForVariable(D);
if (Linkage == GVA_Internal)
- GV->setLinkage(llvm::Function::InternalLinkage);
+ return llvm::Function::InternalLinkage;
else if (D->hasAttr<DLLImportAttr>())
- GV->setLinkage(llvm::Function::DLLImportLinkage);
+ return llvm::Function::DLLImportLinkage;
else if (D->hasAttr<DLLExportAttr>())
- GV->setLinkage(llvm::Function::DLLExportLinkage);
+ return llvm::Function::DLLExportLinkage;
else if (D->hasAttr<WeakAttr>()) {
if (GV->isConstant())
- GV->setLinkage(llvm::GlobalVariable::WeakODRLinkage);
+ return llvm::GlobalVariable::WeakODRLinkage;
else
- GV->setLinkage(llvm::GlobalVariable::WeakAnyLinkage);
+ return llvm::GlobalVariable::WeakAnyLinkage;
} else if (Linkage == GVA_TemplateInstantiation ||
Linkage == GVA_ExplicitTemplateInstantiation)
// FIXME: It seems like we can provide more specific linkage here
// (LinkOnceODR, WeakODR).
- GV->setLinkage(llvm::GlobalVariable::WeakAnyLinkage);
+ return llvm::GlobalVariable::WeakAnyLinkage;
else if (!getLangOptions().CPlusPlus && !CodeGenOpts.NoCommon &&
!D->hasExternalStorage() && !D->getInit() &&
!D->getAttr<SectionAttr>() && !D->isThreadSpecified()) {
// Thread local vars aren't considered common linkage.
- GV->setLinkage(llvm::GlobalVariable::CommonLinkage);
- // common vars aren't constant even if declared const.
- GV->setConstant(false);
- } else
- GV->setLinkage(llvm::GlobalVariable::ExternalLinkage);
-
- SetCommonAttributes(D, GV);
-
- // Emit global variable debug information.
- if (CGDebugInfo *DI = getDebugInfo()) {
- DI->setLocation(D->getLocation());
- DI->EmitGlobalVariable(GV, D);
+ return llvm::GlobalVariable::CommonLinkage;
}
+ return llvm::GlobalVariable::ExternalLinkage;
}
/// ReplaceUsesOfNonProtoTypeWithRealFunction - This function is called when we
OpenPOWER on IntegriCloud