[jdk17] Integrated: 8269141: Switch statement containing pattern case label element gets in the loop during execution
Jan Lahoda
jlahoda at openjdk.java.net
Wed Jun 30 08:48:06 UTC 2021
On Thu, 24 Jun 2021 10:50:16 GMT, Jan Lahoda <jlahoda at openjdk.org> wrote:
> Guards in the pattern matching switches are implemented internally through `continue` in switches (which cannot be written in the source, but can be used internally). Consider code:
>
> switch (...) {
> case String s && s.isEmpty(): break;
> default: //fall through outside the switch
> }
>
> The current implementation in Gen will: `code.resolve(switchEnv.info.cont);` which puts (merges) the code paths for the `continue`s to `pendingJumps`. The `code.branch(goto_)` in `code.resolve(code.branch(goto_), switchStart)` will merge the `pendingJumps` (i.e. the continues) with the execution as it falls through the default case of the switch, and the `code.resolve` will jump for all the merged code paths to the beginning of the switch. This is wrong - we should only jump to the beginning of the switch for the `continue` code paths, not for the final fall-through code path. This is what the fix is trying to do.
This pull request has now been integrated.
Changeset: c3c91892
Author: Jan Lahoda <jlahoda at openjdk.org>
URL: https://git.openjdk.java.net/jdk17/commit/c3c918928cab49d970ddf74d53db1e57e91dc30c
Stats: 34 lines in 2 files changed: 31 ins; 1 del; 2 mod
8269141: Switch statement containing pattern case label element gets in the loop during execution
Reviewed-by: vromero
-------------
PR: https://git.openjdk.java.net/jdk17/pull/135
More information about the compiler-dev
mailing list