Skip to content

Commit fd09907

Browse files
committed
[rtsan] Introduce halt_on_error flag
1 parent 38371a1 commit fd09907

File tree

3 files changed

+35
-12
lines changed

3 files changed

+35
-12
lines changed

compiler-rt/lib/rtsan/rtsan.cpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,11 @@ static InitializationState GetInitializationState() {
4444
atomic_load(&rtsan_initialized, memory_order_acquire));
4545
}
4646

47-
static auto PrintDiagnosticsAndDieAction(DiagnosticsInfo info) {
47+
static auto DefaultErrorAction(DiagnosticsInfo info) {
4848
return [info]() {
4949
__rtsan::PrintDiagnostics(info);
50-
Die();
50+
if (flags().halt_on_error)
51+
Die();
5152
};
5253
}
5354

@@ -105,20 +106,18 @@ __rtsan_notify_intercepted_call(const char *func_name) {
105106

106107
__rtsan_ensure_initialized();
107108
GET_CALLER_PC_BP;
108-
ExpectNotRealtime(
109-
GetContextForThisThread(),
110-
PrintDiagnosticsAndDieAction(
111-
{DiagnosticsInfoType::InterceptedCall, func_name, pc, bp}));
109+
ExpectNotRealtime(GetContextForThisThread(),
110+
DefaultErrorAction({DiagnosticsInfoType::InterceptedCall,
111+
func_name, pc, bp}));
112112
}
113113

114114
SANITIZER_INTERFACE_ATTRIBUTE void
115115
__rtsan_notify_blocking_call(const char *func_name) {
116116
__rtsan_ensure_initialized();
117117
GET_CALLER_PC_BP;
118-
ExpectNotRealtime(
119-
GetContextForThisThread(),
120-
PrintDiagnosticsAndDieAction(
121-
{DiagnosticsInfoType::BlockingCall, func_name, pc, bp}));
118+
ExpectNotRealtime(GetContextForThisThread(),
119+
DefaultErrorAction({DiagnosticsInfoType::BlockingCall,
120+
func_name, pc, bp}));
122121
}
123122

124123
} // extern "C"

compiler-rt/lib/rtsan/rtsan_flags.inc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,4 @@
1616
// RTSAN_FLAG(Type, Name, DefaultValue, Description)
1717
// See COMMON_FLAG in sanitizer_flags.inc for more details.
1818

19-
// Example flag, until we get a real one
20-
// RTSAN_FLAG(bool, halt_on_error, true, "If true, halt the program on error")
19+
RTSAN_FLAG(bool, halt_on_error, true, "Exit after first reported error.")
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// RUN: %clangxx -fsanitize=realtime %s -o %t
2+
// RUN: env RTSAN_OPTIONS="halt_on_error=false" %run %t 2>&1 | FileCheck %s
3+
// UNSUPPORTED: ios
4+
5+
// Intent: Ensure that halt_on_error does not exit on the first violation.
6+
7+
#include <stdlib.h>
8+
9+
void *MallocViolation() { return malloc(10); }
10+
11+
void FreeViolation(void *Ptr) { free(Ptr); }
12+
13+
void process() [[clang::nonblocking]] {
14+
void *Ptr = MallocViolation();
15+
FreeViolation(Ptr);
16+
}
17+
18+
int main() {
19+
process();
20+
return 0;
21+
// CHECK: ==ERROR: RealtimeSanitizer
22+
// CHECK-NEXT: {{.*`malloc`.*}}
23+
// CHECK: ==ERROR: RealtimeSanitizer
24+
// CHECK-NEXT: {{.*`free`.*}}
25+
}

0 commit comments

Comments
 (0)