[compiler-rt] 9ef9acb - [rtsan] Introduce halt_on_error flag (#109832)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 24 17:08:46 PDT 2024
Author: Chris Apple
Date: 2024-09-24T17:08:42-07:00
New Revision: 9ef9acbd4f5f84e1bfceb677a064b724f102554e
URL: https://github.com/llvm/llvm-project/commit/9ef9acbd4f5f84e1bfceb677a064b724f102554e
DIFF: https://github.com/llvm/llvm-project/commit/9ef9acbd4f5f84e1bfceb677a064b724f102554e.diff
LOG: [rtsan] Introduce halt_on_error flag (#109832)
Added:
compiler-rt/test/rtsan/halt_on_error.cpp
Modified:
compiler-rt/lib/rtsan/rtsan.cpp
compiler-rt/lib/rtsan/rtsan_flags.inc
Removed:
################################################################################
diff --git a/compiler-rt/lib/rtsan/rtsan.cpp b/compiler-rt/lib/rtsan/rtsan.cpp
index 84e4b8fae1e2fa..1e10069f51dd3b 100644
--- a/compiler-rt/lib/rtsan/rtsan.cpp
+++ b/compiler-rt/lib/rtsan/rtsan.cpp
@@ -44,10 +44,11 @@ static InitializationState GetInitializationState() {
atomic_load(&rtsan_initialized, memory_order_acquire));
}
-static auto PrintDiagnosticsAndDieAction(DiagnosticsInfo info) {
+static auto OnViolationAction(DiagnosticsInfo info) {
return [info]() {
__rtsan::PrintDiagnostics(info);
- Die();
+ if (flags().halt_on_error)
+ Die();
};
}
@@ -105,20 +106,18 @@ __rtsan_notify_intercepted_call(const char *func_name) {
__rtsan_ensure_initialized();
GET_CALLER_PC_BP;
- ExpectNotRealtime(
- GetContextForThisThread(),
- PrintDiagnosticsAndDieAction(
- {DiagnosticsInfoType::InterceptedCall, func_name, pc, bp}));
+ ExpectNotRealtime(GetContextForThisThread(),
+ OnViolationAction({DiagnosticsInfoType::InterceptedCall,
+ func_name, pc, bp}));
}
SANITIZER_INTERFACE_ATTRIBUTE void
__rtsan_notify_blocking_call(const char *func_name) {
__rtsan_ensure_initialized();
GET_CALLER_PC_BP;
- ExpectNotRealtime(
- GetContextForThisThread(),
- PrintDiagnosticsAndDieAction(
- {DiagnosticsInfoType::BlockingCall, func_name, pc, bp}));
+ ExpectNotRealtime(GetContextForThisThread(),
+ OnViolationAction({DiagnosticsInfoType::BlockingCall,
+ func_name, pc, bp}));
}
} // extern "C"
diff --git a/compiler-rt/lib/rtsan/rtsan_flags.inc b/compiler-rt/lib/rtsan/rtsan_flags.inc
index 93b0294313672f..25d62cf0a60fb0 100644
--- a/compiler-rt/lib/rtsan/rtsan_flags.inc
+++ b/compiler-rt/lib/rtsan/rtsan_flags.inc
@@ -16,5 +16,4 @@
// RTSAN_FLAG(Type, Name, DefaultValue, Description)
// See COMMON_FLAG in sanitizer_flags.inc for more details.
-// Example flag, until we get a real one
-// RTSAN_FLAG(bool, halt_on_error, true, "If true, halt the program on error")
+RTSAN_FLAG(bool, halt_on_error, true, "Exit after first reported error.")
diff --git a/compiler-rt/test/rtsan/halt_on_error.cpp b/compiler-rt/test/rtsan/halt_on_error.cpp
new file mode 100644
index 00000000000000..c2ebdf349f371a
--- /dev/null
+++ b/compiler-rt/test/rtsan/halt_on_error.cpp
@@ -0,0 +1,26 @@
+// RUN: %clangxx -fsanitize=realtime %s -o %t
+// RUN: %env_rtsan_opts="halt_on_error=true" not %run %t 2>&1 | FileCheck %s
+// RUN: %env_rtsan_opts="halt_on_error=false" %run %t 2>&1 | FileCheck %s --check-prefixes=CHECK-NO-HALT,CHECK
+// UNSUPPORTED: ios
+
+// Intent: Ensure that halt_on_error does not exit on the first violation.
+
+#include <stdlib.h>
+
+void *MallocViolation() { return malloc(10); }
+
+void FreeViolation(void *Ptr) { free(Ptr); }
+
+void process() [[clang::nonblocking]] {
+ void *Ptr = MallocViolation();
+ FreeViolation(Ptr);
+}
+
+int main() {
+ process();
+ return 0;
+ // CHECK: ==ERROR: RealtimeSanitizer
+ // CHECK-NEXT: {{.*`malloc`.*}}
+ // CHECK-NO-HALT: ==ERROR: RealtimeSanitizer
+ // CHECK-NO-HALT-NEXT: {{.*`free`.*}}
+}
More information about the llvm-commits
mailing list