diff options
Diffstat (limited to 'clang/lib')
-rw-r--r-- | clang/lib/CodeGen/CGDecl.cpp | 24 | ||||
-rw-r--r-- | clang/lib/CodeGen/CodeGenModule.cpp | 6 | ||||
-rw-r--r-- | clang/lib/CodeGen/CodeGenModule.h | 1 |
3 files changed, 27 insertions, 4 deletions
diff --git a/clang/lib/CodeGen/CGDecl.cpp b/clang/lib/CodeGen/CGDecl.cpp index 7fdd334e04c..cb157486463 100644 --- a/clang/lib/CodeGen/CGDecl.cpp +++ b/clang/lib/CodeGen/CGDecl.cpp @@ -129,9 +129,27 @@ void CodeGenFunction::EmitVarDecl(const VarDecl &D) { // uniqued. We can't do this in C, though, because there's no // standard way to agree on which variables are the same (i.e. // there's no mangling). - if (getLangOpts().CPlusPlus) - if (llvm::GlobalValue::isWeakForLinker(CurFn->getLinkage())) - Linkage = CurFn->getLinkage(); + if (getLangOpts().CPlusPlus) { + const Decl *D = CurCodeDecl; + while (true) { + if (isa<BlockDecl>(D)) { + // FIXME: Handle this case properly! (Should be similar to the + // way we handle lambdas in computeLVForDecl in Decl.cpp.) + break; + } else if (isa<CapturedDecl>(D)) { + D = cast<Decl>(cast<CapturedDecl>(D)->getParent()); + } else { + break; + } + } + // FIXME: Do we really only care about FunctionDecls here? + if (D && isa<FunctionDecl>(D)) { + llvm::GlobalValue::LinkageTypes ParentLinkage = + CGM.getFunctionLinkage(cast<FunctionDecl>(D)); + if (llvm::GlobalValue::isWeakForLinker(ParentLinkage)) + Linkage = ParentLinkage; + } + } return EmitStaticVarDecl(D, Linkage); } diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index f6218cddfb5..4865a9174c9 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -510,7 +510,11 @@ void CodeGenModule::EmitCtorList(const CtorList &Fns, const char *GlobalName) { llvm::GlobalValue::LinkageTypes CodeGenModule::getFunctionLinkage(GlobalDecl GD) { - const FunctionDecl *D = cast<FunctionDecl>(GD.getDecl()); + return getFunctionLinkage(cast<FunctionDecl>(GD.getDecl())); +} + +llvm::GlobalValue::LinkageTypes +CodeGenModule::getFunctionLinkage(const FunctionDecl *D) { GVALinkage Linkage = getContext().GetGVALinkageForFunction(D); if (Linkage == GVA_Internal) diff --git a/clang/lib/CodeGen/CodeGenModule.h b/clang/lib/CodeGen/CodeGenModule.h index ffb1243726e..6e5985d9bf1 100644 --- a/clang/lib/CodeGen/CodeGenModule.h +++ b/clang/lib/CodeGen/CodeGenModule.h @@ -925,6 +925,7 @@ public: void AddDependentLib(StringRef Lib); llvm::GlobalVariable::LinkageTypes getFunctionLinkage(GlobalDecl GD); + llvm::GlobalVariable::LinkageTypes getFunctionLinkage(const FunctionDecl *D); void setFunctionLinkage(GlobalDecl GD, llvm::GlobalValue *V) { V->setLinkage(getFunctionLinkage(GD)); |