Skip to content

Commit e8b56ec

Browse files
Merge pull request #1617 from goblint/issue_1615
Fix `thread` for non-unique spawns
2 parents 39d0a8a + eb149f9 commit e8b56ec

File tree

3 files changed

+61
-6
lines changed

3 files changed

+61
-6
lines changed

src/analyses/threadAnalysis.ml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,7 @@ struct
9595
let startstate v = D.bot ()
9696

9797
let threadenter ctx ~multiple lval f args =
98-
if multiple then
99-
(let tid = ThreadId.get_current_unlift (Analyses.ask_of_ctx ctx) in
100-
ctx.sideg tid (true, TS.bot (), false));
98+
(* ctx is of creator, side-effects to denote non-uniqueness are performed in threadspawn *)
10199
[D.bot ()]
102100

103101
let threadspawn ctx ~multiple lval f args fctx =
@@ -106,9 +104,9 @@ struct
106104
let repeated = D.mem tid ctx.local in
107105
let eff =
108106
match creator with
109-
| `Lifted ctid -> (repeated, TS.singleton ctid, false)
110-
| `Top -> (true, TS.bot (), false)
111-
| `Bot -> (false, TS.bot (), false)
107+
| `Lifted ctid -> (repeated || multiple, TS.singleton ctid, false)
108+
| `Top -> (true, TS.bot (), false)
109+
| `Bot -> (multiple, TS.bot (), false)
112110
in
113111
ctx.sideg tid eff;
114112
D.join ctx.local (D.singleton tid)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// PARAM: --set ana.activated[+] thread --set ana.activated[+] threadid --set ana.thread.domain plain
2+
3+
#include <pthread.h>
4+
#include <stdio.h>
5+
6+
int myglobal;
7+
int myglobal2;
8+
9+
void* bla(void *arg) {
10+
// This is created multiple times, it should race with itself
11+
myglobal = 10; //RACE
12+
return NULL;
13+
}
14+
15+
void* other(void) {
16+
// This is created only once, it should not be marked as non-unique
17+
unknown(bla);
18+
myglobal2 = 30; //NORACE
19+
}
20+
21+
int main(void) {
22+
pthread_t id;
23+
pthread_create(&id, NULL, other, NULL);
24+
25+
return 0;
26+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// PARAM: --set ana.context.gas_value 0 --set ana.activated[+] thread --set ana.activated[+] threadid
2+
3+
#include <pthread.h>
4+
#include <stdio.h>
5+
6+
int myglobal;
7+
int myglobal2;
8+
9+
void *t_flurb(void *arg) {
10+
myglobal=40; //RACE
11+
return NULL;
12+
}
13+
14+
void* bla(void *arg) {
15+
return NULL;
16+
}
17+
18+
void *t_fun(void *arg) {
19+
unknown(t_flurb); // NOCRASH
20+
return NULL;
21+
}
22+
23+
int main(void) {
24+
pthread_t id;
25+
pthread_create(&id, NULL, t_fun, NULL);
26+
pthread_create(&id, NULL, t_fun, NULL);
27+
28+
unknown(bla);
29+
30+
return 0;
31+
}

0 commit comments

Comments
 (0)