Skip to content

Commit

Permalink
Don't break bs_match sequences by mixing registers (again)
Browse files Browse the repository at this point in the history
See erlang#6623 for a fix to a similar bug reported in erlang#6613.

Closes erlang#6755
  • Loading branch information
bjorng authored and josevalim committed Jan 30, 2023
1 parent 9a4ac73 commit f3e0f6b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/compiler/src/beam_ssa_codegen.erl
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,8 @@ prefer_xregs_is([#cg_set{op=Op}=I|Is], St, Copies0, Acc)
when Op =:= bs_checked_get;
Op =:= bs_checked_skip;
Op =:= bs_checked_get_tail;
Op =:= bs_ensure ->
Op =:= bs_ensure;
Op =:= bs_match_string ->
Copies = prefer_xregs_prune(I, Copies0, St),
prefer_xregs_is(Is, St, Copies, [I|Acc]);
prefer_xregs_is([#cg_set{args=Args0}=I0|Is], St, Copies0, Acc) ->
Expand Down
14 changes: 14 additions & 0 deletions lib/compiler/test/bs_match_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -2690,6 +2690,8 @@ bs_match(_Config) ->
<<"abc">> = do_bs_match_gh_6660(id(<<"abc">>)),
{'EXIT', {{try_clause,abc},_}} = catch do_bs_match_gh_6660(id(abc)),

{'EXIT',{{case_clause,_},_}} = catch do_bs_match_gh_6755(id(<<"1000">>)),

ok.

do_bs_match_1(_, X) ->
Expand Down Expand Up @@ -2749,6 +2751,18 @@ do_bs_match_gh_6660(X) ->
ok
end.

do_bs_match_gh_6755(B) ->
C = case B of
<<"1000">> -> test;
<<"1001">> -> test2
end,

_ = atom_to_list(C),

case B of
<<"b">> -> b
end.

%% GH-6348/OTP-18297: Allow aliases for binaries.
-record(ba_foo, {a,b,c}).

Expand Down

0 comments on commit f3e0f6b

Please sign in to comment.