summaryrefslogtreecommitdiff
path: root/test/tsan
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2014-10-13 08:46:25 +0000
committerDmitry Vyukov <dvyukov@google.com>2014-10-13 08:46:25 +0000
commit17c47bfd1adf4d4d38d5a7653fdf0ac09a346a3e (patch)
treeab159db1c35f4c1b336e276e9c3f128e5d32cae8 /test/tsan
parentc2061931d92911b7608526571cc95eb07835ee2a (diff)
tsan: better reporting for virtual-call-after-free
Previously we said that it's a data race, which is confusing if it happens in the same thread. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@219600 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/tsan')
-rw-r--r--test/tsan/vptr_harmful_race4.cc34
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)
+