[clang] [NFC] Clarify behavior of ownership_holds in docs (PR #197933)
DonĂ¡t Nagy via cfe-commits
cfe-commits at lists.llvm.org
Fri May 15 06:20:28 PDT 2026
https://github.com/NagyDonat created https://github.com/llvm/llvm-project/pull/197933
I misunderstood the behavior of the attribute `ownership_holds` based on the claim that "using held memory is assumed to be legitimate".
To avoid similar misunderstandings in the future, I'm adding an extra sentence to the documentation.
(This question came up during the discussion of #196798)
>From 4fd07d7b226140f64000c8ae490fe165c792915d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Don=C3=A1t=20Nagy?= <donat.nagy at ericsson.com>
Date: Fri, 15 May 2026 15:02:00 +0200
Subject: [PATCH] [NFC] Clarify behavior of ownership_holds in docs
I misunderstood the behavior of the attribute `ownership_holds` based on
the claim that "using held memory is assumed to be legitimate".
To avoid similar misunderstandings in the future, I'm adding an extra
sentence to the documentation.
---
clang/docs/analyzer/user-docs/Annotations.rst | 3 ++-
clang/include/clang/Basic/AttrDocs.td | 4 +++-
2 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/clang/docs/analyzer/user-docs/Annotations.rst b/clang/docs/analyzer/user-docs/Annotations.rst
index 3b5a13fd91d9b..273bdf4fd1731 100644
--- a/clang/docs/analyzer/user-docs/Annotations.rst
+++ b/clang/docs/analyzer/user-docs/Annotations.rst
@@ -207,7 +207,8 @@ Use this attribute to mark functions that take ownership of memory and will deal
void __attribute((ownership_holds(malloc, 2))) store_in_table(int key, record_t *val);
-The annotations ``ownership_takes`` and ``ownership_holds`` both prevent memory leak reports (concerning the specified parameter); the difference between them is that using taken memory is a use-after-free error, while using held memory is assumed to be legitimate.
+The annotations ``ownership_takes`` and ``ownership_holds`` both prevent memory leak reports (concerning the specified parameter); the difference between them is that using taken memory is a use-after-free error, while using held memory is assumed to be legitimate. (However, releasing the held memory or passing it to another holding call is reported by the analyzer as an "attempt to release non-owned memory".)
+
Mac OS X API Annotations
________________________
diff --git a/clang/include/clang/Basic/AttrDocs.td b/clang/include/clang/Basic/AttrDocs.td
index 4b45f413054f3..e20291f27d642 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -1663,7 +1663,9 @@ safely deallocated with the standard ``free()``.
The annotations ``ownership_takes`` and ``ownership_holds`` both prevent memory
leak reports (concerning the specified parameter); the difference between them
is that using taken memory is a use-after-free error, while using held memory
-is assumed to be legitimate.
+is assumed to be legitimate. (However, releasing the held memory or passing it
+to another holding call is reported by the analyzer as an "attempt to release
+non-owned memory".)
Example:
More information about the cfe-commits
mailing list