From 63c13786ec04bba57acaea6dee1f2fbc77c7b5e1 Mon Sep 17 00:00:00 2001 From: Kostis Sagonas Date: Tue, 26 Jan 2010 17:38:55 +0200 Subject: Fix a HiPE compiler bug evaluating an expression that throws system_limit --- lib/hipe/cerl/erl_bif_types.erl | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) (limited to 'lib/hipe/cerl') diff --git a/lib/hipe/cerl/erl_bif_types.erl b/lib/hipe/cerl/erl_bif_types.erl index 756fcb8bbf..8aa2cc76c7 100644 --- a/lib/hipe/cerl/erl_bif_types.erl +++ b/lib/hipe/cerl/erl_bif_types.erl @@ -3128,20 +3128,25 @@ arith(Op, X1, X2) -> %% io:format("done arith ~p = ~p~n", [Op, {NewMin, NewMax}]), {ok, t_from_range(NewMin, NewMax)}; false -> - AllVals = - case Op of - '+' -> [X + Y || X <- L1, Y <- L2]; - '-' -> [X - Y || X <- L1, Y <- L2]; - '*' -> [X * Y || X <- L1, Y <- L2]; - 'div' -> [X div Y || X <- L1, Y <- L2,Y =/= 0]; - 'rem' -> [X rem Y || X <- L1, Y <- L2,Y =/= 0]; - 'bsl' -> [X bsl Y || X <- L1, Y <- L2]; - 'bsr' -> [X bsr Y || X <- L1, Y <- L2]; - 'band' -> [X band Y || X <- L1, Y <- L2]; - 'bor' -> [X bor Y || X <- L1, Y <- L2]; - 'bxor' -> [X bxor Y || X <- L1, Y <- L2] - end, - {ok, t_integers(ordsets:from_list(AllVals))} + %% Some of these arithmetic operations might throw a system_limit + %% exception; for example, when trying to evaluate 1 bsl 100000000. + try case Op of + '+' -> [X + Y || X <- L1, Y <- L2]; + '-' -> [X - Y || X <- L1, Y <- L2]; + '*' -> [X * Y || X <- L1, Y <- L2]; + 'div' -> [X div Y || X <- L1, Y <- L2,Y =/= 0]; + 'rem' -> [X rem Y || X <- L1, Y <- L2,Y =/= 0]; + 'bsl' -> [X bsl Y || X <- L1, Y <- L2]; + 'bsr' -> [X bsr Y || X <- L1, Y <- L2]; + 'band' -> [X band Y || X <- L1, Y <- L2]; + 'bor' -> [X bor Y || X <- L1, Y <- L2]; + 'bxor' -> [X bxor Y || X <- L1, Y <- L2] + end of + AllVals -> + {ok, t_integers(ordsets:from_list(AllVals))} + catch + error:system_limit -> error + end end end. -- cgit v1.2.3