[clang] [clang][docs] Improve documentation of [[ownership_returns]] attribute (PR #191005)
Balázs Benics via cfe-commits
cfe-commits at lists.llvm.org
Wed Apr 8 09:58:53 PDT 2026
================
@@ -174,12 +174,21 @@ If a project uses custom functions for dynamic memory management (that e.g. act
Attribute 'ownership_returns' (Clang-specific)
----------------------------------------------
-Use this attribute to mark functions that return dynamically allocated memory. Takes a single argument, the type of the allocation (e.g. ``malloc`` or ``new``).
+Use this attribute to mark functions that return dynamically allocated memory.
+The first argument is the type of the allocation (e.g. ``malloc``, ``new``, or any other identifier).
+An optional second argument is the 1-based index of the function parameter that specifies the allocation size in bytes.
+The referenced parameter must have an integral type.
+
+This attribute may appear at most once per function declaration.
.. code-block:: c
+ // Without size parameter:
void __attribute((ownership_returns(malloc))) *my_malloc(size_t);
----------------
steakhal wrote:
```suggestion
void __attribute((ownership_returns(malloc))) *my_malloc(size_t sz);
```
https://github.com/llvm/llvm-project/pull/191005
More information about the cfe-commits
mailing list