Skip to content

Commit dc0c3e3

Browse files
Add problematic examples for #1457
1 parent 5cd8650 commit dc0c3e3

9 files changed

+495
-0
lines changed
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-treachery-and-lies.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-how-could-we-have-been-so-blind.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: 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+
// Like 80-treachery-and-lies.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 write --enable ana.int.enums
2+
// Like 81-how-could-we-have-been-so-blind.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 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)