Skip to content

Commit 697f4fc

Browse files
committed
Hack to remove type argument from do_update_offset, fix other issues
1 parent 23e99b5 commit 697f4fc

File tree

3 files changed

+20
-19
lines changed

3 files changed

+20
-19
lines changed

src/analyses/base.ml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1675,8 +1675,9 @@ struct
16751675
lval_type
16761676
else
16771677
try
1678-
Cilfacade.typeOfLval (Var x, cil_offset)
1679-
with Cilfacade.TypeOfError _ ->
1678+
Offs.type_of ~base:x.vtype offs
1679+
(* Cilfacade.typeOfLval (Var x, cil_offset) *)
1680+
with Cilfacade.TypeOfError _ | Offset.Type_of_error _ ->
16801681
(* If we cannot determine the correct type here, we go with the one of the LVal *)
16811682
(* This will usually lead to a type mismatch in the ValueDomain (and hence supertop) *)
16821683
M.debug ~category:Analyzer "Cilfacade.typeOfLval failed Could not obtain the type of %a" d_lval (Var x, cil_offset);
@@ -1698,7 +1699,7 @@ struct
16981699
else
16991700
new_value
17001701
in
1701-
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;
1702+
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 t D.pretty st;
17021703
if isFunctionType x.vtype then begin
17031704
if M.tracing then M.tracel "set" "update_one_addr: returning: '%a' is a function type " d_type x.vtype;
17041705
st
@@ -1989,7 +1990,7 @@ struct
19891990
let t = v.vtype in
19901991
let iv = VD.bot_value ~varAttr:v.vattr t in (* correct bottom value for top level variable *)
19911992
if M.tracing then M.tracel "set" "init bot value (%a): %a" d_plaintype t VD.pretty iv;
1992-
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 *)
1993+
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 *)
19931994
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 *)
19941995
| _ ->
19951996
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 & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -983,7 +983,7 @@ struct
983983
do_eval_offset x offs l o
984984

