Skip to content

Commit 911f9d9

Browse files
authored
Merge pull request #1914 from goblint/valuedomain-do-offset
Remove constant `do_eval_offset` and `do_update_offset` arguments
2 parents 6218f0c + 23e99b5 commit 911f9d9

File tree

1 file changed

+24
-24
lines changed

1 file changed

+24
-24
lines changed

src/cdomain/value/cdomains/valueDomain.ml

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -907,26 +907,26 @@ struct
907907

908908
(* Funny, this does not compile without the final type annotation! *)
909909
let rec eval_offset (ask: VDQ.t) f (x: t) (offs:offs) (exp:exp option) (v:lval option) (t:typ): t =
910-
let rec do_eval_offset (ask:VDQ.t) f (x:t) (offs:offs) (exp:exp option) (l:lval option) (o:offset option) (v:lval option) (t:typ): t =
910+
let rec do_eval_offset (x:t) (offs:offs) (l:lval option) (o:offset option): t =
911911
if M.tracing then M.traceli "eval_offset" "do_eval_offset %a %a (%a)" pretty x Offs.pretty offs (Pretty.docOpt (CilType.Exp.pretty ())) exp;
912912
let r =
913913
match x, offs with
914914
| Blob((va, _, zeroinit) as c), `Index (_, ox) ->
915915
begin
916916
let l', o' = shift_one_over l o in
917-
let ev = do_eval_offset ask f (Blobs.value c) ox exp l' o' v t in
917+
let ev = do_eval_offset (Blobs.value c) ox l' o' in
918918
zero_init_calloced_memory zeroinit ev t
919919
end
920920
| Blob((va, _, zeroinit) as c), `Field _ ->
921921
begin
922922
let l', o' = shift_one_over l o in
923-
let ev = do_eval_offset ask f (Blobs.value c) offs exp l' o' v t in
923+
let ev = do_eval_offset (Blobs.value c) offs l' o' in
924924
zero_init_calloced_memory zeroinit ev t
925925
end
926926
| Blob((va, _, zeroinit) as c), `NoOffset ->
927927
begin
928928
let l', o' = shift_one_over l o in
929-
let ev = do_eval_offset ask f (Blobs.value c) offs exp l' o' v t in
929+
let ev = do_eval_offset (Blobs.value c) offs l' o' in
930930
zero_init_calloced_memory zeroinit ev t
931931
end
932932
| Bot, _ -> Bot
@@ -938,7 +938,7 @@ struct
938938
| Struct str ->
939939
let x = Structs.get str fld in
940940
let l', o' = shift_one_over l o in
941-
do_eval_offset ask f x offs exp l' o' v t
941+
do_eval_offset x offs l' o'
942942
| Top -> M.info ~category:Imprecise "Trying to read a field, but the struct is unknown"; top ()
943943
| _ -> M.warn ~category:Imprecise ~tags:[Category Program] "Trying to read a field, but was not given a struct"; top ()
944944
end
@@ -953,7 +953,7 @@ struct
953953
| _ ->
954954
let x = cast ~kind:Internal fld.ftype value in (* TODO: proper castkind *)
955955
let l', o' = shift_one_over l o in
956-
do_eval_offset ask f x offs exp l' o' v t)
956+
do_eval_offset x offs l' o')
957957
| Union _ -> top ()
958958
| Top -> M.info ~category:Imprecise "Trying to read a field, but the union is unknown"; top ()
959959
| _ -> M.warn ~category:Imprecise ~tags:[Category Program] "Trying to read a field, but was not given a union"; top ()
@@ -963,12 +963,12 @@ struct
963963
match x with
964964
| Array x ->
965965
let e = determine_offset ask l o exp v in
966-
do_eval_offset ask f (CArrays.get ask x (e, idx)) offs exp l' o' v t
966+
do_eval_offset (CArrays.get ask x (e, idx)) offs l' o'
967967
| Address _ ->
968968
begin
969-
do_eval_offset ask f x offs exp l' o' v t (* this used to be `blob `address -> we ignore the index *)
969+
do_eval_offset x offs l' o' (* this used to be `blob `address -> we ignore the index *)
970970
end
971-
| x when GobOption.exists (Z.equal Z.zero) (IndexDomain.to_int idx) -> eval_offset ask f x offs exp v t
971+
| x when GobOption.exists (Z.equal Z.zero) (IndexDomain.to_int idx) -> eval_offset ask f x offs exp v t (* TODO: why recursive call to outer function? *)
972972
| Top -> M.info ~category:Imprecise "Trying to read an index, but the array is unknown"; top ()
973973
| _ -> M.warn ~category:Imprecise ~tags:[Category Program] "Trying to read an index, but was not given an array (%a)" pretty x; top ()
974974
end
@@ -980,10 +980,10 @@ struct
980980
| Some(Lval (x,o)) -> Some ((x, NoOffset)), Some(o)
981981
| _ -> None, None
982982
in
983-
do_eval_offset ask f x offs exp l o v t
983+
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) (ask:VDQ.t) (x:t) (offs:offs) (value:t) (exp:exp option) (l:lval option) (o:offset 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? *)
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 ask x ofs value exp l' o' v t), s, zeroinit))
997+
mu (Blob (join x (do_update_offset x ofs l' o' t), 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 ask x offs value exp l' o' v t), s, zeroinit)
1020+
Blob ((do_update_offset x offs l' o' t), s, zeroinit)
10211021
else
1022-
mu (Blob (join x (do_update_offset ask x offs value exp l' o' v t), s, zeroinit))
1022+
mu (Blob (join x (do_update_offset x offs l' o' t), 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 ask x offs value exp l' o' v t), s, zeroinit)
1046+
Blob ((do_update_offset x offs l' o' t), s, zeroinit)
10471047
else
1048-
mu (Blob (join x (do_update_offset ask x offs value exp l' o' v t), s, zeroinit))
1048+
mu (Blob (join x (do_update_offset x offs l' o' t), 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 ask (Structs.get str fld) offs value exp l' o' v t in
1091+
let value' = do_update_offset ~bitfield:fld.fbitfield (Structs.get str fld) offs l' o' t 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 ask Bot offs value exp l' o' v t))
1102+
Struct (Structs.replace strc fld (do_update_offset Bot offs l' o' t))
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 ask tempval tempoffs value exp l' o' v t)
1136-
| Bot -> Union (`Lifted fld, do_update_offset ask Bot offs value exp l' o' v t)
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)
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 ask (CArrays.get ask x' (e,idx)) offs value exp l' o' v t in
1148+
let new_value_at_index = do_update_offset (CArrays.get ask x' (e,idx)) offs l' o' t 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 ask Bot offs value exp l' o' v t in
1157+
let new_value_at_index = do_update_offset Bot offs l' o' t 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 ask x offs value exp l' o' v t
1165+
| x when GobOption.exists (Z.equal Z.zero) (IndexDomain.to_int idx) -> do_update_offset x offs l' o' t
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 ask x offs value exp l o v t
1177+
do_update_offset x offs l o t
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)