[compiler-rt] r188279 - tsan/msan: add halt_on_error flag

Dmitry Vyukov dvyukov at google.com
Tue Aug 13 08:33:00 PDT 2013


Author: dvyukov
Date: Tue Aug 13 10:33:00 2013
New Revision: 188279

URL: http://llvm.org/viewvc/llvm-project?rev=188279&view=rev
Log:
tsan/msan: add halt_on_error flag
If halt_on_error==true, program terminates after reporting first error.


Added:
    compiler-rt/trunk/lib/tsan/lit_tests/halt_on_error.cc
Modified:
    compiler-rt/trunk/lib/msan/lit_tests/keep-going.cc
    compiler-rt/trunk/lib/msan/msan.cc
    compiler-rt/trunk/lib/msan/msan_flags.h
    compiler-rt/trunk/lib/msan/msan_interceptors.cc
    compiler-rt/trunk/lib/tsan/check_cmake.sh
    compiler-rt/trunk/lib/tsan/rtl/tsan_flags.cc
    compiler-rt/trunk/lib/tsan/rtl/tsan_flags.h
    compiler-rt/trunk/lib/tsan/rtl/tsan_rtl_report.cc

Modified: compiler-rt/trunk/lib/msan/lit_tests/keep-going.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/lit_tests/keep-going.cc?rev=188279&r1=188278&r2=188279&view=diff
==============================================================================
--- compiler-rt/trunk/lib/msan/lit_tests/keep-going.cc (original)
+++ compiler-rt/trunk/lib/msan/lit_tests/keep-going.cc Tue Aug 13 10:33:00 2013
@@ -11,6 +11,10 @@
 // FileCheck %s <%t.out
 // RUN: %clangxx_msan -m64 -mllvm -msan-keep-going=1 -O0 %s -o %t && MSAN_OPTIONS=keep_going=1 not %t >%t.out 2>&1
 // FileCheck --check-prefix=CHECK-KEEP-GOING %s <%t.out
+// RUN: %clangxx_msan -m64 -mllvm -msan-keep-going=1 -O0 %s -o %t && MSAN_OPTIONS=halt_on_error=1 not %t >%t.out 2>&1
+// FileCheck %s <%t.out
+// RUN: %clangxx_msan -m64 -mllvm -msan-keep-going=1 -O0 %s -o %t && MSAN_OPTIONS=halt_on_error=0 not %t >%t.out 2>&1
+// FileCheck --check-prefix=CHECK-KEEP-GOING %s <%t.out
 
 // Test behaviour of -mllvm -msan-keep-going and MSAN_OPTIONS=keep_going.
 // -mllvm -msan-keep-going provides the default value of keep_going flag; value

