From 354e712c81fbb07c0ce5f06180788b25fffa1b56 Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Wed, 27 Oct 2010 16:21:54 +0000 Subject: 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). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@117452 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CodeGenModule.cpp | 47 ++++++++++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 19 deletions(-) (limited to 'lib/CodeGen/CodeGenModule.cpp') diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp index d35965e2c4..efcdce70a0 100644 --- a/lib/CodeGen/CodeGenModule.cpp +++ b/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()) - GV->setLinkage(llvm::Function::DLLImportLinkage); + return llvm::Function::DLLImportLinkage; else if (D->hasAttr()) - GV->setLinkage(llvm::Function::DLLExportLinkage); + return llvm::Function::DLLExportLinkage; else if (D->hasAttr()) { 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() && !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 -- cgit v1.2.3-70-g09d2