Skip to content

Commit

Permalink
Share eval_unop definitions between base.ml and baseInvariant.ml
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-schwarz committed Feb 4, 2024
1 parent 9f0c940 commit c8b2fb7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
6 changes: 6 additions & 0 deletions src/analyses/base.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1645,6 +1645,9 @@ struct
module V = V
module G = G

let unop_ID = unop_ID
let unop_FD = unop_FD

let eval_rv = eval_rv
let eval_rv_address = eval_rv_address
let eval_lv = eval_lv
Expand Down Expand Up @@ -2842,6 +2845,9 @@ struct

let ost = octx.local

let unop_ID = unop_ID
let unop_FD = unop_FD

(* all evals happen in octx with non-top values *)
let eval_rv ~ctx st e = eval_rv ~ctx:octx ost e
let eval_rv_address ~ctx st e = eval_rv_address ~ctx:octx ost e
Expand Down
15 changes: 4 additions & 11 deletions src/analyses/baseInvariant.ml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ sig
module V: Analyses.SpecSysVar
module G: Lattice.S

val unop_ID: Cil.unop -> ID.t -> ID.t
val unop_FD: Cil.unop -> FD.t -> VD.t

val eval_rv: ctx:(D.t, G.t, _, V.t) Analyses.ctx -> D.t -> exp -> VD.t
val eval_rv_address: ctx:(D.t, G.t, _, V.t) Analyses.ctx -> D.t -> exp -> VD.t
val eval_lv: ctx:(D.t, G.t, _, V.t) Analyses.ctx -> D.t -> lval -> AD.t
Expand Down Expand Up @@ -41,16 +44,6 @@ module Make (Eval: Eval) =
struct
open Eval

let unop_ID = function
| Neg -> ID.neg
| BNot -> ID.lognot
| LNot -> ID.c_lognot

let unop_FD = function
| Neg -> FD.neg
(* other unary operators are not implemented on float values *)
| _ -> (fun c -> FD.top_of (FD.get_fkind c))

let is_some_bot (x:VD.t) =
match x with
| Bot -> false (* HACK: bot is here due to typing conflict (we do not cast appropriately) *)
Expand Down Expand Up @@ -589,7 +582,7 @@ struct
inv_exp (Float zero_float) e st
| _ -> st
)
| UnOp (Neg, e, _), Float c -> inv_exp (Float (unop_FD Neg c)) e st
| UnOp (Neg, e, _), Float c -> inv_exp (unop_FD Neg c) e st
| UnOp ((BNot|Neg) as op, e, _), Int c -> inv_exp (Int (unop_ID op c)) e st
(* no equivalent for Float, as VD.is_safe_cast fails for all float types anyways *)
| BinOp((Eq | Ne) as op, CastE (t1, e1), CastE (t2, e2), t), Int c when typeSig (Cilfacade.typeOf e1) = typeSig (Cilfacade.typeOf e2) && VD.is_safe_cast t1 (Cilfacade.typeOf e1) && VD.is_safe_cast t2 (Cilfacade.typeOf e2) ->
Expand Down

0 comments on commit c8b2fb7

Please sign in to comment.