[compiler-rt] [llvm] [asan] Adopt sanitizer_common operator-new framework (PR #196388)

Justin T. Gibbs via llvm-commits llvm-commits at lists.llvm.org
Sun Sep 27 13:49:42 PDT 2026


================
@@ -1206,10 +1206,13 @@ uptr asan_malloc_usable_size(const void* ptr, uptr pc, uptr bp) {
 
 namespace {
 
+// Force may_return_null=true so the Alloc lambdas in asan_new_delete.cpp
+// satisfy the operator-new framework's contract (return nullptr on OOM
+// failure rather than abort).
 void* asan_new(uptr size, BufferedStackTrace* stack, bool array) {
-  return SetErrnoOnNull(instance.Allocate(size, /*alignment=*/0, stack,
-                                          array ? FROM_NEW_BR : FROM_NEW,
-                                          /*can_fill=*/true));
+  return SetErrnoOnNull(instance.AllocateImpl(
+      size, /*alignment=*/0, stack, array ? FROM_NEW_BR : FROM_NEW,
+      /*can_fill=*/true, /*may_return_null=*/true));
 }
----------------
scsiguy wrote:

Adjusted both `asan_new` and `asan_new_aligned`. The comment is now inside the function
body:
```
    // Return nullptr, not abort, when storage cannot be obtained so the operator
    // new framework can run the std::get_new_handler() loop and then apply the
    // allocator_may_return_null flag.
```

The `may_return_null` local override is easy to see in the code, so I don't think it needs to be restated in the comment.

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


More information about the llvm-commits mailing list