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.
This change includes checking of whether there is a default statement when using `case <variable>:` (LLVM IR switch instruction cannot be used), although that is currently not allowed in the D language. Therefore there is no testcase that covers that.
See GH issue #3375
* Extend the error message, closely following DMD. Tested by
fail_compilation/fail5634.d.
* Check across all compiled modules, not on a per-object-file basis.
That's what DMD does too.
* Apply the implicit `return 0` / void -> int return type promotion to
all D/C main functions, not just the first one. This prevents some
potential follow-up crashes.
This may negatively impact performance, as the (final, i.e.,
non-virtual) Expression::is... family is implemented in D and not
available inline in the C++ headers.
Not all type declarations yet (e.g., some TypeInfo subtypes are still
accessed directly), but those already wrapped as LazyType in the
gen/runtime.cpp module (with check and proper error msg in case object.d
doesn't contain a required declaration).
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).
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.
They were only ever used in ToIRVisitor[SwitchStatement] anyway,
so just use a local vector.
The code for emitting the string switch tables was moved and slightly
refactored, but should functionally still be the same.
Really looking forward to easily being able to zip together
two containers for iteration in C++.