diff options
Diffstat (limited to 'test/tsan/oob_race.cc')
-rw-r--r-- | test/tsan/oob_race.cc | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/test/tsan/oob_race.cc b/test/tsan/oob_race.cc new file mode 100644 index 000000000..c84e819cb --- /dev/null +++ b/test/tsan/oob_race.cc @@ -0,0 +1,26 @@ +// RUN: %clangxx_tsan -O1 %s -o %t && not %t 2>&1 | FileCheck %s +#include <pthread.h> +#include <stdio.h> +#include <unistd.h> + +const long kOffset = 64*1024; + +void *Thread(void *p) { + sleep(1); + ((char*)p)[-kOffset] = 43; + return 0; +} + +int main() { + char *volatile p0 = new char[16]; + delete[] p0; + char *p = new char[32]; + pthread_t th; + pthread_create(&th, 0, Thread, p); + p[-kOffset] = 42; + pthread_join(th, 0); +} + +// Used to crash with CHECK failed. +// CHECK: WARNING: ThreadSanitizer: data race + |