[clang] [LifetimeSafety] Add support for `new`/`delete` (PR #192504)
Utkarsh Saxena via cfe-commits
cfe-commits at lists.llvm.org
Sun Apr 19 10:48:38 PDT 2026
================
@@ -195,33 +221,33 @@ class LifetimeChecker {
/// Get loans directly pointing to the invalidated container
LoanSet DirectlyInvalidatedLoans =
LoanPropagation.getLoans(InvalidatedOrigin, IOF);
- auto IsInvalidated = [&](const Loan *L) {
+ auto IsInvalidated = [&](const LoanID &LID) {
for (LoanID InvalidID : DirectlyInvalidatedLoans) {
const Loan *InvalidL = FactMgr.getLoanMgr().getLoan(InvalidID);
+ const Loan *L = FactMgr.getLoanMgr().getLoan(LID);
+
if (InvalidL->getAccessPath() == L->getAccessPath())
return true;
}
return false;
};
// For each live origin, check if it holds an invalidated loan and report.
LivenessMap Origins = LiveOrigins.getLiveOriginsAt(IOF);
- for (auto &[OID, LiveInfo] : Origins) {
- LoanSet HeldLoans = LoanPropagation.getLoans(OID, IOF);
- for (LoanID LiveLoanID : HeldLoans)
- if (IsInvalidated(FactMgr.getLoanMgr().getLoan(LiveLoanID))) {
- bool CurDomination = causingFactDominatesExpiry(LiveInfo.Kind);
- bool LastDomination =
- FinalWarningsMap.lookup(LiveLoanID).CausingFactDominatesExpiry;
- if (!LastDomination) {
- FinalWarningsMap[LiveLoanID] = {
- /*ExpiryLoc=*/{},
- /*CausingFact=*/LiveInfo.CausingFact,
- /*MovedExpr=*/nullptr,
- /*InvalidatedByExpr=*/IOF->getInvalidationExpr(),
- /*CausingFactDominatesExpiry=*/CurDomination};
- }
- }
- }
+ recordWarningsForMatchingLoans(IOF->getInvalidationExpr(), IOF,
+ IsInvalidated);
+ }
+
+ void checkDestroyed(const DestroyOriginFact *DOF) {
+ OriginID DestroyedOrigin = DOF->getDestroyedOrigin();
+ LoanSet DirectlyDestroyedLoans =
+ LoanPropagation.getLoans(DestroyedOrigin, DOF);
+ LivenessMap Origins = LiveOrigins.getLiveOriginsAt(DOF);
+
+ auto IsDestroyed = [&DirectlyDestroyedLoans](const LoanID &LID) {
----------------
usx95 wrote:
super nit: let's remove the explicit capture and just have `&`
https://github.com/llvm/llvm-project/pull/192504
More information about the cfe-commits
mailing list