From e718e07d578af2ca9726641751101e45b80cd25b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= Date: Wed, 3 May 2023 13:12:56 +0200 Subject: Eliminate crash in beam_types Closes #7198 --- lib/compiler/src/beam_types.erl | 24 ++++++++++-------------- lib/compiler/test/beam_type_SUITE.erl | 7 +++++++ 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 18a29f2643..21bfe5c7ec 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'. -- cgit v1.2.1