Skip to content

Commit

Permalink
Merge pull request #6431 from bjorng/bjorn/compiler/ssa_opt_bsm_short…
Browse files Browse the repository at this point in the history
…cut/GH-6426/OTP-18308

compiler: Eliminate internal error in sub pass ssa_opt_bsm_shortcut
  • Loading branch information
bjorng authored Nov 7, 2022
2 parents 0ef2b5d + 71136a9 commit 69a84e1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/compiler/src/beam_ssa_opt.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1766,14 +1766,15 @@ coalesce_skips_is([#b_set{op=bs_match,
args=[#b_literal{val=skip},
Ctx0,Type,Flags,
#b_literal{val=Size0},
#b_literal{val=Unit0}]}=Skip0,
#b_literal{val=Unit0}],
dst=Ctx}=Skip0,
#b_set{op={succeeded,guard}}],
#b_br{succ=L2,fail=Fail}=Br0,
Bs0) when is_integer(Size0) ->
case Bs0 of
[{L2,#b_blk{is=[#b_set{op=bs_match,
dst=SkipDst,
args=[#b_literal{val=skip},_,_,_,
args=[#b_literal{val=skip},Ctx,_,_,
#b_literal{val=Size1},
#b_literal{val=Unit1}]},
#b_set{op={succeeded,guard}}=Succeeded],
Expand All @@ -1787,7 +1788,7 @@ coalesce_skips_is([#b_set{op=bs_match,
Is = [Skip,Succeeded],
{Is,Br,Bs};
[{L2,#b_blk{is=[#b_set{op=bs_test_tail,
args=[_Ctx,#b_literal{val=TailSkip}]}],
args=[Ctx,#b_literal{val=TailSkip}]}],
last=#b_br{succ=NextSucc,fail=Fail}}}|Bs] ->
SkipBits = Size0 * Unit0,
TestTail = Skip0#b_set{op=bs_test_tail,
Expand Down
9 changes: 9 additions & 0 deletions lib/compiler/test/bs_match_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -2448,6 +2448,11 @@ empty_matches(Config) when is_list(Config) ->
<<Zero:0/unit:1>> = id(<<>>),
0 = id(Zero),

ok = em_4(<<>>, <<>>),
{'EXIT',{function_clause,[_|_]}} = catch em_4(<<>>, <<0:1>>),
{'EXIT',{function_clause,[_|_]}} = catch em_4(<<0:1>>, <<>>),
{'EXIT',{function_clause,[_|_]}} = catch em_4(<<0:1>>, <<0:1>>),

ok.

em_1(Bytes) ->
Expand All @@ -2471,6 +2476,10 @@ em_3(<<V:0/binary,Rest/bits>>) ->

em_3_1(I) -> I.

%% GH-6426/OTP-xxxxx
em_4(<<X:0, _:X>>, <<Y:0, _:Y>>) ->
ok.

%% beam_trim would sometimes crash when bs_start_match4 had {atom,resume} as
%% its fail label.
trim_bs_start_match_resume(Config) when is_list(Config) ->
Expand Down

0 comments on commit 69a84e1

Please sign in to comment.