[compiler-rt] [ubsan-minimal] Switch to weak symbols for callbacks to allow overriding in client code (PR #119242)

via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 9 10:25:19 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 6c8ac3b6a5665733d9adc70b88ed34405b3272bc --extensions c,cpp -- compiler-rt/test/ubsan_minimal/TestCases/override-callback.c 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 aa91a66cb6..8be25f97e4 100644
--- a/compiler-rt/lib/ubsan_minimal/ubsan_minimal_handlers.cpp
+++ b/compiler-rt/lib/ubsan_minimal/ubsan_minimal_handlers.cpp
@@ -96,14 +96,14 @@ constexpr unsigned kAddrBuf = SANITIZER_WORDSIZE / 4;
 // Reserve an additional byte for '\n'.
 #define MSG_BUF_LEN(msg) (sizeof(MSG_TMPL(msg)) + kAddrBuf + 1)
 
-#define HANDLER_RECOVER(name, msg)                               \
-  SANITIZER_INTERFACE_WEAK_DEF(                                  \
-    void, __ubsan_handle_##name##_minimal, void) {               \
-    uintptr_t caller = GET_CALLER_PC();                          \
-    if (!report_this_error(caller)) return;                      \
-    char msg_buf[MSG_BUF_LEN(msg)] = MSG_TMPL(msg);              \
-    decorate_msg(MSG_TMPL_END(msg_buf, msg), caller);            \
-    message(msg_buf);                                            \
+#define HANDLER_RECOVER(name, msg)                                             \
+  SANITIZER_INTERFACE_WEAK_DEF(void, __ubsan_handle_##name##_minimal, void) {  \
+    uintptr_t caller = GET_CALLER_PC();                                        \
+    if (!report_this_error(caller))                                            \
+      return;                                                                  \
+    char msg_buf[MSG_BUF_LEN(msg)] = MSG_TMPL(msg);                            \
+    decorate_msg(MSG_TMPL_END(msg_buf, msg), caller);                          \
+    message(msg_buf);                                                          \
   }
 
 #define HANDLER_NORECOVER(name, msg)                             \
diff --git a/compiler-rt/test/ubsan_minimal/TestCases/override-callback.c b/compiler-rt/test/ubsan_minimal/TestCases/override-callback.c
index 2893b5df86..c2bc185ac9 100644
--- a/compiler-rt/test/ubsan_minimal/TestCases/override-callback.c
+++ b/compiler-rt/test/ubsan_minimal/TestCases/override-callback.c
@@ -1,7 +1,7 @@
 // RUN: %clang -fsanitize=implicit-integer-sign-change %s -o %t && %run %t 2>&1 | FileCheck %s --check-prefixes=CHECK
 
-#include <stdio.h>
 #include <stdint.h>
+#include <stdio.h>
 
 void __ubsan_handle_implicit_conversion_minimal() {
   printf("CUSTOM_CALLBACK\n");
@@ -9,6 +9,6 @@ void __ubsan_handle_implicit_conversion_minimal() {
 
 int main() {
   int32_t t0 = (~((uint32_t)0));
-// CHECK: CUSTOM_CALLBACK
+  // CHECK: CUSTOM_CALLBACK
   return 0;
 }

``````````

</details>


https://github.com/llvm/llvm-project/pull/119242


More information about the llvm-commits mailing list