From 4fd07d7b226140f64000c8ae490fe165c792915d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Don=C3=A1t=20Nagy?= Date: Fri, 15 May 2026 15:02:00 +0200 Subject: [PATCH 1/2] [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: From 52873f652efcae4c7f01472cb6614fb8427db218 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Don=C3=A1t=20Nagy?= Date: Tue, 19 May 2026 12:43:53 +0200 Subject: [PATCH 2/2] Remove parentheses MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Kristóf Umann --- clang/docs/analyzer/user-docs/Annotations.rst | 2 +- clang/include/clang/Basic/AttrDocs.td | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/clang/docs/analyzer/user-docs/Annotations.rst b/clang/docs/analyzer/user-docs/Annotations.rst index 273bdf4fd1731..957fc8d273c6a 100644 --- a/clang/docs/analyzer/user-docs/Annotations.rst +++ b/clang/docs/analyzer/user-docs/Annotations.rst @@ -207,7 +207,7 @@ 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. (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".) +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 e20291f27d642..19d14837679d3 100644 --- a/clang/include/clang/Basic/AttrDocs.td +++ b/clang/include/clang/Basic/AttrDocs.td @@ -1663,9 +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. (However, releasing the held memory or passing it +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".) +non-owned memory". Example: