Skip to content

Commit e699fd0

Browse files
authored
Merge pull request #1984 from goblint/valuedomain-do-offset-2
Remove type argument from `do_update_offset`, fix calls with incorrect offset type
2 parents 2dc5b68 + 4d3d8e3 commit e699fd0

3 files changed

Lines changed: 21 additions & 26 deletions

File tree

src/analyses/base.ml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1675,7 +1675,7 @@ struct
16751675
* not include the flag. *)
16761676
let set_mval ~(man: _ man) ?(invariant=false) ?(blob_destructive=false) ?lval_raw ?rval_raw ?t_override (st: store) ((x, offs): Addr.Mval.t) (lval_type: Cil.typ) (value: value): store =
16771677
let ask = Analyses.ask_of_man man in
1678-
let cil_offset = Offs.to_cil_offset offs in
1678+
let cil_offset = Offs.to_cil_offset offs in (* Only for partitioned arrays! Drops indices. *)
16791679
let t = match t_override with
16801680
| Some t -> t
16811681
| None ->
@@ -1685,11 +1685,11 @@ struct
16851685
lval_type
16861686
else
16871687
try
1688-
Cilfacade.typeOfLval (Var x, cil_offset)
1689-
with Cilfacade.TypeOfError _ ->
1688+
Offs.type_of ~base:x.vtype offs
1689+
with Offset.Type_of_error _ ->
16901690
(* If we cannot determine the correct type here, we go with the one of the LVal *)
16911691
(* This will usually lead to a type mismatch in the ValueDomain (and hence supertop) *)
1692-
M.debug ~category:Analyzer "Cilfacade.typeOfLval failed Could not obtain the type of %a" d_lval (Var x, cil_offset);
1692+
M.debug ~category:Analyzer "Could not obtain the type of %a" Addr.Mval.pretty (x, offs);
16931693
lval_type
16941694
in
16951695
let update_offset old_value =
@@ -1708,7 +1708,7 @@ struct
17081708
else
17091709
new_value
17101710
in
1711-
if M.tracing then M.tracel "set" "update_one_addr: start with '%a' (type '%a') \nstate:%a" AD.pretty (AD.of_mval (x,offs)) d_type x.vtype D.pretty st;
1711+
if M.tracing then M.tracel "set" "update_one_addr: start with '%a' (type '%a') \nstate:%a" Addr.Mval.pretty (x,offs) d_type t D.pretty st;
17121712
if isFunctionType x.vtype then begin
17131713
if M.tracing then M.tracel "set" "update_one_addr: returning: '%a' is a function type " d_type x.vtype;
17141714
st
@@ -2002,7 +2002,7 @@ struct
20022002
let t = v.vtype in
20032003
let iv = VD.bot_value ~varAttr:v.vattr t in (* correct bottom value for top level variable *)
20042004
if M.tracing then M.tracel "set" "init bot value (%a): %a" d_plaintype t VD.pretty iv;
2005-
let nv = VD.update_offset (Queries.to_value_domain_ask (Analyses.ask_of_man man)) iv offs rval_val (Some (Lval lval)) lval t in (* do desired update to value *)
2005+
let nv = VD.update_offset (Queries.to_value_domain_ask (Analyses.ask_of_man man)) iv offs rval_val (Some (Lval lval)) lval lval_t in (* do desired update to value *)
20062006
set_savetop ~man man.local (AD.of_var v) lval_t nv ~lval_raw:lval ~rval_raw:rval (* set top-level variable to updated value *)
20072007
| _ ->
20082008
set_savetop ~man man.local lval_val lval_t rval_val ~lval_raw:lval ~rval_raw:rval

