[clang] 9fda68e - [Clang] Document the interaction of malloc_span and alloc_size (#216967)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Sep 14 04:14:41 PDT 2026
Author: Nikolas Klauser
Date: 2026-09-14T13:14:37+02:00
New Revision: 9fda68e41dcb8d19751bc042508eeee8bd9c596a
URL: https://github.com/llvm/llvm-project/commit/9fda68e41dcb8d19751bc042508eeee8bd9c596a
DIFF: https://github.com/llvm/llvm-project/commit/9fda68e41dcb8d19751bc042508eeee8bd9c596a.diff
LOG: [Clang] Document the interaction of malloc_span and alloc_size (#216967)
The `malloc_span` attribute is intended to be used for
`allocate_at_least`-like functions. Part of that interface is a
guarantee that the number of bytes returned are actually
dereferenceable. Document that, so that we can optimize on it in the
future.
Added:
Modified:
clang/include/clang/Basic/AttrDocs.td
Removed:
################################################################################
diff --git a/clang/include/clang/Basic/AttrDocs.td b/clang/include/clang/Basic/AttrDocs.td
index 1bbaae8b21106..3b733b820bed5 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -5572,6 +5572,11 @@ members, one of which is a pointer to the start of the allocated memory and
the other one is either an integer type containing the size of the actually
allocated memory or a pointer to the end of the allocated region. Note, static
data members do not impact whether a type is span-like or not.
+
+In combination with the `alloc_size` attribute, if the begin pointer is
+non-null, the size of the returned span-like object has to be greater or equal
+to the number of bytes guaranteed to be dereferenceable by `alloc_size`. It also
+guarantees that the number of dereferenceable bytes is at least size.
}];
}
More information about the cfe-commits
mailing list