]> granicus.if.org Git - clang/commit
Fix IRGen for referencing a static local before emitting its decl
authorReid Kleckner <reid@kleckner.net>
Wed, 8 Oct 2014 01:07:54 +0000 (01:07 +0000)
committerReid Kleckner <reid@kleckner.net>
Wed, 8 Oct 2014 01:07:54 +0000 (01:07 +0000)
commit2564ee299d8c48fb785f6786800ec584e355c251
tree8b2b7e21232df459e407d96849e56a705c33eb65
parent0b181741a9a86fb5717c34882862356ce040f121
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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@219265 91177308-0d34-0410-b5e6-96231b3b80d8
lib/CodeGen/CGDecl.cpp
lib/CodeGen/CGExpr.cpp
lib/CodeGen/CGExprConstant.cpp
lib/CodeGen/CodeGenFunction.h
lib/CodeGen/CodeGenModule.h
test/CodeGenCXX/static-local-in-local-class.cpp