Skip to content

Commit 334a4f8

Browse files
committed
Addressed comments.
1 parent 056ea1a commit 334a4f8

File tree

2 files changed

+17
-37
lines changed

2 files changed

+17
-37
lines changed

compiler-rt/lib/ubsan_minimal/ubsan_minimal_handlers.cpp

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,21 @@ static __sanitizer::atomic_uintptr_t caller_pcs[kMaxCallerPcs];
2020
// that "too many errors" has already been reported.
2121
static __sanitizer::atomic_uint32_t caller_pcs_sz;
2222

23-
SANITIZER_INTERFACE_WEAK_DEF(int, __sanitizer_report_ubsan_error,
24-
uintptr_t caller, const char* name) {
23+
SANITIZER_INTERFACE_WEAK_DEF(void, __ubsan_report_error, uintptr_t caller,
24+
const char *msg, const char *decorated_msg) {
2525
if (caller == 0)
26-
return false;
26+
return;
2727
while (true) {
2828
unsigned sz = __sanitizer::atomic_load_relaxed(&caller_pcs_sz);
29-
if (sz > kMaxCallerPcs) return false; // early exit
29+
if (sz > kMaxCallerPcs) return; // early exit
3030
// when sz==kMaxCallerPcs print "too many errors", but only when cmpxchg
3131
// succeeds in order to not print it multiple times.
3232
if (sz > 0 && sz < kMaxCallerPcs) {
3333
uintptr_t p;
3434
for (unsigned i = 0; i < sz; ++i) {
3535
p = __sanitizer::atomic_load_relaxed(&caller_pcs[i]);
3636
if (p == 0) break; // Concurrent update.
37-
if (p == caller) return false;
37+
if (p == caller) return;
3838
}
3939
if (p == 0) continue; // FIXME: yield?
4040
}
@@ -45,10 +45,10 @@ SANITIZER_INTERFACE_WEAK_DEF(int, __sanitizer_report_ubsan_error,
4545

4646
if (sz == kMaxCallerPcs) {
4747
message("ubsan: too many errors\n");
48-
return false;
48+
return;
4949
}
5050
__sanitizer::atomic_store_relaxed(&caller_pcs[sz], caller);
51-
return true;
51+
message(decorated_msg);
5252
}
5353
}
5454

@@ -100,18 +100,17 @@ constexpr unsigned kAddrBuf = SANITIZER_WORDSIZE / 4;
100100
#define HANDLER_RECOVER(name, msg) \
101101
INTERFACE void __ubsan_handle_##name##_minimal() { \
102102
uintptr_t caller = GET_CALLER_PC(); \
103-
if (!__sanitizer_report_ubsan_error(caller, #name)) \
104-
return; \
105103
char msg_buf[MSG_BUF_LEN(msg)] = MSG_TMPL(msg); \
106104
decorate_msg(MSG_TMPL_END(msg_buf, msg), caller); \
107-
message(msg_buf); \
105+
__ubsan_report_error(caller, msg, msg_buf); \
108106
}
109107

110108
#define HANDLER_NORECOVER(name, msg) \
111109
INTERFACE void __ubsan_handle_##name##_minimal_abort() { \
110+
uintptr_t caller = GET_CALLER_PC(); \
112111
char msg_buf[MSG_BUF_LEN(msg)] = MSG_TMPL(msg); \
113-
decorate_msg(MSG_TMPL_END(msg_buf, msg), GET_CALLER_PC()); \
114-
message(msg_buf); \
112+
decorate_msg(MSG_TMPL_END(msg_buf, msg), caller); \
113+
__ubsan_report_error(caller, #msg, msg_buf); \
115114
abort_with_message(msg_buf); \
116115
}
117116

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,16 @@
1-
// RUN: %clang -fsanitize=implicit-integer-sign-change %s -o %t && %run %t 0 2>&1 | \
2-
// RUN: FileCheck %s --check-prefixes=CHECK_NO_MESSAGE
3-
// RUN: %clang -fsanitize=implicit-integer-sign-change %s -o %t && %run %t 1 2>&1 | \
4-
// RUN: FileCheck %s --check-prefixes=CHECK_MESSAGE
1+
// RUN: %clang -fsanitize=implicit-integer-sign-change %s -o %t && %run %t 0 2>&1 | FileCheck %s
52
#include <stdio.h>
63
#include <stdint.h>
74
#include <stdlib.h>
85

96
static int Result;
107

11-
int __sanitizer_report_ubsan_error(uintptr_t caller, const char* name) {
12-
fprintf(stderr, "CUSTOM_CALLBACK\n");
13-
return Result;
14-
}
15-
16-
void test_message() {
17-
int32_t t0 = (~((uint32_t)0));
18-
// CHECK_MESSAGE: CUSTOM_CALLBACK
19-
// CHECK_MESSAGE: ubsan: implicit-conversion
20-
}
21-
22-
void test_no_message() {
23-
int32_t t0 = (~((uint32_t)0));
24-
// CHECK_NO_MESSAGE: CUSTOM_CALLBACK
25-
// CCHECK_NO_MESSAGE-NOT: ubsan: implicit-conversion
8+
void __ubsan_report_error(uintptr_t caller, const char *msg,
9+
const char *decorated_msg) {
10+
fprintf(stderr, "CUSTOM_CALLBACK: %s\n", msg);
2611
}
2712

2813
int main(int argc, const char** argv) {
29-
Result = atoi(argv[1]);
30-
if (Result)
31-
test_message();
32-
else
33-
test_no_message();
34-
return 0;
14+
int32_t t0 = (~((uint32_t)0));
15+
// CHECK: CUSTOM_CALLBACK: implicit-conversion
3516
}

0 commit comments

Comments
 (0)