src/analyses/baseInvariant.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ struct
103103
let old_val = get_var ~man st var in
104104
let old_val = map_oldval old_val var.vtype in
105105
let offs = convert_offset ~man st o in
106-
let new_val = VD.update_offset (Queries.to_value_domain_ask (Analyses.ask_of_man man)) old_val offs c' (Some exp) x (var.vtype) in
106+
let new_val = VD.update_offset (Queries.to_value_domain_ask (Analyses.ask_of_man man)) old_val offs c' (Some exp) x (Cilfacade.typeOfLval x) in
107107
let v = apply_invariant ~old_val ~new_val in
108108
if is_some_bot v then contra st
109109
else (

src/cdomain/value/cdomains/valueDomain.ml

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -978,7 +978,7 @@ struct
978978
do_eval_offset x offs l o
979979

980980
let update_offset ?(blob_destructive=false) (ask: VDQ.t) (x:t) (offs:offs) (value:t) (exp:exp option) (v:lval) (t:typ): t =
981-
let rec do_update_offset ?(bitfield:int option=None) (x:t) (offs:offs) (l:lval option) (o:offset option) (t:typ):t = (* TODO: why does inner t argument change here, but not in eval_offset? *)
981+
let rec do_update_offset ?(bitfield:int option=None) (x:t) (offs:offs) (l:lval option) (o:offset option):t =
982982
if M.tracing then M.traceli "update_offset" "do_update_offset %a %a (%a) %a" pretty x Offs.pretty offs (Pretty.docOpt (CilType.Exp.pretty ())) exp pretty value;
983983
let mu = function Blob (Blob (y, s', zeroinit), s, _) -> Blob (y, ID.join s s', zeroinit) | x -> x in
984984
let r =
@@ -989,7 +989,7 @@ struct
989989
begin
990990
let l', o' = shift_one_over l o in
991991
let x = zero_init_calloced_memory zeroinit x t in
992-
mu (Blob (join x (do_update_offset x ofs l' o' t), s, zeroinit))
992+
mu (Blob (join x (do_update_offset x ofs l' o'), s, zeroinit))
993993
end
994994
| Blob (x,s,zeroinit), `Field(f, _) ->
995995
begin
@@ -1009,9 +1009,9 @@ struct
10091009
| _ -> false
10101010
in
10111011
if do_strong_update then
1012-
Blob ((do_update_offset x offs l' o' t), s, zeroinit)
1012+
Blob ((do_update_offset x offs l' o'), s, zeroinit)
10131013
else
1014-
mu (Blob (join x (do_update_offset x offs l' o' t), s, zeroinit))
1014+
mu (Blob (join x (do_update_offset x offs l' o'), s, zeroinit))
10151015
end
10161016
| Blob (x,s,zeroinit), `NoOffset -> (* `NoOffset is only remaining possibility for Blob here *)
10171017
begin
@@ -1036,9 +1036,9 @@ struct
10361036
end
10371037
in
10381038
if do_strong_update then
1039-
Blob ((do_update_offset x offs l' o' t), s, zeroinit)
1039+
Blob ((do_update_offset x offs l' o'), s, zeroinit)
10401040
else
1041-
mu (Blob (join x (do_update_offset x offs l' o' t), s, zeroinit))
1041+
mu (Blob (join x (do_update_offset x offs l' o'), s, zeroinit))
10421042
end
10431043
| Thread _, _ ->
10441044
(* hack for pthread_t variables *)
@@ -1076,12 +1076,11 @@ struct
10761076
| _ -> value
10771077
end
10781078
| `Field (fld, offs) when fld.fcomp.cstruct -> begin
1079-
let t = fld.ftype in
10801079
match x with
10811080
| Struct str ->
10821081
begin
10831082
let l', o' = shift_one_over l o in
1084-
let value' = do_update_offset ~bitfield:fld.fbitfield (Structs.get str fld) offs l' o' t in
1083+
let value' = do_update_offset ~bitfield:fld.fbitfield (Structs.get str fld) offs l' o' in
10851084
Struct (Structs.replace str fld value')
10861085
end
10871086
| Bot ->
@@ -1092,12 +1091,11 @@ struct
10921091
in
10931092
let strc = init_comp fld.fcomp in
10941093
let l', o' = shift_one_over l o in
1095-
Struct (Structs.replace strc fld (do_update_offset Bot offs l' o' t))
1094+
Struct (Structs.replace strc fld (do_update_offset Bot offs l' o'))
10961095
| Top -> M.warn ~category:Imprecise "Trying to update a field, but the struct is unknown"; top ()
10971096
| _ -> M.warn ~category:Imprecise "Trying to update a field, but was not given a struct"; top ()
10981097
end
10991098
| `Field (fld, offs) -> begin
1100-
let t = fld.ftype in
11011099
let l', o' = shift_one_over l o in
11021100
match x with
11031101
| Union (last_fld, prev_val) ->
@@ -1125,20 +1123,17 @@ struct
11251123
top (), offs
11261124
end
11271125
in
1128-
Union (`Lifted fld, do_update_offset tempval tempoffs l' o' t)
1129-
| Bot -> Union (`Lifted fld, do_update_offset Bot offs l' o' t)
1126+
Union (`Lifted fld, do_update_offset tempval tempoffs l' o')
1127+
| Bot -> Union (`Lifted fld, do_update_offset Bot offs l' o')
11301128
| Top -> M.warn ~category:Imprecise "Trying to update a field, but the union is unknown"; top ()
11311129
| _ -> M.warn ~category:Imprecise "Trying to update a field, but was not given a union"; top ()
11321130
end
11331131
| `Index (idx, offs) -> begin
11341132
let l', o' = shift_one_over l o in
11351133
match x with
11361134
| Array x' ->
1137-
let t = (match Cil.unrollType t with
1138-
| TArray(t1 ,_,_) -> t1
1139-
| _ -> t) in (* This is necessary because t is not a TArray in case of calloc *)
11401135
let e = determine_offset ask l o exp (Some v) in
1141-
let new_value_at_index = do_update_offset (CArrays.get ask x' (e,idx)) offs l' o' t in
1136+
let new_value_at_index = do_update_offset (CArrays.get ask x' (e,idx)) offs l' o' in
11421137
let new_array_value = CArrays.set ask x' (e, idx) new_value_at_index in
11431138
Array new_array_value
11441139
| Bot ->
@@ -1147,15 +1142,15 @@ struct
11471142
| _ -> t, None) in (* This is necessary because t is not a TArray in case of calloc *)
11481143
let x' = CArrays.bot () in
11491144
let e = determine_offset ask l o exp (Some v) in
1150-
let new_value_at_index = do_update_offset Bot offs l' o' t in
1145+
let new_value_at_index = do_update_offset Bot offs l' o' in
11511146
let new_array_value = CArrays.set ask x' (e, idx) new_value_at_index in
11521147
let len_ci = BatOption.bind len (fun e -> Cil.getInteger @@ Cil.constFold true e) in
11531148
let len_id = BatOption.map (IndexDomain.of_int (Cilfacade.ptrdiff_ikind ())) len_ci in
11541149
let newl = BatOption.default (ID.starting (Cilfacade.ptrdiff_ikind ()) Z.zero) len_id in
11551150
let new_array_value = CArrays.update_length newl new_array_value in
11561151
Array new_array_value
11571152
| Top -> M.warn ~category:Imprecise "Trying to update an index, but the array is unknown"; top ()
1158-
| x when GobOption.exists (Z.equal Z.zero) (IndexDomain.to_int idx) -> do_update_offset x offs l' o' t
1153+
| x when GobOption.exists (Z.equal Z.zero) (IndexDomain.to_int idx) -> do_update_offset x offs l' o'
11591154
| _ -> M.warn ~category:Imprecise "Trying to update an index, but was not given an array(%a)" pretty x; top ()
11601155
end
11611156
in mu result
@@ -1167,7 +1162,7 @@ struct
11671162
| Some(Lval (x,o)) -> Some ((x, NoOffset)), Some(o)
11681163
| _ -> None, None
11691164
in
1170-
do_update_offset x offs l o t
1165+
do_update_offset x offs l o
11711166

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

0 commit comments

Comments
 (0)