diff options
Diffstat (limited to 'gcc/testsuite/g++.dg/tsan/atomic_free2.C')
-rw-r--r-- | gcc/testsuite/g++.dg/tsan/atomic_free2.C | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/gcc/testsuite/g++.dg/tsan/atomic_free2.C b/gcc/testsuite/g++.dg/tsan/atomic_free2.C new file mode 100644 index 00000000000..7ccaa1a95d9 --- /dev/null +++ b/gcc/testsuite/g++.dg/tsan/atomic_free2.C @@ -0,0 +1,21 @@ +/* { dg-do run } */ +/* { dg-shouldfail "tsan" } */ + +#include <pthread.h> +#include <unistd.h> + +void *Thread(void *a) { + sleep(1); + __atomic_fetch_add((int*)a, 1, __ATOMIC_SEQ_CST); + return 0; +} + +int main() { + int *a = new int(0); + pthread_t t; + pthread_create(&t, 0, Thread, a); + delete a; + pthread_join(t, 0); +} + +/* { dg-output "WARNING: ThreadSanitizer: heap-use-after-free.*(\n|\r\n|\r)" } */ |