[clang] [LifetimeSafety] Revamp how accesses and uses are handled (PR #225799)
Gábor Horváth via cfe-commits
cfe-commits at lists.llvm.org
Thu Sep 24 06:05:53 PDT 2026
================
@@ -557,14 +558,22 @@ class LifetimeChecker {
/// Given a chain of origins that shows how a loan propagates, this function
/// extracts the corresponding expressions for each origin. Origins that refer
/// to declarations (rather than expressions) are skipped.
+ ///
+ /// Until the chain reaches a declaration it is inside the use expression,
+ /// where casts just load the used variable.
llvm::SmallVector<const Expr *>
getExprChain(llvm::ArrayRef<OriginID> OriginFlowChain) {
- llvm::SmallVector<const Expr *> rs;
- for (const OriginID CurrOID : OriginFlowChain)
- if (const Expr *CurrExpr =
- FactMgr.getOriginMgr().getOrigin(CurrOID).getExpr())
- rs.push_back(CurrExpr);
- return rs;
+ llvm::SmallVector<const Expr *> Chain;
+ bool InUse = true;
+ for (const OriginID CurrOID : OriginFlowChain) {
+ const Expr *CurrExpr =
+ FactMgr.getOriginMgr().getOrigin(CurrOID).getExpr();
+ if (!CurrExpr)
+ InUse = false;
+ else if (!InUse || !isa<ImplicitCastExpr>(CurrExpr))
+ Chain.push_back(CurrExpr);
+ }
+ return Chain;
}
----------------
Xazax-hun wrote:
I moved it over to `buildOriginFlowChain`. If you still prefer it to be in a separate PR, I can look into it.
https://github.com/llvm/llvm-project/pull/225799
More information about the cfe-commits
mailing list