aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKostis Sagonas <[email protected]>2016-02-07 17:52:03 +0100
committerKostis Sagonas <[email protected]>2016-02-07 17:52:03 +0100
commita4cffd3b94ce1ad6d8f9b1415f5906f7c1170d47 (patch)
tree07454ba18079afed55348e1f9e7a04ad337da39f
parenta03b7add86b92d0d7d2d744e5555314bedbc2197 (diff)
downloadotp-a4cffd3b94ce1ad6d8f9b1415f5906f7c1170d47.tar.gz
otp-a4cffd3b94ce1ad6d8f9b1415f5906f7c1170d47.tar.bz2
otp-a4cffd3b94ce1ad6d8f9b1415f5906f7c1170d47.zip
Fix dialyzer warning and some code refactoring
A previous commit introduced a change that exposed dead code in this module and caused dialyzer warnings. This dead code was taken out. While at it, performed some code refactoring in the handling of the bs_get_integer primop.
-rw-r--r--lib/hipe/icode/hipe_icode_primops.erl39
1 files changed, 20 insertions, 19 deletions
diff --git a/lib/hipe/icode/hipe_icode_primops.erl b/lib/hipe/icode/hipe_icode_primops.erl
index 84aae30291..a0deb31c42 100644
--- a/lib/hipe/icode/hipe_icode_primops.erl
+++ b/lib/hipe/icode/hipe_icode_primops.erl
@@ -504,16 +504,16 @@ type(Primop, Args) ->
NewBinType = match_bin(erl_types:t_bitstr(0, Size), BinType),
NewMatchState =
erl_types:t_matchstate_update_present(NewBinType, MatchState),
- if Signed =:= 0 ->
- UpperBound = inf_add(safe_bsl(1, Size), -1),
- erl_types:t_product([erl_types:t_from_range(0, UpperBound),
- NewMatchState]);
- Signed =:= 4 ->
- erl_types:t_product([erl_types:t_from_range(
- inf_inv(safe_bsl(1, Size-1)),
- inf_add(safe_bsl(1, Size-1), -1)),
- NewMatchState])
- end;
+ Range =
+ case Signed of
+ 0 ->
+ UpperBound = inf_add(safe_bsl_1(Size), -1),
+ erl_types:t_from_range(0, UpperBound);
+ 4 ->
+ Bound = safe_bsl_1(Size - 1),
+ erl_types:t_from_range(inf_inv(Bound), inf_add(Bound, -1))
+ end,
+ erl_types:t_product([Range, NewMatchState]);
[_Arg] ->
NewBinType = match_bin(erl_types:t_bitstr(Size, 0), BinType),
NewMatchState =
@@ -969,18 +969,19 @@ check_fun_args(_, _) ->
match_bin(Pattern, Match) ->
erl_types:t_bitstr_match(Pattern, Match).
-safe_bsl(0, _) -> 0;
-safe_bsl(Base, Shift) when Shift =< 128 -> Base bsl Shift;
-safe_bsl(Base, _Shift) when Base > 0 -> pos_inf;
-safe_bsl(Base, _Shift) when Base < 0 -> neg_inf.
+-spec safe_bsl_1(non_neg_integer()) -> non_neg_integer() | 'pos_inf'.
+
+safe_bsl_1(Shift) when Shift =< 128 -> 1 bsl Shift;
+safe_bsl_1(_Shift) -> pos_inf.
+
+%%
+%% The following two functions are stripped-down versions of more
+%% general functions that exist in hipe_icode_range.erl
+%%
inf_inv(pos_inf) -> neg_inf;
-inf_inv(neg_inf) -> pos_inf;
-inf_inv(Number) -> -Number.
+inf_inv(Number) when is_integer(Number) -> -Number.
inf_add(pos_inf, _Number) -> pos_inf;
-inf_add(neg_inf, _Number) -> neg_inf;
-inf_add(_Number, pos_inf) -> pos_inf;
-inf_add(_Number, neg_inf) -> neg_inf;
inf_add(Number1, Number2) when is_integer(Number1), is_integer(Number2) ->
Number1 + Number2.