Skip to content

Conversation

@vitalybuka
Copy link
Collaborator

@vitalybuka vitalybuka commented Nov 20, 2025

This partially reverts #152192, keeping updated tests and
some code reordering in clang/lib/CodeGen/CGExpr.cpp.

compiler-rt/lib/ubsan_minimal/ubsan_minimal_handlers.cpp is exact revert (with followup #152419)

We don't have a good use case for that, so revert it before we are stuck maintaining this API.

21.x does not have this patch.

This reverts commit a1209d8.

Created using spr 1.3.7
@llvmbot llvmbot added compiler-rt clang:codegen IR generation bugs: mangling, exceptions, etc. compiler-rt:ubsan Undefined behavior sanitizer compiler-rt:sanitizer labels Nov 20, 2025
@llvmbot
Copy link
Member

llvmbot commented Nov 20, 2025

@llvm/pr-subscribers-compiler-rt-sanitizer

@llvm/pr-subscribers-clang-codegen

Author: Vitaly Buka (vitalybuka)

Changes

We don't have good use case for that, so revert it before we stuck with this API.

This reverts commit a1209d8.


Full diff: https://github.com/llvm/llvm-project/pull/168812.diff

4 Files Affected:

  • (modified) clang/lib/CodeGen/CGExpr.cpp (-16)
  • (modified) compiler-rt/lib/ubsan_minimal/ubsan_minimal_handlers.cpp (+13-39)
  • (modified) compiler-rt/test/ubsan_minimal/TestCases/misalignment.cpp (+1-1)
  • (modified) compiler-rt/test/ubsan_minimal/TestCases/null.cpp (+1-1)
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index f2451b16e78be..ffc213b2bd331 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -3898,22 +3898,6 @@ void CodeGenFunction::EmitCheck(
   Branch->setMetadata(llvm::LLVMContext::MD_prof, Node);
   EmitBlock(Handlers);
 
-  // Clear arguments for the MinimalRuntime handler.
-  if (CGM.getCodeGenOpts().SanitizeMinimalRuntime) {
-    switch (CheckHandler) {
-    case SanitizerHandler::TypeMismatch:
-      // Pass value pointer only. It adds minimal overhead.
-      StaticArgs = {};
-      assert(DynamicArgs.size() == 1);
-      break;
-    default:
-      // No arguments for other checks.
-      StaticArgs = {};
-      DynamicArgs = {};
-      break;
-    }
-  }
-
   // Handler functions take an i8* pointing to the (handler-specific) static
   // information block, followed by a sequence of intptr_t arguments
   // representing operand values.
diff --git a/compiler-rt/lib/ubsan_minimal/ubsan_minimal_handlers.cpp b/compiler-rt/lib/ubsan_minimal/ubsan_minimal_handlers.cpp
index a2a2e36e8523d..ebc36a8583e05 100644
--- a/compiler-rt/lib/ubsan_minimal/ubsan_minimal_handlers.cpp
+++ b/compiler-rt/lib/ubsan_minimal/ubsan_minimal_handlers.cpp
@@ -34,16 +34,12 @@ static char *append_hex(uintptr_t d, char *buf, const char *end) {
   return buf;
 }
 
-static void format_msg(const char *kind, uintptr_t caller,
-                       const uintptr_t *address, char *buf, const char *end) {
+static void format_msg(const char *kind, uintptr_t caller, char *buf,
+                       const char *end) {
   buf = append_str("ubsan: ", buf, end);
   buf = append_str(kind, buf, end);
   buf = append_str(" by 0x", buf, end);
   buf = append_hex(caller, buf, end);
-  if (address) {
-    buf = append_str(" address 0x", buf, end);
-    buf = append_hex(*address, buf, end);
-  }
   buf = append_str("\n", buf, end);
   if (buf == end)
     --buf; // Make sure we don't cause a buffer overflow.
@@ -51,7 +47,7 @@ static void format_msg(const char *kind, uintptr_t caller,
 }
 
 SANITIZER_INTERFACE_WEAK_DEF(void, __ubsan_report_error, const char *kind,
-                             uintptr_t caller, const uintptr_t *address) {
+                             uintptr_t caller) {
   if (caller == 0)
     return;
   while (true) {
@@ -84,32 +80,28 @@ SANITIZER_INTERFACE_WEAK_DEF(void, __ubsan_report_error, const char *kind,
     __sanitizer::atomic_store_relaxed(&caller_pcs[sz], caller);
 
     char msg_buf[128];
-    format_msg(kind, caller, address, msg_buf, msg_buf + sizeof(msg_buf));
+    format_msg(kind, caller, msg_buf, msg_buf + sizeof(msg_buf));
     message(msg_buf);
   }
 }
 
 SANITIZER_INTERFACE_WEAK_DEF(void, __ubsan_report_error_fatal, const char *kind,
-                             uintptr_t caller, const uintptr_t *address) {
+                             uintptr_t caller) {
   // Use another handlers, in case it's already overriden.
-  __ubsan_report_error(kind, caller, address);
+  __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,
-                               const uintptr_t *address) {
+static void abort_with_message(const char *kind, uintptr_t caller) {
   char msg_buf[128];
-  format_msg(kind, caller, address, msg_buf, msg_buf + sizeof(msg_buf));
+  format_msg(kind, caller, msg_buf, msg_buf + sizeof(msg_buf));
   if (&android_set_abort_message)
     android_set_abort_message(msg_buf);
   abort();
 }
 #else
-static void abort_with_message(const char *kind, uintptr_t caller,
-                               const uintptr_t *address) {
-  abort();
-}
+static void abort_with_message(const char *kind, uintptr_t caller) { abort(); }
 #endif
 
 #if SANITIZER_DEBUG
@@ -129,39 +121,21 @@ void NORETURN CheckFailed(const char *file, int, const char *cond, u64, u64) {
 
 #define HANDLER_RECOVER(name, kind)                                            \
   INTERFACE void __ubsan_handle_##name##_minimal() {                           \
-    __ubsan_report_error(kind, GET_CALLER_PC(), nullptr);                      \
+    __ubsan_report_error(kind, GET_CALLER_PC());                               \
   }
 
 #define HANDLER_NORECOVER(name, kind)                                          \
   INTERFACE void __ubsan_handle_##name##_minimal_abort() {                     \
     uintptr_t caller = GET_CALLER_PC();                                        \
-    __ubsan_report_error_fatal(kind, caller, nullptr);                         \
-    abort_with_message(kind, caller, nullptr);                                 \
+    __ubsan_report_error_fatal(kind, caller);                                  \
+    abort_with_message(kind, caller);                                          \
   }
 
 #define HANDLER(name, kind)                                                    \
   HANDLER_RECOVER(name, kind)                                                  \
   HANDLER_NORECOVER(name, kind)
 
-#define HANDLER_RECOVER_PTR(name, kind)                                        \
-  INTERFACE void __ubsan_handle_##name##_minimal(const uintptr_t address) {    \
-    __ubsan_report_error(kind, GET_CALLER_PC(), &address);                     \
-  }
-
-#define HANDLER_NORECOVER_PTR(name, kind)                                      \
-  INTERFACE void __ubsan_handle_##name##_minimal_abort(                        \
-      const uintptr_t address) {                                               \
-    uintptr_t caller = GET_CALLER_PC();                                        \
-    __ubsan_report_error_fatal(kind, caller, &address);                        \
-    abort_with_message(kind, caller, &address);                                \
-  }
-
-// A version of a handler that takes a pointer to a value.
-#define HANDLER_PTR(name, kind)                                                \
-  HANDLER_RECOVER_PTR(name, kind)                                              \
-  HANDLER_NORECOVER_PTR(name, kind)
-
-HANDLER_PTR(type_mismatch, "type-mismatch")
+HANDLER(type_mismatch, "type-mismatch")
 HANDLER(alignment_assumption, "alignment-assumption")
 HANDLER(add_overflow, "add-overflow")
 HANDLER(sub_overflow, "sub-overflow")
diff --git a/compiler-rt/test/ubsan_minimal/TestCases/misalignment.cpp b/compiler-rt/test/ubsan_minimal/TestCases/misalignment.cpp
index cf828792a324f..3f01dc8444489 100644
--- a/compiler-rt/test/ubsan_minimal/TestCases/misalignment.cpp
+++ b/compiler-rt/test/ubsan_minimal/TestCases/misalignment.cpp
@@ -7,7 +7,7 @@ int *t;
 int main() {
   int r;
   t = (int *)(((char *)&r) + 1);
-  // CHECK: ubsan: type-mismatch by 0x{{[[:xdigit:]]+}} address 0x{{[[:xdigit:]]+$}}
+  // CHECK: ubsan: type-mismatch by 0x{{[[:xdigit:]]+}}
   // CHECK-NOT: type-mismatch
   f(*t);
 }
diff --git a/compiler-rt/test/ubsan_minimal/TestCases/null.cpp b/compiler-rt/test/ubsan_minimal/TestCases/null.cpp
index c97527b72cd0c..b3d9db2b309d1 100644
--- a/compiler-rt/test/ubsan_minimal/TestCases/null.cpp
+++ b/compiler-rt/test/ubsan_minimal/TestCases/null.cpp
@@ -5,7 +5,7 @@ void f(int &n) {}
 int *t;
 
 int main() {
-  // CHECK: ubsan: type-mismatch by 0x{{[[:xdigit:]]+}} address 0x{{[[:xdigit:]]+$}}
+  // CHECK: ubsan: type-mismatch by 0x{{[[:xdigit:]]+}}
   // CHECK-NOT: type-mismatch
   f(*t);
 }

@vitalybuka vitalybuka requested a review from fmayer November 20, 2025 03:06
@vitalybuka
Copy link
Collaborator Author

CC @alazarev @padriff

@github-actions
Copy link

github-actions bot commented Nov 20, 2025

🐧 Linux x64 Test Results

  • 111347 tests passed
  • 4435 tests skipped

@fmayer
Copy link
Contributor

fmayer commented Nov 21, 2025

2025-11-20T03:10:48.4663549Z Failed Tests (4):
2025-11-20T03:10:48.4663852Z   Clang :: CodeGen/cfi-icall-trap-recover-runtime.c
2025-11-20T03:10:48.4664250Z   Clang :: CodeGen/ubsan-trap-merge.c
2025-11-20T03:10:48.4664609Z   Clang :: CodeGen/unsigned-overflow-minimal.c
2025-11-20T03:10:48.4665039Z   Clang :: CodeGenCXX/cfi-vcall-trap-recover-runtime.cpp

Created using spr 1.3.7
@vitalybuka
Copy link
Collaborator Author

done

@vitalybuka vitalybuka merged commit af098e0 into main Nov 21, 2025
8 of 9 checks passed
@vitalybuka vitalybuka deleted the users/vitalybuka/spr/revert-ubsan_minimal-allow-ubsan-handler-from-minimal-runtime-to-accept-arguments-152192 branch November 21, 2025 09:09
aadeshps-mcw pushed a commit to aadeshps-mcw/llvm-project that referenced this pull request Nov 26, 2025
…ccept arguments (llvm#152192)" (llvm#168812)

This partially reverts llvm#152192, keeping updated tests and
some code reordering in clang/lib/CodeGen/CGExpr.cpp.

compiler-rt/lib/ubsan_minimal/ubsan_minimal_handlers.cpp is exact revert
(with followup llvm#152419)

We don't have a good use case for that, so revert it before we are stuck
maintaining this API.

21.x does not have this patch.

This reverts commit a1209d8.
Priyanshu3820 pushed a commit to Priyanshu3820/llvm-project that referenced this pull request Nov 26, 2025
…ccept arguments (llvm#152192)" (llvm#168812)

This partially reverts llvm#152192, keeping updated tests and
some code reordering in clang/lib/CodeGen/CGExpr.cpp.

compiler-rt/lib/ubsan_minimal/ubsan_minimal_handlers.cpp is exact revert
(with followup llvm#152419)

We don't have a good use case for that, so revert it before we are stuck
maintaining this API.

21.x does not have this patch.

This reverts commit a1209d8.
augusto2112 pushed a commit to augusto2112/llvm-project that referenced this pull request Dec 3, 2025
…ccept arguments (llvm#152192)" (llvm#168812)

This partially reverts llvm#152192, keeping updated tests and
some code reordering in clang/lib/CodeGen/CGExpr.cpp.

compiler-rt/lib/ubsan_minimal/ubsan_minimal_handlers.cpp is exact revert
(with followup llvm#152419)

We don't have a good use case for that, so revert it before we are stuck
maintaining this API.

21.x does not have this patch.

This reverts commit a1209d8.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang:codegen IR generation bugs: mangling, exceptions, etc. compiler-rt:sanitizer compiler-rt:ubsan Undefined behavior sanitizer compiler-rt

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants