Skip to content

Commit

Permalink
Merge pull request erlang#7285 from bjorng/bjorn/compiler/fix-beam_ss…
Browse files Browse the repository at this point in the history
…a_codegen-crash/erlangGH-7283

Eliminate crash in beam_ssa_codegen
  • Loading branch information
bjorng authored May 26, 2023
2 parents 718a323 + 91e0c5d commit 38fb8bf
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/compiler/src/beam_ssa_codegen.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1814,6 +1814,18 @@ cg_instr(bs_get_position, [Ctx], Dst, Set) ->
cg_instr(put_map, [{atom,assoc},SrcMap|Ss], Dst, Set) ->
Live = get_live(Set),
[{put_map_assoc,{f,0},SrcMap,Dst,Live,{list,Ss}}];
cg_instr(put_map, [{atom,exact},SrcBadMap|_Ss], _Dst, #cg_set{anno=Anno}=Set) ->
%% GH-7283: An exact `put_map` without a failure label was not
%% handled. The absence of the failure label can only mean that
%% the source is known not to be a valid map. (None of the current
%% optimization passes can figure out that the key is always
%% present in the map and that the operation therefore can never
%% fail.)
Live = get_live(Set),
[{test_heap,3,Live},
{put_tuple2,{x,0},{list,[{atom,badmap},SrcBadMap]}},
line(Anno),
{call_ext_last,1,{extfunc,erlang,error,1},1}];
cg_instr(is_nonempty_list, Ss, Dst, Set) ->
#cg_set{anno=#{was_bif_is_list := true}} = Set, %Assertion.

Expand Down
14 changes: 14 additions & 0 deletions lib/compiler/test/beam_ssa_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,10 @@ maps(_Config) ->

[] = maps_3(),

{'EXIT',{{badmap,true},_}} = catch maps_4(id(true), id(true)),
error = maps_4(id(#{}), id(true)),
error = maps_4(id(#{}), id(#{})),

ok.

maps_1(K) ->
Expand Down Expand Up @@ -535,6 +539,16 @@ maps_3() ->
[]
end -- [].

maps_4(A, B = A) when B; A ->
A#{ok := ok},
try A of
B -> B
after
ok
end#{ok := ok};
maps_4(_, _) ->
error.

-record(wx_ref, {type=any_type,ref=any_ref}).

cover_ssa_dead(_Config) ->
Expand Down

0 comments on commit 38fb8bf

Please sign in to comment.