From a034ff64abab5f5cbf5c6aa38762044c968fe377 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= Date: Sat, 25 May 2019 10:23:20 +0200 Subject: Fix unsafe optimizations where guard tests could be removed A repeated test could be optimized away. Example: bar(A) -> if is_bitstring(A) -> if is_binary(A) -> binary; true -> bitstring end; true -> other end. In the example, the `is_binary/1` test would be optimized away, basically turning the example into: bar(A) -> if is_bitstring(A) -> bitstring; true -> other end. Thanks user Marcus Kruse in the Elixir forum for noticing this bug. --- lib/compiler/src/beam_ssa_dead.erl | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) (limited to 'lib/compiler/src') diff --git a/lib/compiler/src/beam_ssa_dead.erl b/lib/compiler/src/beam_ssa_dead.erl index bb43a550ae..e220a89ded 100644 --- a/lib/compiler/src/beam_ssa_dead.erl +++ b/lib/compiler/src/beam_ssa_dead.erl @@ -680,11 +680,8 @@ will_succeed_test(is_list, is_nonempty_list) -> maybe; will_succeed_test(is_nonempty_list, is_list) -> yes; -will_succeed_test(T1, T2) -> - case is_numeric_test(T1) andalso is_numeric_test(T2) of - true -> maybe; - false -> no - end. +will_succeed_test(_T1, _T2) -> + maybe. will_succeed_1('=:=', A, '<', B) -> if @@ -769,11 +766,6 @@ will_succeed_vars('==', Val1, '/=', Val2) when Val1 == Val2 -> no; will_succeed_vars(_, _, _, _) -> maybe. -is_numeric_test(is_float) -> true; -is_numeric_test(is_integer) -> true; -is_numeric_test(is_number) -> true; -is_numeric_test(_) -> false. - eval_type_test(Test, Arg) -> case eval_type_test_1(Test, Arg) of true -> yes; -- cgit v1.2.3