Integrated: 8276836: Error in javac caused by switch expression without result expressions: Internal error: stack sim error
Jan Lahoda
jlahoda at openjdk.java.net
Tue May 31 11:08:47 UTC 2022
On Tue, 24 May 2022 12:47:44 GMT, Jan Lahoda <jlahoda at openjdk.org> wrote:
> Normally, a switch expression must yield a value. But, there are cases where the switch expression has a value in the javac frontend, but, due to optimizations, not when the code is generated. For example:
>
> int i = 1 + switch (0) { default -> {if (true) throw new RuntimeException(); else yield 0; } };
>
>
> javac will optimize the else section away, and the switch expression will always end abruptly. But, javac's simulated stack will still contain the left value of the binary operator, which will never be removed, and javac will consequently fail:
>
> .java:2: error: Internal error: stack sim error on t()
> private void t() {
> ^
> 1 error
>
>
> The proposed solution is twofold:
> - the throw statement/instruction should clear the stack, which adheres more closely to the runtime behavior of the instruction. This is the change in `Code`.
> - skipping code generation for expressions when the code is not "alive", as such code does not have any sense. This is similar to how statements are generated. This is the change in `Gen`.
This pull request has now been integrated.
Changeset: 7ef69935
Author: Jan Lahoda <jlahoda at openjdk.org>
URL: https://git.openjdk.java.net/jdk/commit/7ef6993576006d5fd09186870064d4dc1996e846
Stats: 219 lines in 3 files changed: 218 ins; 0 del; 1 mod
8276836: Error in javac caused by switch expression without result expressions: Internal error: stack sim error
Reviewed-by: vromero
-------------
PR: https://git.openjdk.java.net/jdk/pull/8867
More information about the compiler-dev
mailing list