summaryrefslogtreecommitdiff
path: root/lib/CodeGen/CGDecl.cpp
diff options
context:
space:
mode:
authorEli Friedman <eli.friedman@gmail.com>2013-06-13 21:50:44 +0000
committerEli Friedman <eli.friedman@gmail.com>2013-06-13 21:50:44 +0000
commit678eca456bc62900dc7407bdbc9fa282da9d2f8f (patch)
tree2da495e0f72080966f6bab138e6f183e2e116238 /lib/CodeGen/CGDecl.cpp
parentaa12d8f06e641ee9f047b89efc28cecf9498ac05 (diff)
downloadclang-678eca456bc62900dc7407bdbc9fa282da9d2f8f.tar.gz
clang-678eca456bc62900dc7407bdbc9fa282da9d2f8f.tar.bz2
clang-678eca456bc62900dc7407bdbc9fa282da9d2f8f.tar.xz
Fix the linkage of static locals inside a CapturedStmt. (Found in the
process of trying to fix the related issue for block literals.) git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@183951 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CGDecl.cpp')
-rw-r--r--lib/CodeGen/CGDecl.cpp24
1 files changed, 21 insertions, 3 deletions
diff --git a/lib/CodeGen/CGDecl.cpp b/lib/CodeGen/CGDecl.cpp
index 7fdd334e04..cb15748646 100644
--- a/lib/CodeGen/CGDecl.cpp
+++ b/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);
}