Skip to content

Commit bffc5e3

Browse files
Merge pull request #1458 from goblint/issue1457
`BaseAnalysis`: For non-definite AD, join over **all** components not just `cpa` in `set`
2 parents 91dce01 + d1ed12c commit bffc5e3

10 files changed

+492
-1
lines changed

src/analyses/base.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1738,7 +1738,7 @@ struct
17381738
(* if M.tracing then M.tracel "set" ~var:firstvar "new state1 %a" CPA.pretty nst; *)
17391739
(* If the address was definite, then we just return it. If the address
17401740
* was ambiguous, we have to join it with the initial state. *)
1741-
let nst = if AD.cardinal lval > 1 then { nst with cpa = CPA.join st.cpa nst.cpa } else nst in
1741+
let nst = if AD.cardinal lval > 1 then D.join st nst else nst in
17421742
(* if M.tracing then M.tracel "set" ~var:firstvar "new state2 %a" CPA.pretty nst; *)
17431743
nst
17441744
with
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// PARAM: --set ana.base.privatization protection --enable ana.int.enums
2+
#include<pthread.h>
3+
#include<stdlib.h>
4+
struct a {
5+
int b;
6+
};
7+
8+
struct a *ptr;
9+
struct a *straightandnarrow;
10+
11+
pthread_mutex_t m;
12+
13+
void doit() {
14+
void *newa = malloc(sizeof(struct a));
15+
16+
pthread_mutex_lock(&m);
17+
ptr->b = 5;
18+
19+
int fear = straightandnarrow->b;
20+
__goblint_check(fear == 5); //UNKNOWN!
21+
22+
ptr = newa;
23+
pthread_mutex_unlock(&m);
24+
25+
pthread_mutex_lock(&m);
26+
int hope = straightandnarrow->b;
27+
__goblint_check(hope == 5); //UNKNOWN!
28+
pthread_mutex_unlock(&m);
29+
30+
}
31+
32+
void* k(void *arg) {
33+
doit();
34+
return NULL;
35+
}
36+
37+
int main() {
38+
int top;
39+
struct a other = { 0 };
40+
struct a other2 = { 42 };
41+
if(top) {
42+
ptr = &other;
43+
} else {
44+
ptr = &other2;
45+
}
46+
47+
straightandnarrow = &other;
48+
49+
pthread_t t1;
50+
pthread_create(&t1, 0, k, 0);
51+
52+
doit();
53+
return 0;
54+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// PARAM: --set ana.base.privatization protection --enable ana.int.enums
2+
// Like 80-nondet-struct-ptr.c, but somewhat simplified to not use structs and malloc etc
3+
#include<pthread.h>
4+
#include<stdlib.h>
5+
struct a {
6+
int b;
7+
};
8+
9+
int *ptr;
10+
int *immer_da_oane;
11+
12+
pthread_mutex_t m;
13+
14+
void doit() {
15+
pthread_mutex_lock(&m);
16+
*ptr = 5;
17+
18+
// Should be either 5 or 0, depending on which one the pointer points to
19+
int fear = *immer_da_oane;
20+
__goblint_check(fear == 5); //UNKNOWN!
21+
22+
pthread_mutex_unlock(&m);
23+
24+
pthread_mutex_lock(&m);
25+
int hope = *immer_da_oane;
26+
__goblint_check(hope == 5); //UNKNOWN!
27+
pthread_mutex_unlock(&m);
28+
29+
}
30+
31+
void* k(void *arg) {
32+
// Force MT
33+
return NULL;
34+
}
35+
36+
int main() {
37+
int top;
38+
39+
int da_oane = 0;
40+
int de_andre = 42;
41+
42+
if(top) {
43+
ptr = &da_oane;
44+
} else {
45+
ptr = &de_andre;
46+
}
47+
48+
immer_da_oane = &da_oane;
49+
50+
pthread_t t1;
51+
pthread_create(&t1, 0, k, 0);
52+
53+
doit();
54+
return 0;
55+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// PARAM: --set ana.base.privatization protection --enable ana.int.enums
2+
// Like 81-nondet-struct-ptr.c, but with syntactic globals instead of escaping ones.
3+
#include<pthread.h>
4+
#include<stdlib.h>
5+
struct a {
6+
int b;
7+
};
8+
9+
int *ptr;
10+
int *immer_da_oane;
11+
12+
int da_oane = 0;
13+
int de_andre = 42;
14+
15+
pthread_mutex_t m;
16+
17+
void doit() {
18+
pthread_mutex_lock(&m);
19+
*ptr = 5;
20+
21+
// Should be either 0 or 5, depending on which one ptr points to
22+
int fear = *immer_da_oane;
23+
__goblint_check(fear == 5); //UNKNOWN!
24+
25+
pthread_mutex_unlock(&m);
26+
27+
pthread_mutex_lock(&m);
28+
// This works
29+
int hope = *immer_da_oane;
30+
__goblint_check(hope == 5); //UNKNOWN!
31+
pthread_mutex_unlock(&m);
32+
33+
}
34+
35+
void* k(void *arg) {
36+
// Force MT
37+
return NULL;
38+
}
39+
40+
int main() {
41+
int top;
42+
43+
if(top) {
44+
ptr = &da_oane;
45+
} else {
46+
ptr = &de_andre;
47+
}
48+
49+
immer_da_oane = &da_oane;
50+
51+
pthread_t t1;
52+
pthread_create(&t1, 0, k, 0);
53+
54+
doit();
55+
return 0;
56+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// PARAM: --set ana.base.privatization write --enable ana.int.enums
2+
#include<pthread.h>
3+
#include<stdlib.h>
4+
struct a {
5+
int b;
6+
};
7+
8+
struct a *ptr;
9+
struct a *straightandnarrow;
10+
11+
pthread_mutex_t m;
12+
13+
void doit() {
14+
void *newa = malloc(sizeof(struct a));
15+
16+
pthread_mutex_lock(&m);
17+
ptr->b = 5;
18+
19+
int fear = straightandnarrow->b;
20+
__goblint_check(fear == 5); //UNKNOWN!
21+
22+
ptr = newa;
23+
pthread_mutex_unlock(&m);
24+
25+
pthread_mutex_lock(&m);
26+
int hope = straightandnarrow->b;
27+
__goblint_check(hope == 5); //UNKNOWN!
28+
pthread_mutex_unlock(&m);
29+
30+
}
31+
32+
void* k(void *arg) {
33+
doit();
34+
return NULL;
35+
}
36+
37+
int main() {
38+
int top;
39+
struct a other = { 0 };
40+
struct a other2 = { 42 };
41+
if(top) {
42+
ptr = &other;
43+
} else {
44+
ptr = &other2;
45+
}
46+
47+
straightandnarrow = &other;
48+
49+
pthread_t t1;
50+
pthread_create(&t1, 0, k, 0);
51+
52+
doit();
53+
return 0;
54+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// PARAM: --set ana.base.privatization write --enable ana.int.enums
2+
#include<pthread.h>
3+
#include<stdlib.h>
4+
struct a {
5+
int b;
6+
};
7+
8+
int *ptr;
9+
int *immer_da_oane;
10+
11+
pthread_mutex_t m;
12+
13+
void doit() {
14+
pthread_mutex_lock(&m);
15+
*ptr = 5;
16+
17+
// Should be either 5 or 0, depending on which one the pointer points to
18+
int fear = *immer_da_oane;
19+
__goblint_check(fear == 5); //UNKNOWN!
20+
21+
pthread_mutex_unlock(&m);
22+
23+
pthread_mutex_lock(&m);
24+
int hope = *immer_da_oane;
25+
__goblint_check(hope == 5); //UNKNOWN!
26+
pthread_mutex_unlock(&m);
27+
28+
}
29+
30+
void* k(void *arg) {
31+
// Force MT
32+
return NULL;
33+
}
34+
35+
int main() {
36+
int top;
37+
38+
int da_oane = 0;
39+
int de_andre = 42;
40+
41+
if(top) {
42+
ptr = &da_oane;
43+
} else {
44+
ptr = &de_andre;
45+
}
46+
47+
immer_da_oane = &da_oane;
48+
49+
pthread_t t1;
50+
pthread_create(&t1, 0, k, 0);
51+
52+
doit();
53+
return 0;
54+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// PARAM: --set ana.base.privatization write --enable ana.int.enums
2+
#include<pthread.h>
3+
#include<stdlib.h>
4+
struct a {
5+
int b;
6+
};
7+
8+
int *ptr;
9+
int *immer_da_oane;
10+
11+
int da_oane = 0;
12+
int de_andre = 42;
13+
14+
pthread_mutex_t m;
15+
16+
void doit() {
17+
pthread_mutex_lock(&m);
18+
*ptr = 5;
19+
20+
// Should be either 0 or 5, depending on which one ptr points to
21+
int fear = *immer_da_oane;
22+
__goblint_check(fear == 5); //UNKNOWN!
23+
24+
pthread_mutex_unlock(&m);
25+
26+
pthread_mutex_lock(&m);
27+
// This works
28+
int hope = *immer_da_oane;
29+
__goblint_check(hope == 5); //UNKNOWN!
30+
pthread_mutex_unlock(&m);
31+
32+
}
33+
34+
void* k(void *arg) {
35+
// Force MT
36+
return NULL;
37+
}
38+
39+
int main() {
40+
int top;
41+
42+
if(top) {
43+
ptr = &da_oane;
44+
} else {
45+
ptr = &de_andre;
46+
}
47+
48+
immer_da_oane = &da_oane;
49+
50+
pthread_t t1;
51+
pthread_create(&t1, 0, k, 0);
52+
53+
doit();
54+
return 0;
55+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// PARAM: --set ana.base.privatization lock --enable ana.int.enums
2+
#include<pthread.h>
3+
#include<stdlib.h>
4+
struct a {
5+
int b;
6+
};
7+
8+
struct a *ptr;
9+
struct a *straightandnarrow;
10+
11+
pthread_mutex_t m;
12+
13+
void doit() {
14+
void *newa = malloc(sizeof(struct a));
15+
16+
pthread_mutex_lock(&m);
17+
ptr->b = 5;
18+
19+
int fear = straightandnarrow->b;
20+
__goblint_check(fear == 5); //UNKNOWN!
21+
22+
ptr = newa;
23+
pthread_mutex_unlock(&m);
24+
25+
pthread_mutex_lock(&m);
26+
int hope = straightandnarrow->b;
27+
__goblint_check(hope == 5); //UNKNOWN!
28+
pthread_mutex_unlock(&m);
29+
30+
}
31+
32+
void* k(void *arg) {
33+
doit();
34+
return NULL;
35+
}
36+
37+
int main() {
38+
int top;
39+
struct a other = { 0 };
40+
struct a other2 = { 42 };
41+
if(top) {
42+
ptr = &other;
43+
} else {
44+
ptr = &other2;
45+
}
46+
47+
straightandnarrow = &other;
48+
49+
pthread_t t1;
50+
pthread_create(&t1, 0, k, 0);
51+
52+
doit();
53+
return 0;
54+
}

0 commit comments

Comments
 (0)