erlang/otp

[erlc] internal error in pass beam_kernel_to_ssa

RobinMorisset opened this issue · 2 comments

On master (with and without cherry-picking #6559), the following testcase:

f(<<X>>) ->
    Y =
        case ok of
            X ->
                true = (ok > ((Y = _) = -1)),
                <<>> =
                    {f1(
                        <<
                            (ok - ok),
                            (bnot ok),
                            (f0() band ok),
                            (f0()),
                            (not ok),
                            (ok or f0()),
                            (f1(
                                f1(
                                    <<
                                        (f1(
                                            <<
                                                (f1(
                                                    <<0 || _ <- []>>
                                                ))
                                            >>
                                        ) * ok)
                                    >>
                                )
                            ))
                        >>
                    )}
        end.

f0() ->
    ok.

f1(_) ->
    ok.

causes the following erlc error:

Function: f/1
minimized/kernel_to_ssa.erl: internal error in pass beam_kernel_to_ssa:
exception error: no function clause matching beam_kernel_to_ssa:cg({k_return,[],[{k_var,[],41},{k_literal,[compiler_generated],-1}]},
 {cg,47,1,none,
     #{0 => {b_var,0},
       4 => {b_var,4},
       12 => {b_var,12},
       13 => {b_var,13},
       14 => {b_var,14},
       15 => {b_var,15},
       16 => {b_var,16},
       17 => {b_var,17},
       18 => {b_var,18},
       19 => {b_var,19},
       20 => {b_var,20},
       21 => {b_var,21},
       22 => {b_var,22},
       23 => {b_var,23},
       24 => {b_var,24},
       25 => {b_var,25},
       26 => {b_var,26},
       27 => {b_var,27},
       28 => {b_var,28},
       29 => {b_var,29},
       30 => {b_var,30},
       41 => {b_var,41},
       42 => {b_var,42},
       43 => {b_var,43},
       44 => {b_var,44},
       '@ssa_bool' => {b_var,{'@ssa_bool',45}},
       '@ssa_ret' => {b_var,'@ssa_ret'}},
     5,0,1,#{},false}) 
  in function  beam_kernel_to_ssa:cg/2 (beam_kernel_to_ssa.erl, line 114)
  in call from beam_kernel_to_ssa:guard_clause_cg/3 (beam_kernel_to_ssa.erl, line 563)
  in call from beam_kernel_to_ssa:match_cg/3 (beam_kernel_to_ssa.erl, line 177)
  in call from beam_kernel_to_ssa:do_match_cg/3 (beam_kernel_to_ssa.erl, line 167)
  in call from beam_kernel_to_ssa:select_bin_end/4 (beam_kernel_to_ssa.erl, line 437)
  in call from beam_kernel_to_ssa:select_bin_seg/4 (beam_kernel_to_ssa.erl, line 397)
  in call from beam_kernel_to_ssa:select_binary/5 (beam_kernel_to_ssa.erl, line 314)

I've been unable to minimize the testcase any further, all parts of it seem required to reproduce this bug.

The reason you could not minimize the test case is that the fixpoint iteration limit needed be reached for the bug to appear.

Thank you for the explanation (and for the fix!), I was surprised by the size of the testcase but it makes sense now.