8000 beam_types: Fix another +0.0/-0.0 issue by jhogberg · Pull Request #8101 · erlang/otp · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

beam_types: Fix another +0.0/-0.0 issue #8101

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

Merged
merged 1 commit into from
Feb 9, 2024
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
13 changes: 9 additions & 4 deletions lib/compiler/src/beam_types.erl
Original file line number Diff line number Diff line change
Expand Up @@ -260,10 +260,15 @@ join(#t_tuple{}=A, #t_tuple{}=B) ->
lub(A, B);
{_Key, none} ->
lub(A, B);
{KeyA, KeyB} when KeyA < KeyB ->
#t_union{tuple_set=[{KeyA, A}, {KeyB, B}]};
{KeyA, KeyB} when KeyA > KeyB ->
#t_union{tuple_set=[{KeyB, B}, {KeyA, A}]}
{KeyA, KeyB} ->
%% We must use total ordering rather than plain '<' as -0.0 differs
%% from +0.0
case total_compare(KeyA, KeyB, fun erlang:'<'/2) of
true ->
#t_union{tuple_set=[{KeyA, A}, {KeyB, B}]};
false ->
#t_union{tuple_set=[{KeyB, B}, {KeyA, A}]}
end
end;
join(#t_tuple{}=A, B) ->
%% All other combinations have been tried already, so B must be 'other'
Expand Down
17 changes: 17 additions & 0 deletions lib/compiler/test/beam_type_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1514,6 +1514,7 @@ float_confusion(_Config) ->
{'EXIT', _} = catch float_confusion_3(id(0.0)),
ok = float_confusion_4(id(1)),
{'EXIT', _} = catch float_confusion_5(),
{'EXIT', _} = catch float_confusion_6(),
ok.

float_confusion_1(_, _) ->
Expand Down Expand Up @@ -1547,6 +1548,22 @@ float_confusion_5() ->
end * 0,
ok.

%% GH-8097: Record keys weren't compared in total order, confusing +0.0 and
%% -0.0 and crashing the compiler.
float_confusion_6() ->
<<
(ok)
|| _ := {_V1} <- ok,
(maybe
{} ?= _V1
else
-0.0 ->
[];
0.0 ->
[]
end)
>>.

%%%
%%% Common utilities.
%%%
Expand Down
0