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 splitting static local creation up into a getAddrOf phase and
a definition phase, as is done for other globals.
Fixes PR18020. See also previous attempts to fix static locals in
PR6769 and PR7101.