Implement -femit-local-var-lifetime which adds local (stack) variable lifetime annotation to LLVM IR, which enables sharing stack space for variables whose lifetimes do not overlap.
Resolves issue #2227
This is not enabled by default yet, to prevent miscompilation due to bugs (should be enabled in future for optimization levels > 0, and when sanitizers are enabled).
Replace the stack of IRScopes, each with its own IRBuilder, by directly
tampering with the state of a single IRBuilder.
This seems like the most feasible way to account for a breaking change
in LLVM 11, disallowing IRBuilder from being copied.
Single intended functional change/fix: check ALL active catch blocks in
`isCatchingNonExceptions()`, not just the ones from the innermost
try-catch scope.
The catch bodies of a try-catch scope are now emitted in lexical order
(used to be reversed, last catch block first).
Invoke nothrow callees only in try-blocks with at least 1 catch-block,
otherwise call them directly.
Errors thrown by nothrow callees can thus still be caught inside a
try-catch-statement (and this is apparently required for release builds
too).
Most calls will be direct calls though, and this small change will lead
to substantially less IR as we then skip the clean-ups after an Error.
Proper clean-up when unwinding after an Error seems not to be guaranteed
anyway. There are apparent RAII front-end optimizations for structs with
nothrow dtor - see PR #1656.
Instead, put the mapping into the function-local codegen state,
where it belongs. As a side-effect of the refactoring, avoids
generating trivial "forwarding" BBs (see `nbb` in old code).
Avoids the issue from GitHub #1638 and similar altogether.
Previously, the transitory state only needed and valid during
generation of the LLVM IR for the function body was conflated
with the general codegen metadata for the function declaration
in IrFunction.
There is further potential for cleanup regarding the use of
gIR->func() and so on all over the code base, but this is out
of scope of this commit, which is only concerned with those
IrFunction members moved to FuncGenState.
GitHub: Fixes#1661.