Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[erlc] internal error in pass beam_kernel_to_ssa #6572

Closed
RobinMorisset opened this issue Dec 17, 2022 · 2 comments · Fixed by #6575
Closed

[erlc] internal error in pass beam_kernel_to_ssa #6572

RobinMorisset opened this issue Dec 17, 2022 · 2 comments · Fixed by #6575
Assignees
Labels
bug Issue is reported as a bug team:VM Assigned to OTP team VM

Comments

@RobinMorisset
Copy link
Contributor

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.

@RobinMorisset RobinMorisset added the bug Issue is reported as a bug label Dec 17, 2022
@bjorng bjorng added the team:VM Assigned to OTP team VM label Dec 19, 2022
@bjorng bjorng self-assigned this Dec 19, 2022
bjorng added a commit to bjorng/otp that referenced this issue Dec 19, 2022
The `sys_core_fold` does a fixpoint iteration, limited to at most 20
iterations. One of the optimizations (coalescing two `let` constructs)
would temporarily generate unsafe code, which would eventually be
corrected, **unless** the 20 iteration limit was reached.

Closes erlang#6572
bjorng added a commit to bjorng/otp that referenced this issue Dec 19, 2022
The `sys_core_fold` does a fixpoint iteration, limited to at most 20
iterations. One of the optimizations (coalescing two `let` constructs)
would temporarily generate unsafe code, which would eventually be
corrected, **unless** the 20 iteration limit was reached.

Closes erlang#6572
@bjorng
Copy link
Contributor

bjorng commented Dec 19, 2022

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

@RobinMorisset
Copy link
Contributor Author

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

bjorng added a commit to bjorng/otp that referenced this issue Dec 19, 2022
…master/primary_preloaded

* bjorn/compiler/sys_core_fold/erlangGH-6572:
  Eliminate crash in beam_kernel_to_ssa
bjorng added a commit that referenced this issue Dec 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue is reported as a bug team:VM Assigned to OTP team VM
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants