[llvm-branch-commits] [clang] [analyzer][docs] Add documentation for the UseAfterLifetimeEnd checker (PR #217122)

Benedek Kaibas via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Wed Aug 19 03:20:16 PDT 2026


================
@@ -3304,6 +3304,65 @@ it. This can lead to false positives.
    is_null(ptr); // false positive: the pointer is compared, not dereferenced
  }
 
+.. _alpha-core-UseAfterLifetimeEnd:
+
+alpha.core.UseAfterLifetimeEnd (C, C++)
+"""""""""""""""""""""""""""""""""""""""
+Check for returned pointers and references that are bound to an object whose
+lifetime ends when the function returns. The checker only analyzes code that
+is annotated with the ``[[clang::lifetimebound]]`` attribute. The annotation
+tells the checker which object the returned value is bound to.
+
+.. code-block:: cpp
+
+ int *bound(int *p [[clang::lifetimebound]]);
+
+ int *direct_return() {
+   int i = 5; // note: 'i' initialized here
+   return bound(&i); // warn: returning value bound to 'i' that will go
+                     //       out of scope
+ }
+
+The attribute states that the returned value may refer to the annotated
----------------
benedekaibas wrote:

Yes, yes, this is the scenario I wanted to add just forgot. You are right! Thanks for the reminder will include it.

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


More information about the llvm-branch-commits mailing list