[compiler-rt] r182354 - tsan: detect when a thread ends with ignores enabled

Kostya Serebryany kcc at google.com
Tue May 21 01:24:21 PDT 2013


On Tue, May 21, 2013 at 12:12 PM, Dmitry Vyukov <dvyukov at google.com> wrote:

> Author: dvyukov
> Date: Tue May 21 03:12:35 2013
> New Revision: 182354
>
> URL: http://llvm.org/viewvc/llvm-project?rev=182354&view=rev
> Log:
> tsan: detect when a thread ends with ignores enabled
>
> Added:
>     compiler-rt/trunk/lib/tsan/lit_tests/thread_end_with_ignore.cc
>     compiler-rt/trunk/lib/tsan/lit_tests/thread_end_with_ignore2.cc
> Modified:
>     compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.cc
>     compiler-rt/trunk/lib/tsan/rtl/tsan_rtl_thread.cc
>
> Added: compiler-rt/trunk/lib/tsan/lit_tests/thread_end_with_ignore.cc
> URL:
> http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/lit_tests/thread_end_with_ignore.cc?rev=182354&view=auto
>
> ==============================================================================
> --- compiler-rt/trunk/lib/tsan/lit_tests/thread_end_with_ignore.cc (added)
> +++ compiler-rt/trunk/lib/tsan/lit_tests/thread_end_with_ignore.cc Tue May
> 21 03:12:35 2013
> @@ -0,0 +1,19 @@
> +// RUN: %clangxx_tsan -O1 %s -o %t && %t 2>&1 | FileCheck %s
> +#include <pthread.h>
> +#include <stdio.h>
> +
> +extern "C" void AnnotateIgnoreReadsBegin(const char *f, int l);
> +
> +void *Thread(void *x) {
> +  AnnotateIgnoreReadsBegin("", 0);
> +  return 0;
> +}
> +
> +int main() {
> +  pthread_t t;
> +  pthread_create(&t, 0, Thread, 0);
> +  pthread_join(t, 0);
> +}
> +
> +// CHECK: ThreadSanitizer: thread T1 finished with ignores enabled
> +
>
> Added: compiler-rt/trunk/lib/tsan/lit_tests/thread_end_with_ignore2.cc
> URL:
> http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/lit_tests/thread_end_with_ignore2.cc?rev=182354&view=auto
>
> ==============================================================================
> --- compiler-rt/trunk/lib/tsan/lit_tests/thread_end_with_ignore2.cc (added)
> +++ compiler-rt/trunk/lib/tsan/lit_tests/thread_end_with_ignore2.cc Tue
> May 21 03:12:35 2013
> @@ -0,0 +1,9 @@
> +// RUN: %clangxx_tsan -O1 %s -o %t && %t 2>&1 | FileCheck %s
> +extern "C" void AnnotateIgnoreWritesBegin(const char *f, int l);
> +
> +int main() {
> +  AnnotateIgnoreWritesBegin("", 0);
> +}
> +
> +// CHECK: ThreadSanitizer: thread T0 finished with ignores enabled
> +
>
> Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.cc
> URL:
> http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.cc?rev=182354&r1=182353&r2=182354&view=diff
>
> ==============================================================================
> --- compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.cc (original)
> +++ compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.cc Tue May 21 03:12:35 2013
> @@ -84,8 +84,7 @@ ThreadState::ThreadState(Context *ctx, i
>    : fast_state(tid, epoch)
>    // Do not touch these, rely on zero initialization,
>    // they may be accessed before the ctor.
> -  // , fast_ignore_reads()
> -  // , fast_ignore_writes()
> +  // , ignore_reads_and_writes()
>    // , in_rtl()
>    , shadow_stack_pos(&shadow_stack[0])
>  #ifndef TSAN_GO
>
> Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_rtl_thread.cc
> URL:
> http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_rtl_thread.cc?rev=182354&r1=182353&r2=182354&view=diff
>
> ==============================================================================
> --- compiler-rt/trunk/lib/tsan/rtl/tsan_rtl_thread.cc (original)
> +++ compiler-rt/trunk/lib/tsan/rtl/tsan_rtl_thread.cc Tue May 21 03:12:35
> 2013
> @@ -165,8 +165,16 @@ static void MaybeReportThreadLeak(Thread
>  }
>  #endif
>
> +static void ThreadCheckIgnore(ThreadState *thr) {
> +  if (thr->ignore_reads_and_writes) {
> +    Printf("ThreadSanitizer: thread T%d finished with ignores enabled.\n",
> +           thr->tid);
>

Maybe it should be a fatal error? Or somehow else more visible?


> +  }
> +}
> +
>  void ThreadFinalize(ThreadState *thr) {
>    CHECK_GT(thr->in_rtl, 0);
> +  ThreadCheckIgnore(thr);
>  #ifndef TSAN_GO
>    if (!flags()->report_thread_leaks)
>      return;
> @@ -235,6 +243,7 @@ void ThreadStart(ThreadState *thr, int t
>
>  void ThreadFinish(ThreadState *thr) {
>    CHECK_GT(thr->in_rtl, 0);
> +  ThreadCheckIgnore(thr);
>    StatInc(thr, StatThreadFinish);
>    if (thr->stk_addr && thr->stk_size)
>      DontNeedShadowFor(thr->stk_addr, thr->stk_size);
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130521/510009b7/attachment.html>


More information about the llvm-commits mailing list