[llvm-branch-commits] [clang] [LifetimeSafety][NFC] Update Checker to use prefix comparison interfaces (PR #207519)
Utkarsh Saxena via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Sat Jul 4 12:17:15 PDT 2026
https://github.com/usx95 updated https://github.com/llvm/llvm-project/pull/207519
>From 16f77ac1a8dedc19b87aaa7361239135ae25696d Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena <usx at google.com>
Date: Sat, 4 Jul 2026 16:17:19 +0000
Subject: [PATCH] [LifetimeSafety][NFC] Update Checker to use prefix comparison
interfaces
This patch switches the Checker's expiry and invalidation checks to use `AccessPath::isPrefixOf` instead of equality (`==`).
Since all generated access paths are currently empty, `isPrefixOf` is behaviorally identical to `==` (NFC). This prepares the checker to handle nested paths (fields and container interiors) in subsequent commits.
TAG=agy
CONV=2cfd8d00-18d7-4a03-8d78-2aba2f9a8f23
---
clang/lib/Analysis/LifetimeSafety/Checker.cpp | 34 +++++++++----------
.../Analysis/LifetimeSafety/MovedLoans.cpp | 2 +-
2 files changed, 18 insertions(+), 18 deletions(-)
diff --git a/clang/lib/Analysis/LifetimeSafety/Checker.cpp b/clang/lib/Analysis/LifetimeSafety/Checker.cpp
index 4deead08e6fed..7bb02394138aa 100644
--- a/clang/lib/Analysis/LifetimeSafety/Checker.cpp
+++ b/clang/lib/Analysis/LifetimeSafety/Checker.cpp
@@ -188,22 +188,22 @@ class LifetimeChecker {
LoanSet HeldLoans = LoanPropagation.getLoans(OID, EF);
for (LoanID HeldLoanID : HeldLoans) {
const Loan *HeldLoan = FactMgr.getLoanMgr().getLoan(HeldLoanID);
- if (ExpiredPath != HeldLoan->getAccessPath())
- continue;
- // HeldLoan is expired because its AccessPath is expired.
- PendingWarning &CurWarning = FinalWarningsMap[HeldLoan->getID()];
- const Expr *MovedExpr = nullptr;
- if (auto *ME = MovedLoans.getMovedLoans(EF).lookup(HeldLoanID))
- MovedExpr = *ME;
- // Skip if we already have a dominating causing fact.
- if (CurWarning.CausingFactDominatesExpiry)
- continue;
- if (causingFactDominatesExpiry(LiveInfo.Kind))
- CurWarning.CausingFactDominatesExpiry = true;
- CurWarning.CausingFact = LiveInfo.CausingFact;
- CurWarning.ExpiryLoc = EF->getExpiryLoc();
- CurWarning.MovedExpr = MovedExpr;
- CurWarning.InvalidatedByExpr = nullptr;
+ if (ExpiredPath.isPrefixOf(HeldLoan->getAccessPath())) {
+ // HeldLoan is expired because its base or itself is expired.
+ PendingWarning &CurWarning = FinalWarningsMap[HeldLoan->getID()];
+ const Expr *MovedExpr = nullptr;
+ if (auto *ME = MovedLoans.getMovedLoans(EF).lookup(HeldLoanID))
+ MovedExpr = *ME;
+ // Skip if we already have a dominating causing fact.
+ if (CurWarning.CausingFactDominatesExpiry)
+ continue;
+ if (causingFactDominatesExpiry(LiveInfo.Kind))
+ CurWarning.CausingFactDominatesExpiry = true;
+ CurWarning.CausingFact = LiveInfo.CausingFact;
+ CurWarning.ExpiryLoc = EF->getExpiryLoc();
+ CurWarning.MovedExpr = MovedExpr;
+ CurWarning.InvalidatedByExpr = nullptr;
+ }
}
}
}
@@ -223,7 +223,7 @@ class LifetimeChecker {
auto IsInvalidated = [&](const Loan *L) {
for (LoanID InvalidID : DirectlyInvalidatedLoans) {
const Loan *InvalidL = FactMgr.getLoanMgr().getLoan(InvalidID);
- if (InvalidL->getAccessPath() == L->getAccessPath())
+ if (InvalidL->getAccessPath().isPrefixOf(L->getAccessPath()))
return true;
}
return false;
diff --git a/clang/lib/Analysis/LifetimeSafety/MovedLoans.cpp b/clang/lib/Analysis/LifetimeSafety/MovedLoans.cpp
index 138704821024a..1a9ce3e576733 100644
--- a/clang/lib/Analysis/LifetimeSafety/MovedLoans.cpp
+++ b/clang/lib/Analysis/LifetimeSafety/MovedLoans.cpp
@@ -80,7 +80,7 @@ class AnalysisImpl
auto IsInvalidated = [&](const AccessPath &Path) {
for (LoanID LID : ImmediatelyMovedLoans) {
const Loan *MovedLoan = LoanMgr.getLoan(LID);
- if (MovedLoan->getAccessPath() == Path)
+ if (MovedLoan->getAccessPath().isPrefixOf(Path))
return true;
}
return false;
More information about the llvm-branch-commits
mailing list