Skip to content

Commit 8eb3d72

Browse files
Do not swallow dead code and add example
1 parent 939cec3 commit 8eb3d72

File tree

2 files changed

+36
-5
lines changed

2 files changed

+36
-5
lines changed

src/analyses/baseInvariant.ml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ struct
102102
)
103103
| Mem (Lval lv), NoOffset ->
104104
let lvals = eval_lv ~man st x in
105-
let res = AD.fold (fun a acc ->
105+
let res = AD.fold (fun a acc ->
106106
if M.tracing then M.tracel "inv" "Consider case of lval %a = %a" d_lval lv VD.pretty (Address (AD.singleton a));
107107
let st = set' lv (Address (AD.singleton a)) st in
108108
let old_val = get ~man st (AD.singleton a) None in
@@ -111,14 +111,18 @@ struct
111111
(* let old_val = eval_rv_lval_refine ~man st exp x in *)
112112
let old_val = map_oldval old_val (Cilfacade.typeOfLval x) in
113113
let v = apply_invariant ~old_val ~new_val:c' in
114-
if is_some_bot v then
114+
if is_some_bot v then
115115
D.join acc (try contra st with Analyses.Deadcode -> D.bot ())
116116
else (
117117
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';
118118
D.join acc (set' x v st)
119-
)
120-
) lvals (D.bot ()) in
121-
res
119+
)
120+
) lvals (D.bot ())
121+
in
122+
if D.is_bot res then
123+
raise Analyses.Deadcode
124+
else
125+
res
122126
| Var _, _
123127
| Mem _, _ ->
124128
(* For accesses via pointers, not yet *)
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// PARAM: --enable ana.int.interval
2+
3+
int two = 2;
4+
int three = 5;
5+
6+
int main() {
7+
int* ptr;
8+
int top;
9+
10+
int indicator = 1;
11+
12+
if(top) {
13+
ptr = &two;
14+
} else {
15+
ptr = &three;
16+
}
17+
18+
// Evaluating this in the interval domain yields [2,5]
19+
// Only trying to optimize per-pointer discovers that this in fact dead code (https://github.com/goblint/analyzer/pull/1659)
20+
if(*ptr == 3) {
21+
// Dead
22+
indicator = 0;
23+
}
24+
25+
__goblint_check(indicator == 1);
26+
return 0;
27+
}

0 commit comments

Comments
 (0)