[all-commits] [llvm/llvm-project] 0e17fc: [LifetimeSafety] Implement support for lifetimebou...

Utkarsh Saxena via All-commits all-commits at lists.llvm.org
Thu Sep 25 15:44:46 PDT 2025


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 0e17fcf93b6c4a53e23c3ba8ee8961ff3b1a7fba
      https://github.com/llvm/llvm-project/commit/0e17fcf93b6c4a53e23c3ba8ee8961ff3b1a7fba
  Author: Utkarsh Saxena <usx at google.com>
  Date:   2025-09-25 (Thu, 25 Sep 2025)

  Changed paths:
    A clang/include/clang/Analysis/Analyses/LifetimeAnnotations.h
    M clang/include/clang/Analysis/Analyses/LifetimeSafety.h
    M clang/lib/Analysis/CMakeLists.txt
    A clang/lib/Analysis/LifetimeAnnotations.cpp
    M clang/lib/Analysis/LifetimeSafety.cpp
    M clang/lib/Sema/CheckExprLifetime.cpp
    M clang/lib/Sema/CheckExprLifetime.h
    M clang/lib/Sema/SemaAPINotes.cpp
    M clang/test/Analysis/LifetimeSafety/benchmark.py
    M clang/test/Sema/warn-lifetime-safety-dataflow.cpp
    M clang/test/Sema/warn-lifetime-safety.cpp
    M clang/unittests/Analysis/LifetimeSafetyTest.cpp

  Log Message:
  -----------
  [LifetimeSafety] Implement support for lifetimebound attribute (#158489)

Add support for `lifetimebound` attributes in the lifetime safety
analysis to track loans from function parameters to return values.

Implemented support for `lifetimebound` attributes on function
parameters

This change replaces the single `AssignOriginFact` with two separate
operations: `OriginFlowFact` and `KillOriginFact`. The key difference is
in semantics:

* Old `AssignOriginFact`: Replaced the destination origin's loans
entirely with the source origin's loans.
* New `OriginFlowFact`: Can now optionally merge the source origin's
loans to the destination's existing loans.
* New `KillOriginFact`: Clears all loans from an origin.

For function calls with `lifetimebound` parameters, we kill the the
return value' origin first then use `OriginFlowFact` to accumulate loans
from multiple parameters into the return value's origin - enabling
tracking multiple lifetimebound arguments.

- Added a new `LifetimeAnnotations.h/cpp` to provide helper functions
for inspecting and inferring lifetime annotations
- Moved several functions from `CheckExprLifetime.cpp` to the new file
to make them reusable

The `lifetimebound` attribute is a key mechanism for expressing lifetime
dependencies between function parameters and return values. This change
enables the lifetime safety analysis to properly track these
dependencies, allowing it to detect more potential dangling reference
issues.



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list