RFR: 8301858: Verification error when compiling switch with record patterns [v3]

Aggelos Biboudis abimpoudis at openjdk.org
Wed Feb 8 15:00:53 UTC 2023


On Wed, 8 Feb 2023 14:29:10 GMT, Aggelos Biboudis <abimpoudis at openjdk.org> wrote:

>> When unrolling/translating record patterns with an unconditional case, we were translating the last/innermost case to`case null, default` skipping the initialization of a bound variable `o` in the example below:
>> 
>>     switch (..) {
>>       case R1(Object o):
>>                       return meth_O(o); 
>>     }
>>     => 
>>     switch (..) {
>>        case R1: 
>>           switch(..) {
>>             case null, default:
>>                             return meth_O(o);
>>           }
>>     }
>> 
>> This PR addresses that by emitting the correct label instead of default.
>
> Aggelos Biboudis has refreshed the contents of this pull request, and previous commits have been removed. The incremental views will show differences compared to the previous content of the PR. The pull request contains one new commit since the last revision:
> 
>   Fix unrolling with cases that have null and unconditional
>   
>   Co-authored-by: Jan Lahoda <jan.lahoda at oracle.com>

So the minimization of the failing test was this:

    private String test(P p) {
        return switch (p) {
            case P(R(A a1, A b1), R(A a2, A b2)) -> "";
            case P(R(A a1, A b1), R(A a2, B b2)) -> "";
            case P(R(A a1, A b1), R(B a2, A b2)) -> "";
            case P(R(A a1, A b1), R(B a2, B b2)) -> "";
            case P(R(A a1, B b1), R(A a2, A b2)) -> "";
            case P(R(A a1, B b1), R(A a2, B b2)) -> "";
            case P(N a, N b) -> "other";
        };
    }
    
During the desugaring of this switch, the emission of the last case was not using the right binding. The local variable `a` was emitted for the necessary `null` check but we were not using the correct one. As a result, this was crashing the backend.

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

PR: https://git.openjdk.org/jdk/pull/12438


More information about the compiler-dev mailing list