https://github.com/usx95 created https://github.com/llvm/llvm-project/pull/207519
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 >From c87697ba6b96032dcc13f7453a7c940c32409f2f Mon Sep 17 00:00:00 2001 From: Utkarsh Saxena <[email protected]> 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 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/clang/lib/Analysis/LifetimeSafety/Checker.cpp b/clang/lib/Analysis/LifetimeSafety/Checker.cpp index 074c34b1a9aaf..a749a49e7762a 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; _______________________________________________ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
