Skip to content

Commit e789a66

Browse files
committed
Rewrite base pointer refinement by pointee using trick from set (issue #1967)
1 parent 3b9ed98 commit e789a66

1 file changed

Lines changed: 17 additions & 7 deletions

File tree

src/analyses/baseInvariant.ml

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,13 @@ struct
117117
let lvals = eval_lv ~man st (Mem (Lval lv), NoOffset) in
118118
(* Additional offset of value being refined in Addr Offset type *)
119119
let original_offset = convert_offset ~man st off in
120-
let res = AD.fold (fun base_a acc ->
121-
Option.bind acc (fun acc ->
120+
let res = AD.fold (fun base_a st ->
121+
Option.bind st (fun (st, ad) ->
122122
match base_a with
123123
| Addr base_mval ->
124124
let (lval_a:VD.t) = Address (AD.singleton base_a) in
125125
if M.tracing then M.tracel "inv" "Consider case of lval %a = %a" d_lval lv VD.pretty lval_a;
126-
let st = set' lv lval_a st in
126+
(* let st = set' lv lval_a st in *)
127127
let orig = PreValueDomain.Addr.Mval.add_offset base_mval original_offset in
128128
let old_val = get_mval ~man st orig None in
129129
let old_val = VD.cast ~kind:Internal (Cilfacade.typeOfLval x) old_val in (* needed as the type of this pointer may be different *) (* TODO: proper castkind *)
@@ -132,16 +132,26 @@ struct
132132
let old_val = map_oldval old_val (Cilfacade.typeOfLval x) in
133133
let v = apply_invariant ~old_val ~new_val:c' in
134134
if is_some_bot v then
135-
Some (D.join acc (try contra st with Analyses.Deadcode -> D.bot ()))
135+
Some (st, ad) (* TODO: some contra thing? *)
136136
else (
137137
if M.tracing then M.tracel "inv" "improve lval %a from %a to %a (c = %a, c' = %a)" d_lval x VD.pretty old_val VD.pretty v pretty c VD.pretty c';
138-
Some (D.join acc (set' x v st))
138+
Some (set' x v st, AD.add base_a ad)
139139
)
140140
| _ -> None
141141
)
142-
) lvals (Some (D.bot ()))
142+
) lvals (Some (st, AD.empty ()))
143143
in
144-
BatOption.map_default_delayed (fun d -> if D.is_bot d then raise Analyses.Deadcode else d) default res
144+
BatOption.map_default_delayed (fun (d, ad) ->
145+
if AD.is_bot ad then
146+
raise Analyses.Deadcode
147+
else (
148+
let d = set' lv (Address ad) d in
149+
if AD.cardinal ad > 1 then
150+
D.join st d
151+
else
152+
d
153+
)
154+
) default res
145155
| Var _, _
146156
| Mem _, _ ->
147157
default ()

0 commit comments

Comments
 (0)