[PATCH] tsan/msan: add halt_on_error flag
Dmitry Vyukov
dvyukov at google.com
Tue Aug 13 07:48:34 PDT 2013
Hi eugenis,
If halt_on_error==true, program terminates after reporting first error.
http://llvm-reviews.chandlerc.com/D1379
Files:
tsan/check_cmake.sh
tsan/lit_tests/halt_on_error.cc
tsan/rtl/tsan_flags.h
tsan/rtl/tsan_flags.cc
tsan/rtl/tsan_rtl_report.cc
msan/msan.cc
msan/msan_interceptors.cc
msan/msan_flags.h
Index: tsan/check_cmake.sh
===================================================================
--- tsan/check_cmake.sh
+++ tsan/check_cmake.sh
@@ -10,3 +10,4 @@
make check-sanitizer -j64
make check-tsan -j64
make check-asan -j64
+make check-msan -j64
Index: tsan/lit_tests/halt_on_error.cc
===================================================================
--- tsan/lit_tests/halt_on_error.cc
+++ tsan/lit_tests/halt_on_error.cc
@@ -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
+
Index: tsan/rtl/tsan_flags.h
===================================================================
--- tsan/rtl/tsan_flags.h
+++ tsan/rtl/tsan_flags.h
@@ -58,6 +58,8 @@
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".
Index: tsan/rtl/tsan_flags.cc
===================================================================
--- tsan/rtl/tsan_flags.cc
+++ tsan/rtl/tsan_flags.cc
@@ -52,6 +52,7 @@
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 @@
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");
Index: tsan/rtl/tsan_rtl_report.cc
===================================================================
--- tsan/rtl/tsan_rtl_report.cc
+++ tsan/rtl/tsan_rtl_report.cc
@@ -527,7 +527,9 @@
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;
}
Index: msan/msan.cc
===================================================================
--- msan/msan.cc
+++ msan/msan.cc
@@ -124,13 +124,18 @@
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 @@
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 @@
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_keep_going(int keep_going) {
- flags()->keep_going = keep_going;
+ flags()->halt_on_error = !keep_going;
}
void __msan_set_expect_umr(int expect_umr) {
Index: msan/msan_interceptors.cc
===================================================================
--- msan/msan_interceptors.cc
+++ msan/msan_interceptors.cc
@@ -61,7 +61,7 @@
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(); \
} \
Index: msan/msan_flags.h
===================================================================
--- msan/msan_flags.h
+++ msan/msan_flags.h
@@ -25,7 +25,7 @@
bool poison_in_malloc; // default: true
bool report_umrs;
bool wrap_signals;
- bool keep_going;
+ bool halt_on_error;
};
Flags *flags();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D1379.1.patch
Type: text/x-patch
Size: 5205 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130813/3d89496a/attachment.bin>
More information about the llvm-commits
mailing list