[clang] [LifetimeSafety] Introduce buildOriginFlowChain for use-after-scope (PR #199345)
Utkarsh Saxena via cfe-commits
cfe-commits at lists.llvm.org
Sun May 24 10:00:25 PDT 2026
================
@@ -70,6 +80,19 @@ class LifetimeSafetySemaHelperImpl : public LifetimeSafetySemaHelper {
S.Diag(MovedExpr->getExprLoc(), diag::note_lifetime_safety_moved_here)
<< MovedExpr->getSourceRange();
S.Diag(FreeLoc, diag::note_lifetime_safety_destroyed_here);
+
+ StringRef IssueStr;
+ for (const Expr *CurrExpr : reverse(OriginExprChain)) {
+ if (IssueStr.empty()) {
+ IssueStr = formatExpr(CurrExpr);
+ continue;
+ }
+
+ S.Diag(CurrExpr->getBeginLoc(),
+ diag::note_lifetime_safety_note_alias_chain)
+ << CurrExpr->getSourceRange() << formatExpr(CurrExpr) << IssueStr;
+ }
----------------
usx95 wrote:
Let's do this in a separate method.
`void reportAliasingChain(llvm::ArrayRef<const Expr *> OriginExprChain);`
https://github.com/llvm/llvm-project/pull/199345
More information about the cfe-commits
mailing list