[compiler-rt] [sanitizer_common] Add operator new chain-handling framework (PR #201151)

David Justo via llvm-commits llvm-commits at lists.llvm.org
Sat Jun 13 11:55:44 PDT 2026


================
@@ -0,0 +1,140 @@
+//===-- sanitizer_new_handler.h ---------------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This file is shared between run-time libraries of sanitizers.
+//
+// It provides the operator new chain-handling framework required by
+// [new.delete.single]/3+/4: a std::get_new_handler() loop plus the
+// throwing / nothrow exhaustion policies that compose with it. Each
+// sanitizer's operator new wrapper supplies two small lambdas:
+//
+//   * Alloc        — invokes the sanitizer's internal allocator, returning
+//                    nullptr on OOM (never aborting on OOM). Non-OOM
+//                    failure modes (e.g. invalid alignment) are the
+//                    caller's responsibility to detect and report before
----------------
davidmrdavid wrote:

by 'caller' here you mean the allocator itself? I'd recommend making this blurb about 'non-OOM failures' a bit simpler to read. I think it should read 'Non-OOM failures should be handled by the allocator itself, not to be handled by the std::get_new_handler() chain'

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


More information about the llvm-commits mailing list