[clang] [LifetimeSafety] Track origins for lifetimebound calls returning record types (PR #187917)
Utkarsh Saxena via cfe-commits
cfe-commits at lists.llvm.org
Thu Mar 26 03:43:56 PDT 2026
================
@@ -688,9 +707,9 @@ void FactsGenerator::handleFunctionCall(const Expr *Call,
ArgList = getRValueOrigins(Args[I], ArgList);
}
if (isGslOwnerType(Args[I]->getType())) {
- // GSL construction creates a view that borrows from arguments.
- // This implies flowing origins through the list structure.
- flow(CallList, ArgList, KillSrc);
+ CurrentBlockFacts.push_back(FactMgr.createFact<OriginFlowFact>(
----------------
usx95 wrote:
\+1 to add documentation for this. I believe the reason is that owners can now also have origins associated and the origin list would not match for l-value owner expression.
`std::unique_ptr\<S> foo(const int& I [[lifetimebound]])`
This was previously added as test in this PR
```cpp
MyObj getMyObj(const MyObj &obj [[clang::lifetimebound]]);
void gsl_owner_return_does_not_crash() {
MyObj obj;
View v = obj;
getMyObj(obj);
use(v);
}
```
I guess a better example is
```cpp
std::vector<std::string_view> create(const std::string& str [[clang::lifetimebound]]);
std::span<std::string_view> foo() {
std::string local = "local";
auto views = create(local);
return views;
}
```
https://github.com/llvm/llvm-project/pull/187917
More information about the cfe-commits
mailing list