985985
let update_offset ?(blob_destructive=false) (ask: VDQ.t) (x:t) (offs:offs) (value:t) (exp:exp option) (v:lval) (t:typ): t =
986-
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? *)
986+
let rec do_update_offset ?(bitfield:int option=None) (x:t) (offs:offs) (l:lval option) (o:offset option):t = (* TODO: why does inner t argument change here, but not in eval_offset? *)
987987
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;
988988
let mu = function Blob (Blob (y, s', zeroinit), s, _) -> Blob (y, ID.join s s', zeroinit) | x -> x in
989989
let r =
@@ -994,7 +994,7 @@ struct
994994
begin
995995
let l', o' = shift_one_over l o in
996996
let x = zero_init_calloced_memory zeroinit x t in
997-
mu (Blob (join x (do_update_offset x ofs l' o' t), s, zeroinit))
997+
mu (Blob (join x (do_update_offset x ofs l' o'), s, zeroinit))
998998
end
999999
| Blob (x,s,zeroinit), `Field(f, _) ->
10001000
begin
@@ -1017,9 +1017,9 @@ struct
10171017
| _ -> false
10181018
in
10191019
if do_strong_update then
1020-
Blob ((do_update_offset x offs l' o' t), s, zeroinit)
1020+
Blob ((do_update_offset x offs l' o'), s, zeroinit)
10211021
else
1022-
mu (Blob (join x (do_update_offset x offs l' o' t), s, zeroinit))
1022+
mu (Blob (join x (do_update_offset x offs l' o'), s, zeroinit))
10231023
end
10241024
| Blob (x,s,zeroinit), `NoOffset -> (* `NoOffset is only remaining possibility for Blob here *)
10251025
begin
@@ -1043,9 +1043,9 @@ struct
10431043
end
10441044
in
10451045
if do_strong_update then
1046-
Blob ((do_update_offset x offs l' o' t), s, zeroinit)
1046+
Blob ((do_update_offset x offs l' o'), s, zeroinit)
10471047
else
1048-
mu (Blob (join x (do_update_offset x offs l' o' t), s, zeroinit))
1048+
mu (Blob (join x (do_update_offset x offs l' o'), s, zeroinit))
10491049
end
10501050
| Thread _, _ ->
10511051
(* hack for pthread_t variables *)
@@ -1088,7 +1088,7 @@ struct
10881088
| Struct str ->
10891089
begin
10901090
let l', o' = shift_one_over l o in
1091-
let value' = do_update_offset ~bitfield:fld.fbitfield (Structs.get str fld) offs l' o' t in
1091+
let value' = do_update_offset ~bitfield:fld.fbitfield (Structs.get str fld) offs l' o' in
10921092
Struct (Structs.replace str fld value')
10931093
end
10941094
| Bot ->
@@ -1099,7 +1099,7 @@ struct
10991099
in
11001100
let strc = init_comp fld.fcomp in
11011101
let l', o' = shift_one_over l o in
1102-
Struct (Structs.replace strc fld (do_update_offset Bot offs l' o' t))
1102+
Struct (Structs.replace strc fld (do_update_offset Bot offs l' o'))
11031103
| Top -> M.warn ~category:Imprecise "Trying to update a field, but the struct is unknown"; top ()
11041104
| _ -> M.warn ~category:Imprecise "Trying to update a field, but was not given a struct"; top ()
11051105
end
@@ -1132,8 +1132,8 @@ struct
11321132
top (), offs
11331133
end
11341134
in
1135-
Union (`Lifted fld, do_update_offset tempval tempoffs l' o' t)
1136-
| Bot -> Union (`Lifted fld, do_update_offset Bot offs l' o' t)
1135+
Union (`Lifted fld, do_update_offset tempval tempoffs l' o')
1136+
| Bot -> Union (`Lifted fld, do_update_offset Bot offs l' o')
11371137
| Top -> M.warn ~category:Imprecise "Trying to update a field, but the union is unknown"; top ()
11381138
| _ -> M.warn ~category:Imprecise "Trying to update a field, but was not given a union"; top ()
11391139
end
@@ -1145,7 +1145,7 @@ struct
11451145
| TArray(t1 ,_,_) -> t1
11461146
| _ -> t) in (* This is necessary because t is not a TArray in case of calloc *)
11471147
let e = determine_offset ask l o exp (Some v) in
1148-
let new_value_at_index = do_update_offset (CArrays.get ask x' (e,idx)) offs l' o' t in
1148+
let new_value_at_index = do_update_offset (CArrays.get ask x' (e,idx)) offs l' o' in
11491149
let new_array_value = CArrays.set ask x' (e, idx) new_value_at_index in
11501150
Array new_array_value
11511151
| Bot ->
@@ -1154,15 +1154,15 @@ struct
11541154
| _ -> t, None) in (* This is necessary because t is not a TArray in case of calloc *)
11551155
let x' = CArrays.bot () in
11561156
let e = determine_offset ask l o exp (Some v) in
1157-
let new_value_at_index = do_update_offset Bot offs l' o' t in
1157+
let new_value_at_index = do_update_offset Bot offs l' o' in
11581158
let new_array_value = CArrays.set ask x' (e, idx) new_value_at_index in
11591159
let len_ci = BatOption.bind len (fun e -> Cil.getInteger @@ Cil.constFold true e) in
11601160
let len_id = BatOption.map (IndexDomain.of_int (Cilfacade.ptrdiff_ikind ())) len_ci in
11611161
let newl = BatOption.default (ID.starting (Cilfacade.ptrdiff_ikind ()) Z.zero) len_id in
11621162
let new_array_value = CArrays.update_length newl new_array_value in
11631163
Array new_array_value
11641164
| Top -> M.warn ~category:Imprecise "Trying to update an index, but the array is unknown"; top ()
1165-
| x when GobOption.exists (Z.equal Z.zero) (IndexDomain.to_int idx) -> do_update_offset x offs l' o' t
1165+
| x when GobOption.exists (Z.equal Z.zero) (IndexDomain.to_int idx) -> do_update_offset x offs l' o'
11661166
| _ -> M.warn ~category:Imprecise "Trying to update an index, but was not given an array(%a)" pretty x; top ()
11671167
end
11681168
in mu result
@@ -1174,7 +1174,7 @@ struct
11741174
| Some(Lval (x,o)) -> Some ((x, NoOffset)), Some(o)
11751175
| _ -> None, None
11761176
in
1177-
do_update_offset x offs l o t
1177+
do_update_offset x offs l o
11781178

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

0 commit comments

Comments
 (0)