-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1247 from goblint/region-escape-svcomp
Fix region escaping in per-thread-array-init-race
- Loading branch information
Showing
4 changed files
with
72 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
tests/regression/09-regions/41-per-thread-array-init-race.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// PARAM: --set ana.activated[+] region --enable ana.sv-comp.functions | ||
// Per-thread array pointers passed via argument but initialized before thread create. | ||
// Extracted from silver searcher. | ||
#include <stdlib.h> | ||
#include <pthread.h> | ||
extern void abort(void); | ||
void assume_abort_if_not(int cond) { | ||
if(!cond) {abort();} | ||
} | ||
extern int __VERIFIER_nondet_int(); | ||
|
||
void *thread(void *arg) { | ||
int *p = arg; | ||
int i = *p; // RACE! | ||
return NULL; | ||
} | ||
|
||
int main() { | ||
int threads_total = __VERIFIER_nondet_int(); | ||
assume_abort_if_not(threads_total >= 0); | ||
|
||
pthread_t *tids = malloc(threads_total * sizeof(pthread_t)); | ||
int *is = calloc(threads_total, sizeof(int)); | ||
|
||
// create threads | ||
for (int i = 0; i < threads_total; i++) { | ||
pthread_create(&tids[i], NULL, &thread, &is[i]); // may fail but doesn't matter | ||
is[i] = i; // RACE! | ||
} | ||
|
||
// join threads | ||
for (int i = 0; i < threads_total; i++) { | ||
pthread_join(tids[i], NULL); | ||
} | ||
|
||
free(tids); | ||
free(is); | ||
|
||
return 0; | ||
} |