[compiler-rt] [ubsan_minimal] Add __ubsan_report_error_fatal (PR #138999)

Vitaly Buka via llvm-commits llvm-commits at lists.llvm.org
Thu May 8 00:08:27 PDT 2025


https://github.com/vitalybuka updated https://github.com/llvm/llvm-project/pull/138999

>From 95316c976ce39420b80480e8a45ae41a7dfea291 Mon Sep 17 00:00:00 2001
From: Vitaly Buka <vitalybuka at google.com>
Date: Wed, 7 May 2025 17:43:29 -0700
Subject: [PATCH] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20initia?=
 =?UTF-8?q?l=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.4
---
 compiler-rt/lib/ubsan_minimal/ubsan_minimal_handlers.cpp | 8 +++++++-
 .../test/ubsan_minimal/TestCases/override-callback.c     | 9 ++++++++-
 2 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/compiler-rt/lib/ubsan_minimal/ubsan_minimal_handlers.cpp b/compiler-rt/lib/ubsan_minimal/ubsan_minimal_handlers.cpp
index c3ffd41bcacc0..9c03ddf7d063c 100644
--- a/compiler-rt/lib/ubsan_minimal/ubsan_minimal_handlers.cpp
+++ b/compiler-rt/lib/ubsan_minimal/ubsan_minimal_handlers.cpp
@@ -85,6 +85,12 @@ SANITIZER_INTERFACE_WEAK_DEF(void, __ubsan_report_error, const char *kind,
   }
 }
 
+SANITIZER_INTERFACE_WEAK_DEF(void, __ubsan_report_error_fatal, const char *kind,
+                             uintptr_t caller) {
+  // Use another handlers, in case it's already overriden.
+  __ubsan_report_error(kind, caller);
+}
+
 #if defined(__ANDROID__)
 extern "C" __attribute__((weak)) void android_set_abort_message(const char *);
 static void abort_with_message(const char *kind, uintptr_t caller) {
@@ -121,7 +127,7 @@ void NORETURN CheckFailed(const char *file, int, const char *cond, u64, u64) {
 #define HANDLER_NORECOVER(name, kind)                                          \
   INTERFACE void __ubsan_handle_##name##_minimal_abort() {                     \
     uintptr_t caller = GET_CALLER_PC();                                        \
-    __ubsan_report_error(kind, caller);                                        \
+    __ubsan_report_error_fatal(kind, caller);                                  \
     abort_with_message(kind, caller);                                          \
   }
 
diff --git a/compiler-rt/test/ubsan_minimal/TestCases/override-callback.c b/compiler-rt/test/ubsan_minimal/TestCases/override-callback.c
index e11a3712f1be3..8c3b4db9a9cd8 100644
--- a/compiler-rt/test/ubsan_minimal/TestCases/override-callback.c
+++ b/compiler-rt/test/ubsan_minimal/TestCases/override-callback.c
@@ -1,4 +1,6 @@
-// RUN: %clang -fsanitize=implicit-integer-sign-change %s -o %t && %run %t 0 2>&1 | FileCheck %s
+// RUN: %clang -fsanitize=implicit-integer-sign-change                           %s -o %t &&             %run %t 2>&1 | FileCheck %s
+// RUN: %clang -fsanitize=implicit-integer-sign-change -fno-sanitize-recover=all %s -o %t && not --crash %run %t 2>&1 | FileCheck %s --check-prefixes=FATAL
+
 #include <stdint.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -9,7 +11,12 @@ void __ubsan_report_error(const char *kind, uintptr_t caller) {
   fprintf(stderr, "CUSTOM_CALLBACK: %s\n", kind);
 }
 
+void __ubsan_report_error_fatal(const char *kind, uintptr_t caller) {
+  fprintf(stderr, "FATAL_CALLBACK: %s\n", kind);
+}
+
 int main(int argc, const char **argv) {
   int32_t t0 = (~((uint32_t)0));
   // CHECK: CUSTOM_CALLBACK: implicit-conversion
+  // FATAL: FATAL_CALLBACK: implicit-conversion
 }



More information about the llvm-commits mailing list