[compiler-rt] [ubsan-minimal] Refactor error reporting to use a single function (PR #119920)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Dec 13 12:14:05 PST 2024
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff 73adf26d504ba945251b87d78267e2bbfd34928f e26ffe04b5aaa50a74f29ef4f4e6d8cec16d0cee --extensions cpp -- compiler-rt/lib/ubsan_minimal/ubsan_minimal_handlers.cpp
``````````
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/compiler-rt/lib/ubsan_minimal/ubsan_minimal_handlers.cpp b/compiler-rt/lib/ubsan_minimal/ubsan_minimal_handlers.cpp
index 56e97be163..0235384fd9 100644
--- a/compiler-rt/lib/ubsan_minimal/ubsan_minimal_handlers.cpp
+++ b/compiler-rt/lib/ubsan_minimal/ubsan_minimal_handlers.cpp
@@ -1,8 +1,8 @@
#include "sanitizer_common/sanitizer_atomic.h"
+#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
-#include <stdint.h>
#include <string.h>
#include <unistd.h>
@@ -25,7 +25,8 @@ static __sanitizer::atomic_uint32_t caller_pcs_sz;
#define MSG_SUFFIX " by 0x"
static char *append_str(const char *s, char *buf, const char *end) {
- for (const char *p = s; (buf < end) && (*p != '\0'); ++p, ++buf) *buf = *p;
+ for (const char *p = s; (buf < end) && (*p != '\0'); ++p, ++buf)
+ *buf = *p;
return buf;
}
@@ -42,7 +43,8 @@ static char *append_hex(uintptr_t d, char *buf, const char *end) {
#if defined(__ANDROID__)
extern "C" __attribute__((weak)) void android_set_abort_message(const char *);
static void abort_with_message(const char *msg) {
- if (&android_set_abort_message) android_set_abort_message(msg);
+ if (&android_set_abort_message)
+ android_set_abort_message(msg);
abort();
}
#else
@@ -54,7 +56,8 @@ static void report_error(const char *msg, uintptr_t caller, int abort) {
return;
while (true) {
unsigned sz = __sanitizer::atomic_load_relaxed(&caller_pcs_sz);
- if (sz > kMaxCallerPcs) return; // early exit
+ if (sz > kMaxCallerPcs)
+ return; // early exit
// when sz==kMaxCallerPcs print "too many errors", but only when cmpxchg
// succeeds in order to not print it multiple times.
if (sz > 0 && sz < kMaxCallerPcs) {
@@ -62,7 +65,8 @@ static void report_error(const char *msg, uintptr_t caller, int abort) {
for (unsigned i = 0; i < sz; ++i) {
p = __sanitizer::atomic_load_relaxed(&caller_pcs[i]);
if (p == 0) break; // Concurrent update.
- if (p == caller) return;
+ if (p == caller)
+ return;
}
if (p == 0) continue; // FIXME: yield?
}
@@ -82,13 +86,16 @@ static void report_error(const char *msg, uintptr_t caller, int abort) {
char *p = append_str(msg, msg_buf + sizeof(MSG_PREFIX) - 1, end);
p = append_str(MSG_SUFFIX, p, end);
p = append_hex(caller, p, end);
- if (p < end) *p++ = '\n';
+ if (p < end)
+ *p++ = '\n';
// Zero terminate.
- if (p == end) --p;
+ if (p == end)
+ --p;
*p = '\0';
message(msg_buf);
- if (abort) abort_with_message(msg_buf); \
+ if (abort)
+ abort_with_message(msg_buf);
}
}
@@ -107,14 +114,14 @@ void NORETURN CheckFailed(const char *file, int, const char *cond, u64, u64) {
#define INTERFACE extern "C" __attribute__((visibility("default")))
-#define HANDLER_RECOVER(name, msg) \
- INTERFACE void __ubsan_handle_##name##_minimal() { \
- report_error(msg, GET_CALLER_PC(), 0); \
+#define HANDLER_RECOVER(name, msg) \
+ INTERFACE void __ubsan_handle_##name##_minimal() { \
+ report_error(msg, GET_CALLER_PC(), 0); \
}
-#define HANDLER_NORECOVER(name, msg) \
- INTERFACE void __ubsan_handle_##name##_minimal_abort() { \
- report_error(msg, GET_CALLER_PC(), 1); \
+#define HANDLER_NORECOVER(name, msg) \
+ INTERFACE void __ubsan_handle_##name##_minimal_abort() { \
+ report_error(msg, GET_CALLER_PC(), 1); \
}
#define HANDLER(name, msg) \
``````````
</details>
https://github.com/llvm/llvm-project/pull/119920
More information about the llvm-commits
mailing list