Modified: compiler-rt/trunk/lib/msan/msan.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/msan.cc?rev=188279&r1=188278&r2=188279&view=diff
==============================================================================
--- compiler-rt/trunk/lib/msan/msan.cc (original)
+++ compiler-rt/trunk/lib/msan/msan.cc Tue Aug 13 10:33:00 2013
@@ -124,13 +124,18 @@ static void ParseFlagsFromString(Flags *
   ParseFlag(str, &f->exit_code, "exit_code");
   if (f->exit_code < 0 || f->exit_code > 127) {
     Printf("Exit code not in [0, 128) range: %d\n", f->exit_code);
-    f->exit_code = 1;
     Die();
   }
   ParseFlag(str, &f->report_umrs, "report_umrs");
   ParseFlag(str, &f->verbosity, "verbosity");
   ParseFlag(str, &f->wrap_signals, "wrap_signals");
-  ParseFlag(str, &f->keep_going, "keep_going");
+
+  // keep_going is an old name for halt_on_error,
+  // and it has inverse meaning.
+  f->halt_on_error = !f->halt_on_error;
+  ParseFlag(str, &f->halt_on_error, "keep_going");
+  f->halt_on_error = !f->halt_on_error;
+  ParseFlag(str, &f->halt_on_error, "halt_on_error");
 }
 
 static void InitializeFlags(Flags *f, const char *options) {
@@ -151,7 +156,7 @@ static void InitializeFlags(Flags *f, co
   f->report_umrs = true;
   f->verbosity = 0;
   f->wrap_signals = true;
-  f->keep_going = !!&__msan_keep_going;
+  f->halt_on_error = !&__msan_keep_going;
 
   // Override from user-specified string.
   if (__msan_default_options)
@@ -235,7 +240,7 @@ void __msan_warning() {
   GET_CALLER_PC_BP_SP;
   (void)sp;
   PrintWarning(pc, bp);
-  if (!__msan::flags()->keep_going) {
+  if (__msan::flags()->halt_on_error) {
     Printf("Exiting\n");
     Die();
   }
@@ -311,7 +316,7 @@ void __msan_set_exit_code(int exit_code)
 }
 
 void __msan_set_keep_going(int keep_going) {
-  flags()->keep_going = keep_going;
+  flags()->halt_on_error = !keep_going;
 }
 
 void __msan_set_expect_umr(int expect_umr) {

Modified: compiler-rt/trunk/lib/msan/msan_flags.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/msan_flags.h?rev=188279&r1=188278&r2=188279&view=diff
==============================================================================
--- compiler-rt/trunk/lib/msan/msan_flags.h (original)
+++ compiler-rt/trunk/lib/msan/msan_flags.h Tue Aug 13 10:33:00 2013
@@ -25,7 +25,7 @@ struct Flags {
   bool poison_in_malloc;  // default: true
   bool report_umrs;
   bool wrap_signals;
-  bool keep_going;
+  bool halt_on_error;
 };
 
 Flags *flags();

Modified: compiler-rt/trunk/lib/msan/msan_interceptors.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/msan_interceptors.cc?rev=188279&r1=188278&r2=188279&view=diff
==============================================================================
--- compiler-rt/trunk/lib/msan/msan_interceptors.cc (original)
+++ compiler-rt/trunk/lib/msan/msan_interceptors.cc Tue Aug 13 10:33:00 2013
@@ -61,7 +61,7 @@ bool IsInInterceptorScope() {
              offset, x, n);                                                  \
       __msan::PrintWarningWithOrigin(pc, bp,                                 \
                                      __msan_get_origin((char *)x + offset)); \
-      if (!__msan::flags()->keep_going) {                                    \
+      if (__msan::flags()->halt_on_error) {                                  \
         Printf("Exiting\n");                                                 \
         Die();                                                               \
       }                                                                      \

Modified: compiler-rt/trunk/lib/tsan/check_cmake.sh
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/check_cmake.sh?rev=188279&r1=188278&r2=188279&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/check_cmake.sh (original)
+++ compiler-rt/trunk/lib/tsan/check_cmake.sh Tue Aug 13 10:33:00 2013
@@ -10,3 +10,4 @@ make -j64
 make check-sanitizer -j64
 make check-tsan -j64
 make check-asan -j64
+make check-msan -j64

Added: compiler-rt/trunk/lib/tsan/lit_tests/halt_on_error.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/lit_tests/halt_on_error.cc?rev=188279&view=auto
==============================================================================
--- compiler-rt/trunk/lib/tsan/lit_tests/halt_on_error.cc (added)
+++ compiler-rt/trunk/lib/tsan/lit_tests/halt_on_error.cc Tue Aug 13 10:33:00 2013
@@ -0,0 +1,25 @@
+// RUN: %clang_tsan -O1 %s -o %t && TSAN_OPTIONS="$TSAN_OPTIONS halt_on_error=1" not %t 2>&1 | FileCheck %s
+#include <pthread.h>
+#include <stdio.h>
+
+int X;
+
+void *Thread(void *x) {
+  X = 42;
+  return 0;
+}
+
+int main() {
+  fprintf(stderr, "BEFORE\n");
+  pthread_t t;
+  pthread_create(&t, 0, Thread, 0);
+  X = 43;
+  pthread_join(t, 0);
+  fprintf(stderr, "AFTER\n");
+  return 0;
+}
+
+// CHECK: BEFORE
+// CHECK: WARNING: ThreadSanitizer: data race
+// CHECK-NOT: AFTER
+

Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_flags.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_flags.cc?rev=188279&r1=188278&r2=188279&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_flags.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_flags.cc Tue Aug 13 10:33:00 2013
@@ -52,6 +52,7 @@ void InitializeFlags(Flags *f, const cha
   f->print_suppressions = false;
   f->print_benign = false;
   f->exitcode = 66;
+  f->halt_on_error = false;
   f->log_path = "stderr";
   f->atexit_sleep_ms = 1000;
   f->verbosity = 0;
@@ -83,6 +84,7 @@ void InitializeFlags(Flags *f, const cha
   ParseFlag(env, &f->print_suppressions, "print_suppressions");
   ParseFlag(env, &f->print_benign, "print_benign");
   ParseFlag(env, &f->exitcode, "exitcode");
+  ParseFlag(env, &f->halt_on_error, "halt_on_error");
   ParseFlag(env, &f->log_path, "log_path");
   ParseFlag(env, &f->atexit_sleep_ms, "atexit_sleep_ms");
   ParseFlag(env, &f->verbosity, "verbosity");

Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_flags.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_flags.h?rev=188279&r1=188278&r2=188279&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_flags.h (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_flags.h Tue Aug 13 10:33:00 2013
@@ -58,6 +58,8 @@ struct Flags {
   bool print_benign;
   // Override exit status if something was reported.
   int exitcode;
+  // Exit after first reported error.
+  bool halt_on_error;
   // Write logs to "log_path.pid".
   // The special values are "stdout" and "stderr".
   // The default is "stderr".

Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_rtl_report.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_rtl_report.cc?rev=188279&r1=188278&r2=188279&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_rtl_report.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_rtl_report.cc Tue Aug 13 10:33:00 2013
@@ -527,7 +527,9 @@ bool OutputReport(Context *ctx,
   if (OnReport(rep, suppress_pc != 0))
     return false;
   PrintReport(rep);
-  CTX()->nreported++;
+  ctx->nreported++;
+  if (flags()->halt_on_error)
+    internal__exit(flags()->exitcode);
   return true;
 }
 





More information about the llvm-commits mailing list