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: http://llvm.org/svn/llvm-project/cfe/trunk@219265 91177308-0d34-0410-b5e6-96231b3b80d8
Fix test case in no asserts build

git-svn-id: http://llvm.org/svn/llvm-project/cfe/trunk@219266 91177308-0d34-0410-b5e6-96231b3b80d8