Skip to content

Commit e350931

Browse files
committed
Remove type argument from VD.update_offset
1 parent 6471c4f commit e350931

File tree

2 files changed

+18
-27
lines changed

2 files changed

+18
-27
lines changed

src/analyses/base.ml

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1093,9 +1093,6 @@ struct
10931093
* not include the flag. *)
10941094
let update_one_addr (x, offs) (nst, fl, dep): store =
10951095
let cil_offset = Offs.to_cil_offset offs in
1096-
let t = match t_override with
1097-
| Some t -> t
1098-
| None -> Cil.typeOf (Lval(Var x, cil_offset)) in
10991096
if M.tracing then M.tracel "setosek" ~var:firstvar "update_one_addr: start with '%a' (type '%a') \nstate:%a\n\n" AD.pretty (AD.from_var_offset (x,offs)) d_type x.vtype CPA.pretty st;
11001097
if isFunctionType x.vtype then begin
11011098
if M.tracing then M.tracel "setosek" ~var:firstvar "update_one_addr: returning: '%a' is a function type \n" d_type x.vtype;
@@ -1122,13 +1119,13 @@ struct
11221119
if M.tracing then M.tracel "setosek" ~var:x.vname "update_one_addr: update a global var '%s' ...\n" x.vname;
11231120
(* Here, an effect should be generated, but we add it to the local
11241121
* state, waiting for the sync function to publish it. *)
1125-
update_variable x (VD.update_offset a (get x nst) offs value (Option.map (fun x -> Lval x) lval_raw) (Var x, cil_offset) t) nst, fl, dep
1122+
update_variable x (VD.update_offset a (get x nst) offs value (Option.map (fun x -> Lval x) lval_raw) (Var x, cil_offset)) nst, fl, dep
11261123
end
11271124
else begin
11281125
if M.tracing then M.tracel "setosek" ~var:x.vname "update_one_addr: update a local var '%s' ...\n" x.vname;
11291126
(* Normal update of the local state *)
11301127
let lval_raw = (Option.map (fun x -> Lval x) lval_raw) in
1131-
let new_value = VD.update_offset a (CPA.find x nst) offs value lval_raw ((Var x), cil_offset) t in
1128+
let new_value = VD.update_offset a (CPA.find x nst) offs value lval_raw ((Var x), cil_offset) in
11321129
(* what effect does changing this local variable have on arrays -
11331130
we only need to do this here since globals are not allowed in the
11341131
expressions for partitioning *)
@@ -1675,9 +1672,8 @@ struct
16751672
| `Bot -> (* current value is VD `Bot *)
16761673
(match Addr.to_var_offset (AD.choose lval_val) with
16771674
| [(x,offs)] ->
1678-
let t = v.vtype in
16791675
let iv = bot_value ctx.ask ctx.global ctx.local v.vtype in (* correct bottom value for top level variable *)
1680-
let nv = VD.update_offset ctx.ask iv offs rval_val (Some (Lval lval)) lval t in (* do desired update to value *)
1676+
let nv = VD.update_offset ctx.ask iv offs rval_val (Some (Lval lval)) lval in (* do desired update to value *)
16811677
set_savetop ctx.ask ctx.global ctx.local (AD.from_var v) nv (* set top-level variable to updated value *)
16821678
| _ ->
16831679
set_savetop ctx.ask ctx.global ctx.local lval_val rval_val ~lval_raw:lval ~rval_raw:rval

src/cdomains/valueDomain.ml

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ sig
1717
include Lattice.S
1818
type offs
1919
val eval_offset: Q.ask -> (AD.t -> t) -> t-> offs -> exp option -> lval option -> t
20-
val update_offset: Q.ask -> t -> offs -> t -> exp option -> lval -> typ -> t
20+
val update_offset: Q.ask -> t -> offs -> t -> exp option -> lval -> t
2121
val update_array_lengths: (exp -> t) -> t -> Cil.typ -> t
2222
val affect_move: ?replace_with_const:bool -> Q.ask -> t -> varinfo -> (exp -> int option) -> t
2323
val affecting_vars: t -> varinfo list
@@ -739,19 +739,19 @@ struct
739739
in
740740
do_eval_offset ask f x offs exp l o v
741741

742-
let update_offset (ask: Q.ask) (x:t) (offs:offs) (value:t) (exp:exp option) (v:lval) (t:typ): t =
743-
let rec do_update_offset (ask:Q.ask) (x:t) (offs:offs) (value:t) (exp:exp option) (l:lval option) (o:offset option) (v:lval) (t:typ):t =
742+
let update_offset (ask: Q.ask) (x:t) (offs:offs) (value:t) (exp:exp option) (v:lval): t =
743+
let rec do_update_offset (ask:Q.ask) (x:t) (offs:offs) (value:t) (exp:exp option) (l:lval option) (o:offset option) (v:lval):t =
744744
let mu = function `Blob (`Blob (y, s'), s) -> `Blob (y, ID.join s s') | x -> x in
745745
match x, offs with
746746
| `Blob (x,s), `Index (_,ofs) ->
747747
begin
748748
let l', o' = shift_one_over l o in
749-
mu (`Blob (join x (do_update_offset ask x ofs value exp l' o' v t), s))
749+
mu (`Blob (join x (do_update_offset ask x ofs value exp l' o' v), s))
750750
end
751751
| `Blob (x,s),_ ->
752752
begin
753753
let l', o' = shift_one_over l o in
754-
mu (`Blob (join x (do_update_offset ask x offs value exp l' o' v t), s))
754+
mu (`Blob (join x (do_update_offset ask x offs value exp l' o' v), s))
755755
end
756756
| _ ->
757757
let result =
@@ -762,12 +762,11 @@ struct
762762
| _ -> value
763763
end
764764
| `Field (fld, offs) when fld.fcomp.cstruct -> begin
765-
let t = fld.ftype in
766765
match x with
767766
| `Struct str ->
768767
begin
769768
let l', o' = shift_one_over l o in
770-
let value' = (do_update_offset ask (Structs.get str fld) offs value exp l' o' v t) in
769+
let value' = (do_update_offset ask (Structs.get str fld) offs value exp l' o' v) in
771770
`Struct (Structs.replace str fld value')
772771
end
773772
| `Bot ->
@@ -778,12 +777,11 @@ struct
778777
in
779778
let strc = init_comp fld.fcomp in
780779
let l', o' = shift_one_over l o in
781-
`Struct (Structs.replace strc fld (do_update_offset ask `Bot offs value exp l' o' v t))
780+
`Struct (Structs.replace strc fld (do_update_offset ask `Bot offs value exp l' o' v))
782781
| `Top -> M.warn "Trying to update a field, but the struct is unknown"; top ()
783782
| _ -> M.warn "Trying to update a field, but was not given a struct"; top ()
784783
end
785784
| `Field (fld, offs) -> begin
786-
let t = fld.ftype in
787785
let l', o' = shift_one_over l o in
788786
match x with
789787
| `Union (last_fld, prev_val) ->
@@ -812,25 +810,22 @@ struct
812810
top (), offs
813811
end
814812
in
815-
`Union (`Lifted fld, do_update_offset ask tempval tempoffs value exp l' o' v t)
816-
| `Bot -> `Union (`Lifted fld, do_update_offset ask `Bot offs value exp l' o' v t)
813+
`Union (`Lifted fld, do_update_offset ask tempval tempoffs value exp l' o' v)
814+
| `Bot -> `Union (`Lifted fld, do_update_offset ask `Bot offs value exp l' o' v)
817815
| `Top -> M.warn "Trying to update a field, but the union is unknown"; top ()
818816
| _ -> M.warn_each "Trying to update a field, but was not given a union"; top ()
819817
end
820818
| `Index (idx, offs) -> begin
821819
let l', o' = shift_one_over l o in
822820
match x with
823821
| `Array x' ->
824-
(match t with
825-
| TArray(t1 ,_,_) ->
826-
let e = determine_offset ask l o exp (Some v) in
827-
let new_value_at_index = do_update_offset ask (CArrays.get ask x' (e,idx)) offs value exp l' o' v t1 in
828-
let new_array_value = CArrays.set ask x' (e, idx) new_value_at_index in
829-
`Array new_array_value
830-
| _ -> M.warn "Trying to update an array, but the type was not array"; top ())
822+
let e = determine_offset ask l o exp (Some v) in
823+
let new_value_at_index = do_update_offset ask (CArrays.get ask x' (e,idx)) offs value exp l' o' v in
824+
let new_array_value = CArrays.set ask x' (e, idx) new_value_at_index in
825+
`Array new_array_value
831826
| `Bot -> M.warn_each("encountered array bot, made array top"); `Array (CArrays.top ());
832827
| `Top -> M.warn "Trying to update an index, but the array is unknown"; top ()
833-
| x when IndexDomain.to_int idx = Some 0L -> do_update_offset ask x offs value exp l' o' v t
828+
| x when IndexDomain.to_int idx = Some 0L -> do_update_offset ask x offs value exp l' o' v
834829
| _ -> M.warn_each ("Trying to update an index, but was not given an array("^short 80 x^")"); top ()
835830
end
836831
in mu result
@@ -839,7 +834,7 @@ struct
839834
| Some(Lval (x,o)) -> Some ((x, NoOffset)), Some(o)
840835
| _ -> None, None
841836
in
842-
do_update_offset ask x offs value exp l o v t
837+
do_update_offset ask x offs value exp l o v
843838

844839
let rec affect_move ?(replace_with_const=false) ask (x:t) (v:varinfo) movement_for_expr:t =
845840
let move_fun x = affect_move ~replace_with_const:replace_with_const ask x v movement_for_expr in

0 commit comments

Comments
 (0)