llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[LifetimeSafety] Verify lifetimebound param escapes via return

Open usx95 opened this issue 9 months ago • 2 comments

std::string_view identity(const std::string& in) { return in; }

std::string_view max(const std::string& a [[clang::lifetimebound]], 
                                     const std::string& b [[clang::lifetimebound]]) {
  return a > b ? identity(a): identity(b);
}

For verification of lifetimebound, we need to verify that annotated parameter escapes via return.

For example, in the above snippet, we must get a warning that lifetimebound on a and b cannot be verified. In order for the analysis to deduce a escape via return, identity must be annotated with lifetimebound.

cc: @AbhinavPradeep

usx95 avatar Feb 23 '26 20:02 usx95

@llvm/issue-subscribers-clang-temporal-safety

Author: Utkarsh Saxena (usx95)

```cpp std::string_view identity(const std::string& in) { return in; }

std::string_view max(const std::string& a [[clang::lifetimebound]], const std::string& b [[clang::lifetimebound]]) { return a > b ? identity(a): identity(b); }


For verification of `lifetimebound`, we need to verify that annotated parameter escapes via `return`.

For example, in the above snippet, we must get a warning that `lifetimebound` on `a` and `b` cannot be verified. In order for the analysis to deduce a escape via return, `identity` must be annotated with `lifetimebound`.  

cc: @<!-- -->AbhinavPradeep 
</details>

llvmbot avatar Feb 23 '26 20:02 llvmbot

I will try to work on this.

NeKon69 avatar May 03 '26 15:05 NeKon69