Skip to content

Commit d42cc11

Browse files
Merge pull request #1701 from goblint/pr_1659_repair
Fix refinement in `baseInvariant` for more complicated lvals
2 parents 1b63914 + b05e305 commit d42cc11

File tree

2 files changed

+31
-7
lines changed

2 files changed

+31
-7
lines changed

src/analyses/baseInvariant.ml

+11-7
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,18 @@ struct
112112
r
113113
)
114114
| Mem (Lval lv), off ->
115-
let lvals = eval_lv ~man st (Mem (Lval lv), off) in
116-
let res = AD.fold (fun a acc ->
115+
(* Underlying lvals (may have offsets themselves), e.g., for struct members NOT including any offset appended to outer Mem *)
116+
let lvals = eval_lv ~man st (Mem (Lval lv), NoOffset) in
117+
(* Additional offset of value being refined in Addr Offset type *)
118+
let original_offset = convert_offset ~man st off in
119+
let res = AD.fold (fun base_a acc ->
117120
Option.bind acc (fun acc ->
118-
match a with
119-
| Addr (base, _) as orig ->
120-
let (a:VD.t) = Address (AD.singleton (AD.Addr.of_var base)) in
121-
if M.tracing then M.tracel "inv" "Consider case of lval %a = %a" d_lval lv VD.pretty a;
122-
let st = set' lv a st in
121+
match base_a with
122+
| Addr _ ->
123+
let (lval_a:VD.t) = Address (AD.singleton base_a) in
124+
if M.tracing then M.tracel "inv" "Consider case of lval %a = %a" d_lval lv VD.pretty lval_a;
125+
let st = set' lv lval_a st in
126+
let orig = AD.Addr.add_offset base_a original_offset in
123127
let old_val = get ~man st (AD.singleton orig) None in
124128
let old_val = VD.cast (Cilfacade.typeOfLval x) old_val in (* needed as the type of this pointer may be different *)
125129
(* this what I would originally have liked to do, but eval_rv_lval_refine uses queries and thus stale values *)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include <goblint.h>
2+
struct aws_al {
3+
unsigned long current_size;
4+
};
5+
6+
struct aws_pq {
7+
int pred;
8+
struct aws_al container;
9+
};
10+
11+
int main() {
12+
struct aws_pq queue = { 0, { 0}};
13+
struct aws_al *const list = &queue.container;
14+
15+
if (list->current_size == 0UL) {
16+
if (list->current_size == 0UL) {
17+
__goblint_check(1); //REACHABLE
18+
}
19+
}
20+
}

0 commit comments

Comments
 (0)