diff options
Diffstat (limited to 'test/tsan/vptr_harmful_race4.cc')
-rw-r--r-- | test/tsan/vptr_harmful_race4.cc | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/test/tsan/vptr_harmful_race4.cc b/test/tsan/vptr_harmful_race4.cc new file mode 100644 index 000000000..969c9d58a --- /dev/null +++ b/test/tsan/vptr_harmful_race4.cc @@ -0,0 +1,34 @@ +// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s +#include <pthread.h> +#include <stdio.h> +#include <unistd.h> + +struct A { + virtual void F() { + } + + virtual ~A() { + } +}; + +struct B : A { + virtual void F() { + } +}; + +void *Thread(void *x) { + sleep(1); + ((A*)x)->F(); + return 0; +} + +int main() { + A *obj = new B; + pthread_t t; + pthread_create(&t, 0, Thread, obj); + delete obj; + pthread_join(t, 0); +} + +// CHECK: WARNING: ThreadSanitizer: heap-use-after-free (virtual call vs free) + |