diff options
author | Utkarsh Saxena <usx@google.com> | 2025-09-11 15:52:30 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-09-11 15:52:30 +0200 |
commit | 3e18b5af257463718edfdca791215f09f97d2209 (patch) | |
tree | 3e15af92ed5c9caf9bc58e0212de7e2619f5bb6d /llvm/unittests/Support/MathExtrasTest.cpp | |
parent | e1aa2dff8a7a53fec14130e77d7da15d0ac482ca (diff) | |
download | llvm-3e18b5af257463718edfdca791215f09f97d2209.zip llvm-3e18b5af257463718edfdca791215f09f97d2209.tar.gz llvm-3e18b5af257463718edfdca791215f09f97d2209.tar.bz2 |
[LifetimeSafety] Associate origins to all l-valued expressions (#156896)
This patch refactors the C++ lifetime safety analysis to implement a more consistent model for tracking borrows. The central idea is to make loan creation a consequence of referencing a variable, while making loan propagation dependent on the type's semantics.
This change introduces a more uniform model for tracking borrows from non-pointer types:
* Centralised Loan Creation: A Loan is now created for every `DeclRefExpr` that refers to a **non-pointer type** (e.g., `std::string`, `int`). This correctly models that any use of an **gl-value** is a borrow of its storage, replacing the previous heuristic-based loan creation.
* The address-of operator (&) no longer creates loans. Instead, it propagates the origin (and thus the loans) of its sub-expression. This is guarded to exclude expressions that are already pointer types, deferring the complexity of pointers-to-pointers.
**Future Work: Multi-Origin Model**
This patch deliberately defers support for creating loans on references to pointer-type expressions (e.g., `&my_pointer`). The current single-origin model is unable to distinguish between a loan to the pointer variable itself (its storage) and a loan to the object it points to. The future plan is to move to a multi-origin model where a type has a "list of origins" governed by its level of indirection, which will allow the analysis to track these distinct lifetimes separately. Once this more advanced model is in place, the restriction can be lifted, and all `DeclRefExpr` nodes, regardless of type, can uniformly create a loan, making the analysis consistent.
Diffstat (limited to 'llvm/unittests/Support/MathExtrasTest.cpp')
0 files changed, 0 insertions, 0 deletions