diff options
author | Dmitry Vyukov <dvyukov@google.com> | 2014-10-13 08:46:25 +0000 |
---|---|---|
committer | Dmitry Vyukov <dvyukov@google.com> | 2014-10-13 08:46:25 +0000 |
commit | 02ff8bb98671bdeebcc363d2cf031fc7eb51f364 (patch) | |
tree | 02b3e66c2db5b93ece342ff3d8c93b372d0da9a7 /compiler-rt | |
parent | b20597810086a6314a5801f7a2cdf03fb534a461 (diff) | |
download | bcm5719-llvm-02ff8bb98671bdeebcc363d2cf031fc7eb51f364.tar.gz bcm5719-llvm-02ff8bb98671bdeebcc363d2cf031fc7eb51f364.zip |
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.
llvm-svn: 219600
Diffstat (limited to 'compiler-rt')
-rw-r--r-- | compiler-rt/lib/tsan/rtl/tsan_report.cc | 2 | ||||
-rw-r--r-- | compiler-rt/lib/tsan/rtl/tsan_report.h | 1 | ||||
-rw-r--r-- | compiler-rt/lib/tsan/rtl/tsan_rtl_report.cc | 4 | ||||
-rw-r--r-- | compiler-rt/lib/tsan/rtl/tsan_suppressions.cc | 2 | ||||
-rw-r--r-- | compiler-rt/test/tsan/vptr_harmful_race4.cc | 34 |
5 files changed, 42 insertions, 1 deletions
diff --git a/compiler-rt/lib/tsan/rtl/tsan_report.cc b/compiler-rt/lib/tsan/rtl/tsan_report.cc index e14d0b966ae..c5b5c743469 100644 --- a/compiler-rt/lib/tsan/rtl/tsan_report.cc +++ b/compiler-rt/lib/tsan/rtl/tsan_report.cc @@ -70,6 +70,8 @@ static const char *ReportTypeString(ReportType typ) { return "data race on vptr (ctor/dtor vs virtual call)"; if (typ == ReportTypeUseAfterFree) return "heap-use-after-free"; + if (typ == ReportTypeVptrUseAfterFree) + return "heap-use-after-free (virtual call vs free)"; if (typ == ReportTypeThreadLeak) return "thread leak"; if (typ == ReportTypeMutexDestroyLocked) diff --git a/compiler-rt/lib/tsan/rtl/tsan_report.h b/compiler-rt/lib/tsan/rtl/tsan_report.h index 8ea977444fc..ae202341b9b 100644 --- a/compiler-rt/lib/tsan/rtl/tsan_report.h +++ b/compiler-rt/lib/tsan/rtl/tsan_report.h @@ -22,6 +22,7 @@ enum ReportType { ReportTypeRace, ReportTypeVptrRace, ReportTypeUseAfterFree, + ReportTypeVptrUseAfterFree, ReportTypeThreadLeak, ReportTypeMutexDestroyLocked, ReportTypeMutexDoubleLock, diff --git a/compiler-rt/lib/tsan/rtl/tsan_rtl_report.cc b/compiler-rt/lib/tsan/rtl/tsan_rtl_report.cc index b7a48049022..bdffb19ba0f 100644 --- a/compiler-rt/lib/tsan/rtl/tsan_rtl_report.cc +++ b/compiler-rt/lib/tsan/rtl/tsan_rtl_report.cc @@ -627,7 +627,9 @@ void ReportRace(ThreadState *thr) { ThreadRegistryLock l0(ctx->thread_registry); ReportType typ = ReportTypeRace; - if (thr->is_vptr_access) + if (thr->is_vptr_access && freed) + typ = ReportTypeVptrUseAfterFree; + else if (thr->is_vptr_access) typ = ReportTypeVptrRace; else if (freed) typ = ReportTypeUseAfterFree; diff --git a/compiler-rt/lib/tsan/rtl/tsan_suppressions.cc b/compiler-rt/lib/tsan/rtl/tsan_suppressions.cc index aa63c92588f..a243300770a 100644 --- a/compiler-rt/lib/tsan/rtl/tsan_suppressions.cc +++ b/compiler-rt/lib/tsan/rtl/tsan_suppressions.cc @@ -60,6 +60,8 @@ SuppressionType conv(ReportType typ) { return SuppressionRace; else if (typ == ReportTypeUseAfterFree) return SuppressionRace; + else if (typ == ReportTypeVptrUseAfterFree) + return SuppressionRace; else if (typ == ReportTypeThreadLeak) return SuppressionThread; else if (typ == ReportTypeMutexDestroyLocked) diff --git a/compiler-rt/test/tsan/vptr_harmful_race4.cc b/compiler-rt/test/tsan/vptr_harmful_race4.cc new file mode 100644 index 00000000000..969c9d58a01 --- /dev/null +++ b/compiler-rt/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) + |