Skip to content

Commit 6426115

Browse files
Consider pointees separately for refinement
1 parent ea7ee83 commit 6426115

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

src/analyses/baseInvariant.ml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,25 @@ struct
100100
if M.tracing then M.tracel "inv" "st from %a to %a" D.pretty st D.pretty r;
101101
r
102102
)
103+
| Mem (Lval lv), NoOffset ->
104+
let lvals = eval_lv ~man st x in
105+
let res = AD.fold (fun a acc ->
106+
if M.tracing then M.tracel "inv" "Consider case of lval %a = %a" d_lval lv VD.pretty (Address (AD.singleton a));
107+
let st = set' lv (Address (AD.singleton a)) st in
108+
let old_val = get ~man st (AD.singleton a) None in
109+
let old_val = VD.cast (Cilfacade.typeOfLval lv) old_val in (* needed as the type of this pointer may be different *)
110+
(* this what I would originally have liked to do, but eval_rv_lval_refine uses queries and thus stale values *)
111+
(* let old_val = eval_rv_lval_refine ~man st exp x in *)
112+
let old_val = map_oldval old_val (Cilfacade.typeOfLval x) in
113+
let v = apply_invariant ~old_val ~new_val:c' in
114+
if is_some_bot v then
115+
D.join acc (try contra st with Analyses.Deadcode -> D.bot ())
116+
else (
117+
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';
118+
D.join acc (set' x v st)
119+
)
120+
) lvals (D.bot ()) in
121+
res
103122
| Var _, _
104123
| Mem _, _ ->
105124
(* For accesses via pointers, not yet *)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// PARAM: --enable ana.int.interval
2+
3+
int two = 2;
4+
int three = 3;
5+
6+
int main() {
7+
int* ptr;
8+
int top;
9+
10+
if(top) {
11+
ptr = &two;
12+
} else {
13+
ptr = &three;
14+
}
15+
16+
if(*ptr == 2) {
17+
__goblint_check(ptr == &two);
18+
}
19+
20+
return 0;
21+
}

0 commit comments

Comments
 (0)