Refactor Sil.unop into separate Unop module

Summary: Move Sil.unop type and operations into separate Unop module.

Reviewed By: dulmarod

Differential Revision: D3548077

fbshipit-source-id: 49d3d83
master
Josh Berdine 8 years ago committed by Facebook Github Bot 7
parent 9487cab145
commit 2154c2c483

@ -37,13 +37,6 @@ let get_sentinel_func_attribute_value attr_list =>
}; };
/** Unary operations */
type unop =
| Neg /** Unary minus */
| BNot /** Bitwise complement (~) */
| LNot /** Logical Not (!) */;
/** Binary operations */ /** Binary operations */
type binop = type binop =
| PlusA /** arithmetic + */ | PlusA /** arithmetic + */
@ -427,7 +420,7 @@ type dexp =
| Ddot of dexp Ident.fieldname | Ddot of dexp Ident.fieldname
| Dpvar of Pvar.t | Dpvar of Pvar.t
| Dpvaraddr of Pvar.t | Dpvaraddr of Pvar.t
| Dunop of unop dexp | Dunop of Unop.t dexp
| Dunknown | Dunknown
| Dretcall of dexp (list dexp) Location.t call_flags; | Dretcall of dexp (list dexp) Location.t call_flags;
@ -477,7 +470,7 @@ and exp =
/** Pure variable: it is not an lvalue */ /** Pure variable: it is not an lvalue */
| Var of Ident.t | Var of Ident.t
/** Unary operator with type of the result if known */ /** Unary operator with type of the result if known */
| UnOp of unop exp (option Typ.t) | UnOp of Unop.t exp (option Typ.t)
/** Binary operator */ /** Binary operator */
| BinOp of binop exp exp | BinOp of binop exp exp
/** Exception */ /** Exception */
@ -714,19 +707,6 @@ let exp_is_this =
| Lvar pvar => Pvar.is_this pvar | Lvar pvar => Pvar.is_this pvar
| _ => false; | _ => false;
let unop_compare o1 o2 =>
switch (o1, o2) {
| (Neg, Neg) => 0
| (Neg, _) => (-1)
| (_, Neg) => 1
| (BNot, BNot) => 0
| (BNot, _) => (-1)
| (_, BNot) => 1
| (LNot, LNot) => 0
};
let unop_equal o1 o2 => unop_compare o1 o2 == 0;
let binop_compare o1 o2 => let binop_compare o1 o2 =>
switch (o1, o2) { switch (o1, o2) {
| (PlusA, PlusA) => 0 | (PlusA, PlusA) => 0
@ -1062,7 +1042,7 @@ let rec exp_compare (e1: exp) (e2: exp) :int =>
| (Var _, _) => (-1) | (Var _, _) => (-1)
| (_, Var _) => 1 | (_, Var _) => 1
| (UnOp o1 e1 to1, UnOp o2 e2 to2) => | (UnOp o1 e1 to1, UnOp o2 e2 to2) =>
let n = unop_compare o1 o2; let n = Unop.compare o1 o2;
if (n != 0) { if (n != 0) {
n n
} else { } else {
@ -1509,14 +1489,6 @@ let text_binop =
| PtrFld => "_ptrfld_"; | PtrFld => "_ptrfld_";
/** String representation of unary operator. */
let str_unop =
fun
| Neg => "-"
| BNot => "~"
| LNot => "!";
/** Pretty print a binary operator. */ /** Pretty print a binary operator. */
let str_binop pe binop => let str_binop pe binop =>
switch pe.pe_kind { switch pe.pe_kind {
@ -1628,7 +1600,7 @@ let rec dexp_to_string =
}; };
ampersand ^ s ampersand ^ s
} }
| Dunop op de => str_unop op ^ dexp_to_string de | Dunop op de => Unop.str op ^ dexp_to_string de
| Dsizeof typ _ _ => pp_to_string (Typ.pp_full pe_text) typ | Dsizeof typ _ _ => pp_to_string (Typ.pp_full pe_text) typ
| Dunknown => "unknown" | Dunknown => "unknown"
| Dretcall de _ _ _ => "returned by " ^ dexp_to_string de; | Dretcall de _ _ _ => "returned by " ^ dexp_to_string de;
@ -1756,7 +1728,7 @@ let rec _pp_exp pe0 pp_t f e0 => {
| Var id => (Ident.pp pe) f id | Var id => (Ident.pp pe) f id
| Const c => F.fprintf f "%a" (Const.pp pe) c | Const c => F.fprintf f "%a" (Const.pp pe) c
| Cast typ e => F.fprintf f "(%a)%a" pp_t typ pp_exp e | Cast typ e => F.fprintf f "(%a)%a" pp_t typ pp_exp e
| UnOp op e _ => F.fprintf f "%s%a" (str_unop op) pp_exp e | UnOp op e _ => F.fprintf f "%s%a" (Unop.str op) pp_exp e
| BinOp op (Const c) e2 when Config.smt_output => print_binop_stm_output (Const c) op e2 | BinOp op (Const c) e2 when Config.smt_output => print_binop_stm_output (Const c) op e2
| BinOp op e1 e2 => F.fprintf f "(%a %s %a)" pp_exp e1 (str_binop pe op) pp_exp e2 | BinOp op e1 e2 => F.fprintf f "(%a %s %a)" pp_exp e1 (str_binop pe op) pp_exp e2
| Exn e => F.fprintf f "EXN %a" pp_exp e | Exn e => F.fprintf f "EXN %a" pp_exp e
@ -3663,7 +3635,7 @@ let rec exp_compare_structural e1 e2 exp_map => {
switch (e1, e2) { switch (e1, e2) {
| (Var _, Var _) => compare_exps_with_map e1 e2 exp_map | (Var _, Var _) => compare_exps_with_map e1 e2 exp_map
| (UnOp o1 e1 to1, UnOp o2 e2 to2) => | (UnOp o1 e1 to1, UnOp o2 e2 to2) =>
let n = unop_compare o1 o2; let n = Unop.compare o1 o2;
if (n != 0) { if (n != 0) {
(n, exp_map) (n, exp_map)
} else { } else {

@ -26,13 +26,6 @@ type func_attribute = | FA_sentinel of int int;
type access = | Default | Public | Private | Protected; type access = | Default | Public | Private | Protected;
/** Unary operations */
type unop =
| Neg /** Unary minus */
| BNot /** Bitwise complement (~) */
| LNot /** Logical Not (!) */;
/** Binary operations */ /** Binary operations */
type binop = type binop =
| PlusA /** arithmetic + */ | PlusA /** arithmetic + */
@ -154,7 +147,7 @@ type dexp =
| Ddot of dexp Ident.fieldname | Ddot of dexp Ident.fieldname
| Dpvar of Pvar.t | Dpvar of Pvar.t
| Dpvaraddr of Pvar.t | Dpvaraddr of Pvar.t
| Dunop of unop dexp | Dunop of Unop.t dexp
| Dunknown | Dunknown
| Dretcall of dexp (list dexp) Location.t call_flags; | Dretcall of dexp (list dexp) Location.t call_flags;
@ -204,7 +197,7 @@ and exp =
/** Pure variable: it is not an lvalue */ /** Pure variable: it is not an lvalue */
| Var of Ident.t | Var of Ident.t
/** Unary operator with type of the result if known */ /** Unary operator with type of the result if known */
| UnOp of unop exp (option Typ.t) | UnOp of Unop.t exp (option Typ.t)
/** Binary operator */ /** Binary operator */
| BinOp of binop exp exp | BinOp of binop exp exp
/** Exception */ /** Exception */
@ -489,8 +482,6 @@ let block_pvar: Pvar.t;
/** Check if a pvar is a local pointing to a block in objc */ /** Check if a pvar is a local pointing to a block in objc */
let is_block_pvar: Pvar.t => bool; let is_block_pvar: Pvar.t => bool;
let unop_equal: unop => unop => bool;
let binop_equal: binop => binop => bool; let binop_equal: binop => binop => bool;
@ -621,10 +612,6 @@ let color_pre_wrapper: printenv => F.formatter => 'a => (printenv, bool);
let color_post_wrapper: bool => printenv => F.formatter => unit; let color_post_wrapper: bool => printenv => F.formatter => unit;
/** String representation of a unary operator. */
let str_unop: unop => string;
/** String representation of a binary operator. */ /** String representation of a binary operator. */
let str_binop: printenv => binop => string; let str_binop: printenv => binop => string;

@ -0,0 +1,48 @@
/*
* vim: set ft=rust:
* vim: set ft=reason:
*
* Copyright (c) 2009 - 2013 Monoidics ltd.
* Copyright (c) 2013 - present Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
open! Utils;
/** The Smallfoot Intermediate Language: Unary Operators */
let module L = Logging;
let module F = Format;
/** Unary operations */
type t =
| Neg /** Unary minus */
| BNot /** Bitwise complement (~) */
| LNot /** Logical Not (!) */;
let compare o1 o2 =>
switch (o1, o2) {
| (Neg, Neg) => 0
| (Neg, _) => (-1)
| (_, Neg) => 1
| (BNot, BNot) => 0
| (BNot, _) => (-1)
| (_, BNot) => 1
| (LNot, LNot) => 0
};
let equal o1 o2 => compare o1 o2 == 0;
/** String representation of unary operator. */
let str =
fun
| Neg => "-"
| BNot => "~"
| LNot => "!";

@ -0,0 +1,35 @@
/*
* vim: set ft=rust:
* vim: set ft=reason:
*
* Copyright (c) 2009 - 2013 Monoidics ltd.
* Copyright (c) 2013 - present Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
open! Utils;
/** The Smallfoot Intermediate Language: Unary Operators */
let module L = Logging;
let module F = Format;
/** Unary operations */
type t =
| Neg /** Unary minus */
| BNot /** Bitwise complement (~) */
| LNot /** Logical Not (!) */;
let equal: t => t => bool;
let compare: t => t => int;
/** String representation of a unary operator. */
let str: t => string;

@ -937,7 +937,7 @@ let rec exp_partial_join (e1: Sil.exp) (e2: Sil.exp) : Sil.exp =
let e1'' = exp_partial_join e1 e2 in let e1'' = exp_partial_join e1 e2 in
Sil.Cast (t1, e1'') Sil.Cast (t1, e1'')
| Sil.UnOp(unop1, e1, topt1), Sil.UnOp(unop2, e2, _) -> | Sil.UnOp(unop1, e1, topt1), Sil.UnOp(unop2, e2, _) ->
if not (Sil.unop_equal unop1 unop2) then (L.d_strln "failure reason 23"; raise IList.Fail) if not (Unop.equal unop1 unop2) then (L.d_strln "failure reason 23"; raise IList.Fail)
else Sil.UnOp (unop1, exp_partial_join e1 e2, topt1) (* should be topt1 = topt2 *) else Sil.UnOp (unop1, exp_partial_join e1 e2, topt1) (* should be topt1 = topt2 *)
| Sil.BinOp(Sil.PlusPI, e1, e1'), Sil.BinOp(Sil.PlusPI, e2, e2') -> | Sil.BinOp(Sil.PlusPI, e1, e1'), Sil.BinOp(Sil.PlusPI, e2, e2') ->
let e1'' = exp_partial_join e1 e2 in let e1'' = exp_partial_join e1 e2 in
@ -1018,7 +1018,7 @@ let rec exp_partial_meet (e1: Sil.exp) (e2: Sil.exp) : Sil.exp =
let e1'' = exp_partial_meet e1 e2 in let e1'' = exp_partial_meet e1 e2 in
Sil.Cast (t1, e1'') Sil.Cast (t1, e1'')
| Sil.UnOp(unop1, e1, topt1), Sil.UnOp(unop2, e2, _) -> | Sil.UnOp(unop1, e1, topt1), Sil.UnOp(unop2, e2, _) ->
if not (Sil.unop_equal unop1 unop2) then (L.d_strln "failure reason 31"; raise IList.Fail) if not (Unop.equal unop1 unop2) then (L.d_strln "failure reason 31"; raise IList.Fail)
else Sil.UnOp (unop1, exp_partial_meet e1 e2, topt1) (* should be topt1 = topt2 *) else Sil.UnOp (unop1, exp_partial_meet e1 e2, topt1) (* should be topt1 = topt2 *)
| Sil.BinOp(binop1, e1, e1'), Sil.BinOp(binop2, e2, e2') -> | Sil.BinOp(binop1, e1, e1'), Sil.BinOp(binop2, e2, e2') ->
if not (Sil.binop_equal binop1 binop2) then (L.d_strln "failure reason 32"; raise IList.Fail) if not (Sil.binop_equal binop1 binop2) then (L.d_strln "failure reason 32"; raise IList.Fail)

@ -400,7 +400,7 @@ let check_assignement_guard node =
let leti = IList.filter is_letderef_instr ins in let leti = IList.filter is_letderef_instr ins in
match pi, leti with match pi, leti with
| [Sil.Prune (Sil.Var(e1), _, _, _)], [Sil.Letderef(e2, e', _, _)] | [Sil.Prune (Sil.Var(e1), _, _, _)], [Sil.Letderef(e2, e', _, _)]
| [Sil.Prune (Sil.UnOp(Sil.LNot, Sil.Var(e1), _), _, _, _)], | [Sil.Prune (Sil.UnOp(Unop.LNot, Sil.Var(e1), _), _, _, _)],
[Sil.Letderef(e2, e', _, _)] [Sil.Letderef(e2, e', _, _)]
when (Ident.equal e1 e2) -> when (Ident.equal e1 e2) ->
if verbose if verbose
@ -430,7 +430,7 @@ let check_assignement_guard node =
let succs_have_simple_guards () = let succs_have_simple_guards () =
let check_instr = function let check_instr = function
| Sil.Prune (Sil.Var _, _, _, _) -> true | Sil.Prune (Sil.Var _, _, _, _) -> true
| Sil.Prune (Sil.UnOp(Sil.LNot, Sil.Var _, _), _, _, _) -> true | Sil.Prune (Sil.UnOp(Unop.LNot, Sil.Var _, _), _, _, _) -> true
| Sil.Prune _ -> false | Sil.Prune _ -> false
| _ -> true in | _ -> true in
let check_guard n = let check_guard n =

@ -58,7 +58,7 @@ let rec exp_match e1 sub vars e2 : (Sil.subst * Ident.t list) option =
exp_match e1' sub vars e2' exp_match e1' sub vars e2'
| Sil.Cast _, _ | _, Sil.Cast _ -> | Sil.Cast _, _ | _, Sil.Cast _ ->
None None
| Sil.UnOp(o1, e1', _), Sil.UnOp(o2, e2', _) when Sil.unop_equal o1 o2 -> | Sil.UnOp(o1, e1', _), Sil.UnOp(o2, e2', _) when Unop.equal o1 o2 ->
exp_match e1' sub vars e2' exp_match e1' sub vars e2'
| Sil.UnOp _, _ | _, Sil.UnOp _ -> | Sil.UnOp _, _ | _, Sil.UnOp _ ->
None (* Naive *) None (* Naive *)

@ -180,7 +180,7 @@ let create_type tenv n_lexp typ prop =
prop'' prop''
| None -> prop in | None -> prop in
let sil_is_null = Sil.BinOp (Sil.Eq, n_lexp, Sil.exp_zero) in let sil_is_null = Sil.BinOp (Sil.Eq, n_lexp, Sil.exp_zero) in
let sil_is_nonnull = Sil.UnOp (Sil.LNot, sil_is_null, None) in let sil_is_nonnull = Sil.UnOp (Unop.LNot, sil_is_null, None) in
let null_case = Propset.to_proplist (prune ~positive:true sil_is_null prop) in let null_case = Propset.to_proplist (prune ~positive:true sil_is_null prop) in
let non_null_case = Propset.to_proplist (prune ~positive:true sil_is_nonnull prop_type) in let non_null_case = Propset.to_proplist (prune ~positive:true sil_is_nonnull prop_type) in
if ((IList.length non_null_case) > 0) && (!Config.footprint) then if ((IList.length non_null_case) > 0) && (!Config.footprint) then

@ -466,41 +466,41 @@ let sym_eval abs e =
e e
| Sil.Cast (_, e1) -> | Sil.Cast (_, e1) ->
eval e1 eval e1
| Sil.UnOp (Sil.LNot, e1, topt) -> | Sil.UnOp (Unop.LNot, e1, topt) ->
begin begin
match eval e1 with match eval e1 with
| Sil.Const (Const.Cint i) when IntLit.iszero i -> | Sil.Const (Const.Cint i) when IntLit.iszero i ->
Sil.exp_one Sil.exp_one
| Sil.Const (Const.Cint _) -> | Sil.Const (Const.Cint _) ->
Sil.exp_zero Sil.exp_zero
| Sil.UnOp(Sil.LNot, e1', _) -> | Sil.UnOp(Unop.LNot, e1', _) ->
e1' e1'
| e1' -> | e1' ->
if abs then Sil.exp_get_undefined false else Sil.UnOp(Sil.LNot, e1', topt) if abs then Sil.exp_get_undefined false else Sil.UnOp(Unop.LNot, e1', topt)
end end
| Sil.UnOp (Sil.Neg, e1, topt) -> | Sil.UnOp (Unop.Neg, e1, topt) ->
begin begin
match eval e1 with match eval e1 with
| Sil.UnOp (Sil.Neg, e2', _) -> | Sil.UnOp (Unop.Neg, e2', _) ->
e2' e2'
| Sil.Const (Const.Cint i) -> | Sil.Const (Const.Cint i) ->
Sil.exp_int (IntLit.neg i) Sil.exp_int (IntLit.neg i)
| Sil.Const (Const.Cfloat v) -> | Sil.Const (Const.Cfloat v) ->
Sil.exp_float (-. v) Sil.exp_float (-. v)
| Sil.Var id -> | Sil.Var id ->
Sil.UnOp (Sil.Neg, Sil.Var id, topt) Sil.UnOp (Unop.Neg, Sil.Var id, topt)
| e1' -> | e1' ->
if abs then Sil.exp_get_undefined false else Sil.UnOp (Sil.Neg, e1', topt) if abs then Sil.exp_get_undefined false else Sil.UnOp (Unop.Neg, e1', topt)
end end
| Sil.UnOp (Sil.BNot, e1, topt) -> | Sil.UnOp (Unop.BNot, e1, topt) ->
begin begin
match eval e1 with match eval e1 with
| Sil.UnOp(Sil.BNot, e2', _) -> | Sil.UnOp(Unop.BNot, e2', _) ->
e2' e2'
| Sil.Const (Const.Cint i) -> | Sil.Const (Const.Cint i) ->
Sil.exp_int (IntLit.lognot i) Sil.exp_int (IntLit.lognot i)
| e1' -> | e1' ->
if abs then Sil.exp_get_undefined false else Sil.UnOp (Sil.BNot, e1', topt) if abs then Sil.exp_get_undefined false else Sil.UnOp (Unop.BNot, e1', topt)
end end
| Sil.BinOp (Sil.Le, e1, e2) -> | Sil.BinOp (Sil.Le, e1, e2) ->
begin begin
@ -629,8 +629,8 @@ let sym_eval abs e =
Sil.exp_int (n ++ m) Sil.exp_int (n ++ m)
| Sil.Const (Const.Cfloat v), Sil.Const (Const.Cfloat w) -> | Sil.Const (Const.Cfloat v), Sil.Const (Const.Cfloat w) ->
Sil.exp_float (v +. w) Sil.exp_float (v +. w)
| Sil.UnOp(Sil.Neg, f1, _), f2 | Sil.UnOp(Unop.Neg, f1, _), f2
| f2, Sil.UnOp(Sil.Neg, f1, _) -> | f2, Sil.UnOp(Unop.Neg, f1, _) ->
Sil.BinOp (ominus, f2, f1) Sil.BinOp (ominus, f2, f1)
| Sil.BinOp (Sil.PlusA, e, Sil.Const (Const.Cint n1)), Sil.Const (Const.Cint n2) | Sil.BinOp (Sil.PlusA, e, Sil.Const (Const.Cint n1)), Sil.Const (Const.Cint n2)
| Sil.BinOp (Sil.PlusPI, e, Sil.Const (Const.Cint n1)), Sil.Const (Const.Cint n2) | Sil.BinOp (Sil.PlusPI, e, Sil.Const (Const.Cint n1)), Sil.Const (Const.Cint n2)
@ -666,14 +666,14 @@ let sym_eval abs e =
else begin else begin
match e1', e2' with match e1', e2' with
| Sil.Const c, _ when iszero_int_float c -> | Sil.Const c, _ when iszero_int_float c ->
eval (Sil.UnOp(Sil.Neg, e2', None)) eval (Sil.UnOp(Unop.Neg, e2', None))
| _, Sil.Const c when iszero_int_float c -> | _, Sil.Const c when iszero_int_float c ->
e1' e1'
| Sil.Const (Const.Cint n), Sil.Const (Const.Cint m) -> | Sil.Const (Const.Cint n), Sil.Const (Const.Cint m) ->
Sil.exp_int (n -- m) Sil.exp_int (n -- m)
| Sil.Const (Const.Cfloat v), Sil.Const (Const.Cfloat w) -> | Sil.Const (Const.Cfloat v), Sil.Const (Const.Cfloat w) ->
Sil.exp_float (v -. w) Sil.exp_float (v -. w)
| _, Sil.UnOp (Sil.Neg, f2, _) -> | _, Sil.UnOp (Unop.Neg, f2, _) ->
eval (e1 +++ f2) eval (e1 +++ f2)
| _ , Sil.Const(Const.Cint n) -> | _ , Sil.Const(Const.Cint n) ->
eval (e1' +++ (Sil.exp_int (IntLit.neg n))) eval (e1' +++ (Sil.exp_int (IntLit.neg n)))
@ -697,13 +697,13 @@ let sym_eval abs e =
| Sil.Const c, _ when isone_int_float c -> | Sil.Const c, _ when isone_int_float c ->
e2' e2'
| Sil.Const c, _ when isminusone_int_float c -> | Sil.Const c, _ when isminusone_int_float c ->
eval (Sil.UnOp (Sil.Neg, e2', None)) eval (Sil.UnOp (Unop.Neg, e2', None))
| _, Sil.Const c when iszero_int_float c -> | _, Sil.Const c when iszero_int_float c ->
Sil.exp_zero Sil.exp_zero
| _, Sil.Const c when isone_int_float c -> | _, Sil.Const c when isone_int_float c ->
e1' e1'
| _, Sil.Const c when isminusone_int_float c -> | _, Sil.Const c when isminusone_int_float c ->
eval (Sil.UnOp (Sil.Neg, e1', None)) eval (Sil.UnOp (Unop.Neg, e1', None))
| Sil.Const (Const.Cint n), Sil.Const (Const.Cint m) -> | Sil.Const (Const.Cint n), Sil.Const (Const.Cint m) ->
Sil.exp_int (IntLit.mul n m) Sil.exp_int (IntLit.mul n m)
| Sil.Const (Const.Cfloat v), Sil.Const (Const.Cfloat w) -> | Sil.Const (Const.Cfloat v), Sil.Const (Const.Cfloat w) ->
@ -891,7 +891,7 @@ let mk_inequality e =
let new_offset = Sil.exp_int (n' -- n -- IntLit.one) in let new_offset = Sil.exp_int (n' -- n -- IntLit.one) in
let new_e = Sil.BinOp (Sil.Lt, new_offset, base') in let new_e = Sil.BinOp (Sil.Lt, new_offset, base') in
Sil.Aeq (new_e, Sil.exp_one) Sil.Aeq (new_e, Sil.exp_one)
| Sil.UnOp(Sil.Neg, new_base, _) -> | Sil.UnOp(Unop.Neg, new_base, _) ->
(* In this case, base = -new_base. Construct -n-1 < new_base. *) (* In this case, base = -new_base. Construct -n-1 < new_base. *)
let new_offset = Sil.exp_int (IntLit.zero -- n -- IntLit.one) in let new_offset = Sil.exp_int (IntLit.zero -- n -- IntLit.one) in
let new_e = Sil.BinOp (Sil.Lt, new_offset, new_base) in let new_e = Sil.BinOp (Sil.Lt, new_offset, new_base) in
@ -917,7 +917,7 @@ let mk_inequality e =
let new_offset = Sil.exp_int (n' -- n -- IntLit.one) in let new_offset = Sil.exp_int (n' -- n -- IntLit.one) in
let new_e = Sil.BinOp (Sil.Le, base', new_offset) in let new_e = Sil.BinOp (Sil.Le, base', new_offset) in
Sil.Aeq (new_e, Sil.exp_one) Sil.Aeq (new_e, Sil.exp_one)
| Sil.UnOp(Sil.Neg, new_base, _) -> | Sil.UnOp(Unop.Neg, new_base, _) ->
(* In this case, base = -new_base. Construct new_base <= -n-1 *) (* In this case, base = -new_base. Construct new_base <= -n-1 *)
let new_offset = Sil.exp_int (IntLit.zero -- n -- IntLit.one) in let new_offset = Sil.exp_int (IntLit.zero -- n -- IntLit.one) in
let new_e = Sil.BinOp (Sil.Le, new_base, new_offset) in let new_e = Sil.BinOp (Sil.Le, new_base, new_offset) in
@ -942,7 +942,7 @@ let inequality_normalize a =
let pos1, neg1, n1 = exp_to_posnegoff e1 in let pos1, neg1, n1 = exp_to_posnegoff e1 in
let pos2, neg2, n2 = exp_to_posnegoff e2 in let pos2, neg2, n2 = exp_to_posnegoff e2 in
(pos1@neg2, neg1@pos2, n1 -- n2) (pos1@neg2, neg1@pos2, n1 -- n2)
| Sil.UnOp(Sil.Neg, e1, _) -> | Sil.UnOp(Unop.Neg, e1, _) ->
let pos1, neg1, n1 = exp_to_posnegoff e1 in let pos1, neg1, n1 = exp_to_posnegoff e1 in
(neg1, pos1, IntLit.zero -- n1) (neg1, pos1, IntLit.zero -- n1)
| _ -> [e],[], IntLit.zero in | _ -> [e],[], IntLit.zero in
@ -1015,8 +1015,8 @@ let atom_normalize sub a0 =
| _ -> eq in | _ -> eq in
let handle_unary_negation e1 e2 = let handle_unary_negation e1 e2 =
match e1, e2 with match e1, e2 with
| Sil.UnOp (Sil.LNot, e1', _), Sil.Const (Const.Cint i) | Sil.UnOp (Unop.LNot, e1', _), Sil.Const (Const.Cint i)
| Sil.Const (Const.Cint i), Sil.UnOp (Sil.LNot, e1', _) when IntLit.iszero i -> | Sil.Const (Const.Cint i), Sil.UnOp (Unop.LNot, e1', _) when IntLit.iszero i ->
(e1', Sil.exp_zero, true) (e1', Sil.exp_zero, true)
| _ -> (e1, e2, false) in | _ -> (e1, e2, false) in
let handle_boolean_operation from_equality e1 e2 = let handle_boolean_operation from_equality e1 e2 =
@ -1974,7 +1974,7 @@ let find_arithmetic_problem proc_node_session prop exp =
false in false in
let rec walk = function let rec walk = function
| Sil.Var _ -> () | Sil.Var _ -> ()
| Sil.UnOp (Sil.Neg, e, Some ( | Sil.UnOp (Unop.Neg, e, Some (
(Typ.Tint (Typ.Tint
(Typ.IUChar | Typ.IUInt | Typ.IUShort | Typ.IULong | Typ.IULongLong) as typ))) -> (Typ.IUChar | Typ.IUInt | Typ.IUShort | Typ.IULong | Typ.IULongLong) as typ))) ->
uminus_unsigned := (e, typ) :: !uminus_unsigned uminus_unsigned := (e, typ) :: !uminus_unsigned
@ -2779,8 +2779,8 @@ let trans_land_lor op ((idl1, stml1), e1) ((idl2, stml2), e2) loc =
let id = Ident.create_fresh Ident.knormal in let id = Ident.create_fresh Ident.knormal in
let prune_instr1, prune_res1, prune_instr2, prune_res2 = let prune_instr1, prune_res1, prune_instr2, prune_res2 =
let cond1, cond2, res = match op with let cond1, cond2, res = match op with
| Sil.LAnd -> e1, Sil.UnOp(Sil.LNot, e1, None), IntLit.zero | Sil.LAnd -> e1, Sil.UnOp(Unop.LNot, e1, None), IntLit.zero
| Sil.LOr -> Sil.UnOp(Sil.LNot, e1, None), e1, IntLit.one | Sil.LOr -> Sil.UnOp(Unop.LNot, e1, None), e1, IntLit.one
| _ -> assert false in | _ -> assert false in
let cond_res1 = Sil.BinOp(Sil.Eq, Sil.Var id, e2) in let cond_res1 = Sil.BinOp(Sil.Eq, Sil.Var id, e2) in
let cond_res2 = Sil.BinOp(Sil.Eq, Sil.Var id, Sil.exp_int res) in let cond_res2 = Sil.BinOp(Sil.Eq, Sil.Var id, Sil.exp_int res) in
@ -2836,7 +2836,7 @@ let trans_if_then_else ((idl1, stml1), e1) ((idl2, stml2), e2) ((idl3, stml3), e
| Sil.Const (Const.Cint i) when IntLit.iszero i -> (idl1@idl3, stml1@stml3), e3 | Sil.Const (Const.Cint i) when IntLit.iszero i -> (idl1@idl3, stml1@stml3), e3
| Sil.Const (Const.Cint _) -> (idl1@idl2, stml1@stml2), e2 | Sil.Const (Const.Cint _) -> (idl1@idl2, stml1@stml2), e2
| _ -> | _ ->
let e1not = Sil.UnOp(Sil.LNot, e1, None) in let e1not = Sil.UnOp(Unop.LNot, e1, None) in
let id = Ident.create_fresh Ident.knormal in let id = Ident.create_fresh Ident.knormal in
let mk_prune_res e = let mk_prune_res e =
let mk_prune cond = Sil.Prune (cond, loc, true, Sil.Ik_land_lor) let mk_prune cond = Sil.Prune (cond, loc, true, Sil.Ik_land_lor)

@ -324,7 +324,7 @@ let rec prune ~positive condition prop =
assert false assert false
| Sil.Cast (_, condition') -> | Sil.Cast (_, condition') ->
prune ~positive condition' prop prune ~positive condition' prop
| Sil.UnOp (Sil.LNot, condition', _) -> | Sil.UnOp (Unop.LNot, condition', _) ->
prune ~positive:(not positive) condition' prop prune ~positive:(not positive) condition' prop
| Sil.UnOp _ -> | Sil.UnOp _ ->
assert false assert false
@ -445,7 +445,7 @@ let check_already_dereferenced pname cond prop =
let rec is_check_zero = function let rec is_check_zero = function
| Sil.Var id -> | Sil.Var id ->
Some id Some id
| Sil.UnOp(Sil.LNot, e, _) -> | Sil.UnOp(Unop.LNot, e, _) ->
is_check_zero e is_check_zero e
| Sil.BinOp ((Sil.Eq | Sil.Ne), Sil.Const Const.Cint i, Sil.Var id) | Sil.BinOp ((Sil.Eq | Sil.Ne), Sil.Const Const.Cint i, Sil.Var id)
| Sil.BinOp ((Sil.Eq | Sil.Ne), Sil.Var id, Sil.Const Const.Cint i) when IntLit.iszero i -> | Sil.BinOp ((Sil.Eq | Sil.Ne), Sil.Var id, Sil.Const Const.Cint i) when IntLit.iszero i ->

@ -291,7 +291,7 @@ module TransferFunctions (CFG : ProcCfg.S) = struct
| Sil.BinOp (Sil.Eq, lhs, rhs) | Sil.BinOp (Sil.Eq, lhs, rhs)
when is_tracking_exp astate lhs -> when is_tracking_exp astate lhs ->
Sil.exp_equal rhs Sil.exp_one Sil.exp_equal rhs Sil.exp_one
| Sil.UnOp (Sil.LNot, Sil.BinOp (Sil.Eq, lhs, rhs), _) | Sil.UnOp (Unop.LNot, Sil.BinOp (Sil.Eq, lhs, rhs), _)
when is_tracking_exp astate lhs -> when is_tracking_exp astate lhs ->
Sil.exp_equal rhs Sil.exp_zero Sil.exp_equal rhs Sil.exp_zero
| _ -> | _ ->

@ -244,9 +244,9 @@ module BooleanVars = struct
(** Normalize a boolean condition. *) (** Normalize a boolean condition. *)
let normalize_condition cond_e = let normalize_condition cond_e =
match cond_e with match cond_e with
| Sil.UnOp (Sil.LNot, Sil.BinOp (Sil.Eq, e1, e2), _) -> | Sil.UnOp (Unop.LNot, Sil.BinOp (Sil.Eq, e1, e2), _) ->
Sil.BinOp (Sil.Ne, e1, e2) Sil.BinOp (Sil.Ne, e1, e2)
| Sil.UnOp (Sil.LNot, Sil.BinOp (Sil.Ne, e1, e2), _) -> | Sil.UnOp (Unop.LNot, Sil.BinOp (Sil.Ne, e1, e2), _) ->
Sil.BinOp (Sil.Eq, e1, e2) Sil.BinOp (Sil.Eq, e1, e2)
| _ -> cond_e in | _ -> cond_e in

@ -127,9 +127,9 @@ module Match = struct
let e1 = Idenv.expand_expr idenv _e1 in let e1 = Idenv.expand_expr idenv _e1 in
let e2 = Idenv.expand_expr idenv _e2 in let e2 = Idenv.expand_expr idenv _e2 in
binop_match bop op && exp_match env ae1 (Vval e1) && exp_match env ae2 (Vval e2) binop_match bop op && exp_match env ae1 (Vval e1) && exp_match env ae2 (Vval e2)
| Sil.UnOp (Sil.LNot, (Sil.BinOp (Sil.Eq, e1, e2)), _) -> | Sil.UnOp (Unop.LNot, (Sil.BinOp (Sil.Eq, e1, e2)), _) ->
cond_match env idenv (Sil.BinOp (Sil.Ne, e1, e2)) (ae1, op, ae2) cond_match env idenv (Sil.BinOp (Sil.Ne, e1, e2)) (ae1, op, ae2)
| Sil.UnOp (Sil.LNot, (Sil.BinOp (Sil.Ne, e1, e2)), _) -> | Sil.UnOp (Unop.LNot, (Sil.BinOp (Sil.Ne, e1, e2)), _) ->
cond_match env idenv (Sil.BinOp (Sil.Eq, e1, e2)) (ae1, op, ae2) cond_match env idenv (Sil.BinOp (Sil.Eq, e1, e2)) (ae1, op, ae2)
| _ -> false | _ -> false

@ -169,10 +169,10 @@ let unary_operation_instruction uoi e typ loc =
else else
e_minus_1 in e_minus_1 in
(exp, instr1::[Sil.Set (e, typ, e_minus_1, loc)]) (exp, instr1::[Sil.Set (e, typ, e_minus_1, loc)])
| `Not -> (un_exp (Sil.BNot), []) | `Not -> (un_exp (Unop.BNot), [])
| `Minus -> (un_exp (Sil.Neg), []) | `Minus -> (un_exp (Unop.Neg), [])
| `Plus -> (e, []) | `Plus -> (e, [])
| `LNot -> (un_exp (Sil.LNot), []) | `LNot -> (un_exp (Unop.LNot), [])
| `Deref -> | `Deref ->
(* Actual dereferencing is handled by implicit cast from rvalue to lvalue *) (* Actual dereferencing is handled by implicit cast from rvalue to lvalue *)
(e, []) (e, [])

@ -123,7 +123,7 @@ module ComplexExpressions = struct
| Sil.Dpvaraddr _ (* front-end variable -- this should not happen) *) -> | Sil.Dpvaraddr _ (* front-end variable -- this should not happen) *) ->
case_not_handled () case_not_handled ()
| Sil.Dunop (op, de) -> | Sil.Dunop (op, de) ->
Sil.str_unop op ^ dexp_to_string de Unop.str op ^ dexp_to_string de
| Sil.Dsizeof _ -> | Sil.Dsizeof _ ->
case_not_handled () case_not_handled ()
| Sil.Dunknown -> | Sil.Dunknown ->
@ -1023,9 +1023,9 @@ let typecheck_instr
else typestate2 else typestate2
end end
| Sil.UnOp (Sil.LNot, (Sil.BinOp (Sil.Eq, e1, e2)), _) -> | Sil.UnOp (Unop.LNot, (Sil.BinOp (Sil.Eq, e1, e2)), _) ->
check_condition node' (Sil.BinOp (Sil.Ne, e1, e2)) check_condition node' (Sil.BinOp (Sil.Ne, e1, e2))
| Sil.UnOp (Sil.LNot, (Sil.BinOp (Sil.Ne, e1, e2)), _) -> | Sil.UnOp (Unop.LNot, (Sil.BinOp (Sil.Ne, e1, e2)), _) ->
check_condition node' (Sil.BinOp (Sil.Eq, e1, e2)) check_condition node' (Sil.BinOp (Sil.Eq, e1, e2))
| _ -> typestate in | _ -> typestate in
@ -1046,9 +1046,9 @@ let typecheck_instr
(** Normalize the condition by resolving temp variables. *) (** Normalize the condition by resolving temp variables. *)
let rec normalize_cond _node _cond = match _cond with let rec normalize_cond _node _cond = match _cond with
| Sil.UnOp (Sil.LNot, c, top) -> | Sil.UnOp (Unop.LNot, c, top) ->
let node', c' = normalize_cond _node c in let node', c' = normalize_cond _node c in
node', Sil.UnOp (Sil.LNot, c', top) node', Sil.UnOp (Unop.LNot, c', top)
| Sil.BinOp (bop, c1, c2) -> | Sil.BinOp (bop, c1, c2) ->
let node', c1' = normalize_cond _node c1 in let node', c1' = normalize_cond _node c1 in
let node'', c2' = normalize_cond node' c2 in let node'', c2' = normalize_cond node' c2 in

@ -438,7 +438,7 @@ let rec expression context pc expr =
let (instrs, sil_ex, _) = expression context pc ex in let (instrs, sil_ex, _) = expression context pc ex in
begin begin
match unop with match unop with
| JBir.Neg _ -> (instrs, Sil.UnOp (Sil.Neg, sil_ex, Some type_of_expr), type_of_expr) | JBir.Neg _ -> (instrs, Sil.UnOp (Unop.Neg, sil_ex, Some type_of_expr), type_of_expr)
| JBir.ArrayLength -> | JBir.ArrayLength ->
let array_typ_no_ptr = let array_typ_no_ptr =
match type_of_ex with match type_of_ex with
@ -874,7 +874,7 @@ let rec instruction context pc instr : translation =
and (instrs2, sil_ex2, _) = expression context pc e2 in and (instrs2, sil_ex2, _) = expression context pc e2 in
let sil_op = get_test_operator op in let sil_op = get_test_operator op in
let sil_test_false = Sil.BinOp (sil_op, sil_ex1, sil_ex2) in let sil_test_false = Sil.BinOp (sil_op, sil_ex1, sil_ex2) in
let sil_test_true = Sil.UnOp(Sil.LNot, sil_test_false, None) in let sil_test_true = Sil.UnOp(Unop.LNot, sil_test_false, None) in
let sil_instrs_true = Sil.Prune (sil_test_true, loc, true, Sil.Ik_if) in let sil_instrs_true = Sil.Prune (sil_test_true, loc, true, Sil.Ik_if) in
let sil_instrs_false = Sil.Prune (sil_test_false, loc, false, Sil.Ik_if) in let sil_instrs_false = Sil.Prune (sil_test_false, loc, false, Sil.Ik_if) in
let node_kind_true = Cfg.Node.Prune_node (true, Sil.Ik_if, "method_body") in let node_kind_true = Cfg.Node.Prune_node (true, Sil.Ik_if, "method_body") in

@ -73,7 +73,8 @@ let translate_exceptions context exit_nodes get_body_nodes handler_table =
Sil.Call ([id_instanceof], instanceof_builtin, args, loc, Sil.cf_default) in Sil.Call ([id_instanceof], instanceof_builtin, args, loc, Sil.cf_default) in
let if_kind = Sil.Ik_switch in let if_kind = Sil.Ik_switch in
let instr_prune_true = Sil.Prune (Sil.Var id_instanceof, loc, true, if_kind) in let instr_prune_true = Sil.Prune (Sil.Var id_instanceof, loc, true, if_kind) in
let instr_prune_false = Sil.Prune (Sil.UnOp(Sil.LNot, Sil.Var id_instanceof, None), loc, false, if_kind) in let instr_prune_false =
Sil.Prune (Sil.UnOp(Unop.LNot, Sil.Var id_instanceof, None), loc, false, if_kind) in
let instr_set_catch_var = let instr_set_catch_var =
let catch_var = JContext.set_pvar context handler.JBir.e_catch_var ret_type in let catch_var = JContext.set_pvar context handler.JBir.e_catch_var ret_type in
Sil.Set (Sil.Lvar catch_var, ret_type, Sil.Var id_exn_val, loc) in Sil.Set (Sil.Lvar catch_var, ret_type, Sil.Var id_exn_val, loc) in

@ -165,7 +165,7 @@ module Make
create_node (Cfg.Node.Prune_node (true_branch, if_kind, "")) [prune_instr] in create_node (Cfg.Node.Prune_node (true_branch, if_kind, "")) [prune_instr] in
let true_prune_node = mk_prune_node cond_exp if_kind true in let true_prune_node = mk_prune_node cond_exp if_kind true in
let false_prune_node = let false_prune_node =
let negated_cond_exp = Sil.UnOp (Sil.LNot, cond_exp, None) in let negated_cond_exp = Sil.UnOp (Unop.LNot, cond_exp, None) in
mk_prune_node negated_cond_exp if_kind false in mk_prune_node negated_cond_exp if_kind false in
true_prune_node, false_prune_node in true_prune_node, false_prune_node in

Loading…
Cancel
Save