Skip to content

Commit cc4a935

Browse files
Merge pull request #1468 from goblint/issue_1467
Make meet in AddressDomain more precise
2 parents f214ec5 + 7f60099 commit cc4a935

File tree

4 files changed

+96
-3
lines changed

4 files changed

+96
-3
lines changed

src/analyses/base.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1613,7 +1613,7 @@ struct
16131613
let set ~(man: _ man) ?(invariant=false) ?(blob_destructive=false) ?lval_raw ?rval_raw ?t_override (st: store) (lval: AD.t) (lval_type: Cil.typ) (value: value) : store =
16141614
let update_variable x t y z =
16151615
if M.tracing then M.tracel "set" ~var:x.vname "update_variable: start '%s' '%a'\nto\n%a" x.vname VD.pretty y CPA.pretty z;
1616-
let r = update_variable x t y z in (* refers to defintion that is outside of set *)
1616+
let r = update_variable x t y z in (* refers to definition that is outside of set *)
16171617
if M.tracing then M.tracel "set" ~var:x.vname "update_variable: start '%s' '%a'\nto\n%a\nresults in\n%a" x.vname VD.pretty y CPA.pretty z CPA.pretty r;
16181618
r
16191619
in

src/domain/disjointDomain.ml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,14 +184,25 @@ sig
184184
val may_be_equal: elt -> elt -> bool
185185
end
186186

187-
module ProjectiveSetPairwiseMeet (E: Printable.S) (B: MayEqualSetDomain with type elt = E.t) (R: Representative with type elt = E.t): SetDomain.S with type elt = E.t = struct
187+
module ProjectiveSetPairwiseMeet (E: Lattice.S) (B: MayEqualSetDomain with type elt = E.t) (R: Representative with type elt = E.t): SetDomain.S with type elt = E.t = struct
188188
include ProjectiveSet (E) (B) (R)
189189

190190
let meet m1 m2 =
191191
let meet_buckets b1 b2 acc =
192192
B.fold (fun e1 acc ->
193+
let r1 = R.of_elt e1 in
193194
B.fold (fun e2 acc ->
194-
if B.may_be_equal e1 e2 then
195+
(* If they have the same representative, we use the normal meet within this bucket *)
196+
if R.equal r1 (R.of_elt e2) then
197+
try
198+
let m = E.meet e1 e2 in
199+
if not (E.is_bot m) then
200+
add m acc
201+
else
202+
acc
203+
with Lattice.Uncomparable ->
204+
failwith (GobPretty.sprintf "Elements %a and %a are in same bucket, but meet throws!" E.pretty e1 E.pretty e2)
205+
else if B.may_be_equal e1 e2 then
195206
add e1 (add e2 acc)
196207
else
197208
acc
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// PARAM: --set ana.base.privatization write
2+
#include<pthread.h>
3+
struct a {
4+
char* b;
5+
};
6+
7+
struct a *c;
8+
struct a h = {""};
9+
struct a i = {"string"};
10+
11+
void* d(void* args) {
12+
if (c->b) {
13+
// Handled by privatization as a write
14+
// Without fix (#1468) causes both h.b and i.b to become unknown string
15+
__goblint_check(strlen(h.b) == 0); // Check h.b is still known
16+
}
17+
}
18+
19+
int main() {
20+
int top;
21+
22+
if(top) {
23+
c = &h;
24+
} else {
25+
c = &i;
26+
}
27+
28+
pthread_t t;
29+
pthread_create(&t, 0, d, 0);
30+
return 0;
31+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
//PARAM: --enable ana.int.interval
2+
#include <stdio.h>
3+
#include <stdlib.h>
4+
#include <time.h>
5+
6+
int more_intricate() {
7+
int arr[20];
8+
9+
int top;
10+
11+
int i = 2;
12+
int j = 8;
13+
if(top) {
14+
i = 8;
15+
j = 9;
16+
}
17+
18+
int* imprecise1 = &arr[i]; // &arr[2..8]
19+
int* imprecise2 = &arr[j]; // &arr[8..9]
20+
21+
if(imprecise1 == imprecise2) {
22+
__goblint_check(imprecise1 == &arr[8]);
23+
__goblint_check(imprecise2 == &arr[8]); //TODO (Refinement should happen in both directions!)
24+
}
25+
26+
if(imprecise1 == &arr[j]) {
27+
__goblint_check(imprecise1 == &arr[8]);
28+
}
29+
30+
}
31+
32+
33+
int main() {
34+
int arr[20];
35+
36+
int top;
37+
38+
int i = 2;
39+
if(top) {
40+
i = 8;
41+
}
42+
43+
int* imprecise = &arr[i];
44+
45+
if(imprecise == &arr[2]) {
46+
__goblint_check(imprecise == &arr[2]);
47+
}
48+
49+
more_intricate();
50+
return 0;
51+
}

0 commit comments

Comments
 (0)