[compiler-rt] [asan] Allow OOM Policy Injection in Allocator::Allocate API (PR #196413)

Vitaly Buka via llvm-commits llvm-commits at lists.llvm.org
Sun May 31 22:57:33 PDT 2026


================
@@ -120,47 +120,47 @@ INTERCEPTOR(void*, calloc, uptr nmemb, uptr size) {
 // TODO: AIX needs a method to ensure 16-byte alignment if the incoming
 // pointer was allocated with a 16-byte alignment requirement (or perhaps
 // merely if it happens to have 16-byte alignment).
-INTERCEPTOR(void*, realloc, void *ptr, uptr size) {
+INTERCEPTOR(void*, realloc, void* ptr, uptr size) {
   if (DlsymAlloc::Use() || DlsymAlloc::PointerIsMine(ptr))
     return DlsymAlloc::Realloc(ptr, size);
   GET_STACK_TRACE_MALLOC;
   return asan_realloc(ptr, size, &stack);
 }
 
-#if SANITIZER_INTERCEPT_REALLOCARRAY
-INTERCEPTOR(void*, reallocarray, void *ptr, uptr nmemb, uptr size) {
+#  if SANITIZER_INTERCEPT_REALLOCARRAY
+INTERCEPTOR(void*, reallocarray, void* ptr, uptr nmemb, uptr size) {
   AsanInitFromRtl();
   GET_STACK_TRACE_MALLOC;
   return asan_reallocarray(ptr, nmemb, size, &stack);
 }
-#endif  // SANITIZER_INTERCEPT_REALLOCARRAY
+#  endif  // SANITIZER_INTERCEPT_REALLOCARRAY
 
-#if SANITIZER_INTERCEPT_MEMALIGN
+#  if SANITIZER_INTERCEPT_MEMALIGN
 INTERCEPTOR(void*, memalign, uptr boundary, uptr size) {
   GET_STACK_TRACE_MALLOC;
-  return asan_memalign(boundary, size, &stack);
+  return asan_memalign(boundary, size, &stack, AllocatorMayReturnNull());
----------------
vitalybuka wrote:

I agree that this is negligible, but unnecessary, and it does not too complicated to me, to call it brittle. But this issue is not deal breaker to me. Up to you.

Exposing AllocatorMayReturnNull() was important to me. Thanks for changing this!

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


More information about the llvm-commits mailing list