[jdk17] RFR: 8269141: Switch statement containing pattern case label element gets in the loop during execution

Vicente Romero vromero at openjdk.java.net
Tue Jun 29 02:54:07 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.

lgtm

-------------

Marked as reviewed by vromero (Reviewer).

PR: https://git.openjdk.java.net/jdk17/pull/135


More information about the compiler-dev mailing list