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