summaryrefslogtreecommitdiffstats
path: root/clang/lib/CodeGen/CGExpr.cpp
diff options
context:
space:
mode:
authorReid Kleckner <reid@kleckner.net>2014-10-08 01:07:54 +0000
committerReid Kleckner <reid@kleckner.net>2014-10-08 01:07:54 +0000
commit453e0564673e85dc9b98e60e0e54f2e65d42d81b (patch)
tree4e5f1f501f3249a9288869cd76d5139a0f0ce28e /clang/lib/CodeGen/CGExpr.cpp
parent1256198bbcccc66632810d0d3df748af38351b0f (diff)
downloadbcm5719-llvm-453e0564673e85dc9b98e60e0e54f2e65d42d81b.tar.gz
bcm5719-llvm-453e0564673e85dc9b98e60e0e54f2e65d42d81b.zip
Fix IRGen for referencing a static local before emitting its decl
Summary: Previously CodeGen assumed that static locals were emitted before they could be accessed, which is true for automatic storage duration locals. However, it is possible to have CodeGen emit a nested function that uses a static local before emitting the function that defines the static local, breaking that assumption. Fix it by creating the static local upon access and ensuring that the deferred function body gets emitted. We may not be able to emit the initializer properly from outside the function body, so don't try. Fixes PR18020. See also previous attempts to fix static locals in PR6769 and PR7101. Reviewers: rsmith Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D4787 llvm-svn: 219265
Diffstat (limited to 'clang/lib/CodeGen/CGExpr.cpp')
-rw-r--r--clang/lib/CodeGen/CGExpr.cpp3
1 files changed, 2 insertions, 1 deletions
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index 717082a5934..518d81bd361 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -1941,7 +1941,8 @@ LValue CodeGenFunction::EmitDeclRefLValue(const DeclRefExpr *E) {
llvm::Value *V = LocalDeclMap.lookup(VD);
if (!V && VD->isStaticLocal())
- V = CGM.getStaticLocalDeclAddress(VD);
+ V = CGM.getOrCreateStaticVarDecl(
+ *VD, CGM.getLLVMLinkageVarDefinition(VD, /*isConstant=*/false));
// Use special handling for lambdas.
if (!V) {
OpenPOWER on IntegriCloud