1 | // RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s |
2 | #include "test.h" |
3 | |
4 | struct A { |
5 | virtual void F() { |
6 | } |
7 | |
8 | virtual ~A() { |
9 | } |
10 | }; |
11 | |
12 | struct B : A { |
13 | virtual void F() { |
14 | } |
15 | }; |
16 | |
17 | void *Thread(void *x) { |
18 | barrier_wait(barrier: &barrier); |
19 | ((A*)x)->F(); |
20 | return 0; |
21 | } |
22 | |
23 | int main() { |
24 | barrier_init(barrier: &barrier, count: 2); |
25 | A *obj = new B; |
26 | pthread_t t; |
27 | pthread_create(newthread: &t, attr: 0, start_routine: Thread, arg: obj); |
28 | delete obj; |
29 | barrier_wait(barrier: &barrier); |
30 | pthread_join(th: t, thread_return: 0); |
31 | } |
32 | |
33 | // CHECK: WARNING: ThreadSanitizer: heap-use-after-free (virtual call vs free) |
34 | |
35 | |