otp icon indicating copy to clipboard operation
otp copied to clipboard

[erlc] internal error in pass beam_ssa_opt

Open giacomocavalieri opened this issue 7 months ago • 2 comments

Describe the bug erlc crashes when ran on this module:

-module(prova).

-export([test/2]).
-export_type([continue/2, option/1]).

-type continue(S, C) :: {stop, S} | {continue, C}.
-type option(V) :: {some, V} | none.

-spec test(fun((integer()) -> option(integer())), integer()) -> integer().
test(Next, Prev) ->
    Decision = case Next(Prev) of
        none -> {stop, none};
        {some, N} -> {continue, {some, N}}
    end,
    Acc = case Decision of
        {stop, {some, X}} -> X;
        {continue, {some, X}} -> X;
        _ -> 1
    end,
    case Decision of
        {continue, {some, New}} -> New;
        _ -> Acc
    end.

Producing the following error message:

Function: test/2
Sub pass ssa_opt_type_continue
Function: test/2
prova.erl: internal error in pass beam_ssa_opt:
exception error: no match of right hand side value any
  in function  beam_ssa_type:simplify/2 (beam_ssa_type.erl, line 1305)
  in call from beam_ssa_type:simplify/5 (beam_ssa_type.erl, line 1089)
  in call from beam_ssa_type:opt_is/8 (beam_ssa_type.erl, line 582)
  in call from beam_ssa_type:opt_bs/8 (beam_ssa_type.erl, line 524)
  in call from beam_ssa_type:do_opt_function/6 (beam_ssa_type.erl, line 502)
  in call from beam_ssa_type:opt_function/6 (beam_ssa_type.erl, line 475)
  in call from beam_ssa_opt:ssa_opt_type_continue/1 (beam_ssa_opt.erl, line 439)
  in call from compile:run_sub_passes_1/3 (compile.erl, line 1212)

Affected versions I've tested this with Erlang/OTP 27 [erts-15.2.7]

giacomocavalieri avatar May 18 '25 09:05 giacomocavalieri

Thanks for reporting! This appears related to https://github.com/erlang/otp/issues/6599, and we're still working on that.

jhogberg avatar May 28 '25 12:05 jhogberg

For anyone confused, #6599 is closed because the parts which have not been fixed yet (including apparently this bug) were moved to #7342

RobinMorisset avatar Jun 13 '25 17:06 RobinMorisset