summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjörn Gustavsson <bjorn@erlang.org>2023-05-04 13:15:03 +0200
committerGitHub <noreply@github.com>2023-05-04 13:15:03 +0200
commit196a9f2a03921d590a9e21ed4302a58ec63f88be (patch)
tree6cc808022bc4725c654168c2de17452f641c6812
parentc2f02cc939f19ebd76f4c4a07b8b3e4b9b3c7cd0 (diff)
parente718e07d578af2ca9726641751101e45b80cd25b (diff)
downloaderlang-196a9f2a03921d590a9e21ed4302a58ec63f88be.tar.gz
Merge pull request #7200 from bjorng/bjorn/compiler/fix-beam_types-crash/GH-7198
Eliminate crash in beam_types
-rw-r--r--lib/compiler/src/beam_types.erl24
-rw-r--r--lib/compiler/test/beam_type_SUITE.erl7
2 files changed, 17 insertions, 14 deletions
diff --git a/lib/compiler/src/beam_types.erl b/lib/compiler/src/beam_types.erl
index b668251f79..c3bf7c8fae 100644
--- a/lib/compiler/src/beam_types.erl
+++ b/lib/compiler/src/beam_types.erl
@@ -1179,14 +1179,13 @@ float_from_range(none) ->
none;
float_from_range(any) ->
#t_float{};
-float_from_range({'-inf','+inf'}) ->
- #t_float{};
-float_from_range({'-inf',Max}) ->
- make_float_range('-inf', safe_float(Max));
-float_from_range({Min,'+inf'}) ->
- make_float_range(safe_float(Min), '+inf');
-float_from_range({Min,Max}) ->
- make_float_range(safe_float(Min), safe_float(Max)).
+float_from_range({Min0,Max0}) ->
+ case {safe_float(Min0),safe_float(Max0)} of
+ {'-inf','+inf'} ->
+ #t_float{};
+ {Min,Max} ->
+ #t_float{elements={Min,Max}}
+ end.
safe_float(N) when is_number(N) ->
try
@@ -1194,12 +1193,9 @@ safe_float(N) when is_number(N) ->
catch
error:_ when N < 0 -> '-inf';
error:_ when N > 0 -> '+inf'
- end.
-
-make_float_range('-inf', '+inf') ->
- #t_float{};
-make_float_range(Min, Max) ->
- #t_float{elements={Min, Max}}.
+ end;
+safe_float('-inf'=NegInf) -> NegInf;
+safe_float('+inf'=PosInf) -> PosInf.
integer_from_range(none) ->
none;
diff --git a/lib/compiler/test/beam_type_SUITE.erl b/lib/compiler/test/beam_type_SUITE.erl
index 9c5fbc2e69..707c7ca80b 100644
--- a/lib/compiler/test/beam_type_SUITE.erl
+++ b/lib/compiler/test/beam_type_SUITE.erl
@@ -782,6 +782,8 @@ float_overflow(_Config) ->
Res2 = id((-1 bsl 1023) * two()),
Res2 = float_overflow_2(),
+ {'EXIT',{{bad_filter,[0]},_}} = catch float_overflow_3(),
+
ok.
%% GH-7178: There would be an overflow when converting a number range
@@ -808,6 +810,11 @@ float_overflow_2() ->
two() -> 2.
+float_overflow_3() ->
+ [0 || <<>> <= <<>>,
+ [0 || (floor(1.7976931348623157e308) bsl 1) >= (1.0 + map_size(#{}))]
+ ].
+
arity_checks(_Config) ->
%% ERL-549: an unsafe optimization removed a test_arity instruction,
%% causing the following to return 'broken' instead of 'ok'.