diff options
author | John McCall <rjmccall@apple.com> | 2010-05-25 04:30:21 +0000 |
---|---|---|
committer | John McCall <rjmccall@apple.com> | 2010-05-25 04:30:21 +0000 |
commit | 7cb0220e535958756f0c36788b370aebc07aea1f (patch) | |
tree | 9ded153a937343d25326b31eee351dff293d63bf /clang/lib/CodeGen/CGDecl.cpp | |
parent | 26fdebcae9321029dd0a474f2f38d669eebe1133 (diff) | |
download | bcm5719-llvm-7cb0220e535958756f0c36788b370aebc07aea1f.tar.gz bcm5719-llvm-7cb0220e535958756f0c36788b370aebc07aea1f.zip |
If a function definition has any sort of weak linkage, its static local
variables should have that linkage. Otherwise, its static local
variables should have internal linkage. To avoid computing this excessively,
set a function's linkage before we emit code for it.
Previously we were assigning weak linkage to the static variables of
static inline functions in C++, with predictably terrible results. This
fixes that and also gives better linkage than 'weak' when merging is required.
llvm-svn: 104581
Diffstat (limited to 'clang/lib/CodeGen/CGDecl.cpp')
-rw-r--r-- | clang/lib/CodeGen/CGDecl.cpp | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/clang/lib/CodeGen/CGDecl.cpp b/clang/lib/CodeGen/CGDecl.cpp index 611ebed5a3d..8115e384db8 100644 --- a/clang/lib/CodeGen/CGDecl.cpp +++ b/clang/lib/CodeGen/CGDecl.cpp @@ -114,14 +114,14 @@ void CodeGenFunction::EmitBlockVarDecl(const VarDecl &D) { llvm::GlobalValue::LinkageTypes Linkage = llvm::GlobalValue::InternalLinkage; - // If this is a static declaration inside an inline function, it must have - // weak linkage so that the linker will merge multiple definitions of it. - if (getContext().getLangOptions().CPlusPlus) { - if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(CurFuncDecl)) { - if (FD->isInlined()) - Linkage = llvm::GlobalValue::WeakAnyLinkage; - } - } + // If the function definition has some sort of weak linkage, its + // static variables should also be weak so that they get properly + // 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 (getContext().getLangOptions().CPlusPlus) + if (llvm::GlobalValue::isWeakForLinker(CurFn->getLinkage())) + Linkage = CurFn->getLinkage(); return EmitStaticBlockVarDecl(D, Linkage); } |