[clang] [compiler-rt] [ubsan_minimal] Allow UBSan handler from Minimal runtime to acceprt arguments (PR #152192)

Vitaly Buka via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 6 10:07:15 PDT 2025


================
@@ -3717,6 +3717,33 @@ static void emitCheckHandlerCall(CodeGenFunction &CGF,
   }
 }
 
+// Adapts the arguments to the handler function.
+// It is expected that {StaticArgs..., DynamicArgs...} sequence matches the
+// corresponding XxxData type from the ubsan_handlers.h file.
+// Minimal hadler can use a subset of the arguments.
+static void
+AdaptArgsToHandler(CodeGenModule &CGM, SanitizerHandler CheckHandler,
+                   ArrayRef<llvm::Constant *> StaticArgs,
+                   ArrayRef<llvm::Value *> DynamicArgs,
+                   SmallVectorImpl<llvm::Constant *> &HandlerStaticArgs,
+                   SmallVectorImpl<llvm::Value *> &HandlerDynamicArgs) {
+  if (!CGM.getCodeGenOpts().SanitizeMinimalRuntime) {
+    HandlerStaticArgs.assign(StaticArgs.begin(), StaticArgs.end());
+    HandlerDynamicArgs.assign(DynamicArgs.begin(), DynamicArgs.end());
+    return;
+  }
+
+  switch (CheckHandler) {
+  case SanitizerHandler::TypeMismatch:
+    // Pass value pointer only. It adds minimal overhead.
+    HandlerDynamicArgs.assign(DynamicArgs.begin(), DynamicArgs.end());
----------------
vitalybuka wrote:

Express somehow that we know the position of the pointer.

e.g. `assert(DynamicArgs.size() == 0);`
or
`HandlerDynamicArgs.push_back(DynamicArgs[0]);`

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


More information about the llvm-commits mailing list