Open
Description
Describe the bug
Erlc can sometimes crash with a back-trace like this:
Sub pass ssa_opt_type_continue
Function: '-f3/1-lc$^0/1-3-'/1
test362604.erl: internal error in pass beam_ssa_opt:
exception error: no function clause matching beam_types:join([])
in function beam_ssa_type:join_arg_types/3 (beam_ssa_type.erl, line 449)
in call from beam_ssa_type:opt_continue/4 (beam_ssa_type.erl, line 432)
in call from beam_ssa_opt:ssa_opt_type_continue/1 (beam_ssa_opt.erl, line 449)
in call from compile:run_sub_passes_1/3 (compile.erl, line 424)
in call from beam_ssa_opt:phase/4 (beam_ssa_opt.erl, line 116)
in call from beam_ssa_opt:fixpoint/6 (beam_ssa_opt.erl, line 99)
in call from beam_ssa_opt:run_phases/3 (beam_ssa_opt.erl, line 85)
To Reproduce
Unless the patch below is applied, the crash appears to be dependent on the phase of the moon :) With the patch applied, the reproducer (found with Erlfuzz, thanks @RobinMorisset ) triggers the error reliably.
diff --git a/lib/compiler/src/beam_ssa_type.erl b/lib/compiler/src/beam_ssa_type.erl
index d492ed4b50..9d8b965bd3 100644
--- a/lib/compiler/src/beam_ssa_type.erl
+++ b/lib/compiler/src/beam_ssa_type.erl
@@ -379,7 +379,7 @@ init_sig_st(StMap, FuncDb) ->
wl=wl_defer_list(Roots, wl_new()) }.
init_sig_roots(FuncDb) ->
- [Id || Id := #func_info{exported=true} <- FuncDb].
+ [Id || Id := #func_info{exported=true} <- maps:iterator(FuncDb, ordered)].
init_sig_args([Root | Roots], StMap, Acc) ->
#opt_st{args=Args0} = map_get(Root, StMap),
Affected versions
At least maint
(fe0571e)
Additional context
As far as I can tell, beam_ssa_type:signatures_1/2
can produce a different #sig_st{}
and FuncDb
depending on the order of the initial worklist in the #sig_st{}
. This, in turn, leads to number of list-comprehension functions being eliminated from optimization when the compilation succeeds, but kept around when the crash occurs.