[llvm] [LangRef] Mention allocation elision (PR #177592)

Ralf Jung via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 26 01:44:46 PST 2026


================
@@ -2077,6 +2077,15 @@ For example:
     The first three options are mutually exclusive, and the remaining options
     describe more details of how the function behaves. The remaining options
     are invalid for "free"-type functions.
+
+    Calls to functions annotated with ``allockind`` are subject to allocation
+    elision: Calls to allocator functions can be removed, and the allocation
+    served from a virtual allocator instead. Notably, this is allowed even if
+    the allocator calls have side-effects.
+
+    If multiple allocation functions operate on the same allocation (for
+    example, an "alloc" followed by "free"), allocation elision is only allowed
+    if all involved functions have the same ``"alloc-family"``.
----------------
RalfJung wrote:

> For example, if we have an alloc + realloc + free, we can convert that into alloc + free

That remaining alloc call then has the size of the realloc call, I presume? (Assuming that realloc is used to grow the allocation.)

That means the final actual call made to the allocator does not fully correspond to a call in the source program. We could try to come up with an operational approach that precisely captures this, but I wonder if it's not easier or even more accurate to say that LLVM is allowed to synthesize new calls to the allocator following the usual allocator contract?

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


More information about the llvm-commits mailing list