Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix miscompilation of guard with or #7378

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/compiler/src/beam_ssa_bool.erl
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,10 @@ pre_opt_is([#b_set{op={succeeded,_},dst=Dst,args=Args0}=I0|Is],
Sub = Sub0#{Dst=>#b_literal{val=true}},
pre_opt_is(Is, Reached, Sub, Acc);
false ->
pre_opt_is(Is, Reached, Sub0, [I|Acc])
%% Don't remember boolean expressions that can potentially fail,
%% because that can cause unsafe optimizations.
Sub = maps:remove(Arg, Sub0),
pre_opt_is(Is, Reached, Sub, [I|Acc])
end;
pre_opt_is([#b_set{dst=Dst,args=Args0}=I0|Is], Reached, Sub0, Acc) ->
Args = sub_args(Args0, Sub0),
Expand Down
11 changes: 11 additions & 0 deletions lib/compiler/test/guard_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -2619,6 +2619,7 @@ beam_bool_SUITE(_Config) ->
gh_6164(),
gh_6184(),
gh_7339(),
gh_7370(),
ok.

before_and_inside_if() ->
Expand Down Expand Up @@ -3177,6 +3178,16 @@ do_gh_7339(M) when is_number(M) or (not is_map(M#{a => b})) ->
do_gh_7339(_) ->
b.

gh_7370() ->
b = gh_7370(id(42)),
b = gh_7370(id(42.0)),
ok.

gh_7370(A) when (not (not is_float(A))) =/= ((ok and ok) or true) ->
a;
gh_7370(_) ->
b.

%%%
%%% End of beam_bool_SUITE tests.
%%%
Expand Down