Skip to content

Commit

Permalink
Merge branch 'bjorn/compiler/beam_ssa_bool-miscompilation/GH-7370/OTP…
Browse files Browse the repository at this point in the history
…-18634' into maint-26

* bjorn/compiler/beam_ssa_bool-miscompilation/GH-7370/OTP-18634:
  Fix miscompilation of guard with `or`
  • Loading branch information
Erlang/OTP committed Jun 28, 2023
2 parents 3cff1b6 + c17f5de commit 10780bc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
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 @@ -367,7 +367,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 @@ -2620,6 +2620,7 @@ beam_bool_SUITE(_Config) ->
gh_6184(),
gh_7252(),
gh_7339(),
gh_7370(),
ok.

before_and_inside_if() ->
Expand Down Expand Up @@ -3205,6 +3206,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

0 comments on commit 10780bc

Please sign in to comment.