Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix thread for non-unique spawns #1617

Merged
merged 3 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions src/analyses/threadAnalysis.ml
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,7 @@ struct
let startstate v = D.bot ()

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

let threadspawn ctx ~multiple lval f args fctx =
Expand All @@ -106,9 +104,9 @@ struct
let repeated = D.mem tid ctx.local in
let eff =
match creator with
| `Lifted ctid -> (repeated, TS.singleton ctid, false)
| `Top -> (true, TS.bot (), false)
| `Bot -> (false, TS.bot (), false)
| `Lifted ctid -> (repeated || multiple, TS.singleton ctid, false)
| `Top -> (true, TS.bot (), false)
| `Bot -> (multiple, TS.bot (), false)
in
ctx.sideg tid eff;
D.join ctx.local (D.singleton tid)
Expand Down
26 changes: 26 additions & 0 deletions tests/regression/10-synch/29-multiple-created-only.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// PARAM: --set ana.activated[+] thread --set ana.activated[+] threadid --set ana.thread.domain plain

#include <pthread.h>
#include <stdio.h>

int myglobal;
int myglobal2;

void* bla(void *arg) {
// This is created multiple times, it should race with itself
myglobal = 10; //RACE
return NULL;
}

void* other(void) {
// This is created only once, it should not be marked as non-unique
unknown(bla);
myglobal2 = 30; //NORACE
}

int main(void) {
pthread_t id;
pthread_create(&id, NULL, other, NULL);

return 0;
}
31 changes: 31 additions & 0 deletions tests/regression/10-synch/30-no-crash.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// PARAM: --set ana.context.gas_value 0 --set ana.activated[+] thread --set ana.activated[+] threadid

#include <pthread.h>
#include <stdio.h>

int myglobal;
int myglobal2;

void *t_flurb(void *arg) {
myglobal=40; //RACE
return NULL;
}

void* bla(void *arg) {
return NULL;
}

void *t_fun(void *arg) {
unknown(t_flurb); // NOCRASH
return NULL;
}

int main(void) {
pthread_t id;
pthread_create(&id, NULL, t_fun, NULL);
pthread_create(&id, NULL, t_fun, NULL);

unknown(bla);

return 0;
}
Loading