https://github.com/usx95 created https://github.com/llvm/llvm-project/pull/180446
None >From 3da80f8bf7985c7cef37867de5e3580e5a5f4922 Mon Sep 17 00:00:00 2001 From: Utkarsh Saxena <[email protected]> Date: Sun, 8 Feb 2026 22:29:52 +0000 Subject: [PATCH] Improve liveness to detect more invaldiations --- clang/lib/Analysis/LifetimeSafety/FactsGenerator.cpp | 6 ++++++ clang/test/Sema/warn-lifetime-safety-invalidations.cpp | 8 +++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/clang/lib/Analysis/LifetimeSafety/FactsGenerator.cpp b/clang/lib/Analysis/LifetimeSafety/FactsGenerator.cpp index b69f69ddbae34..40661289b2f2b 100644 --- a/clang/lib/Analysis/LifetimeSafety/FactsGenerator.cpp +++ b/clang/lib/Analysis/LifetimeSafety/FactsGenerator.cpp @@ -366,6 +366,9 @@ void FactsGenerator::VisitBinaryOperator(const BinaryOperator *BO) { // result should have the same loans as the pointer operand. if (BO->isCompoundAssignmentOp()) return; + if (auto *RHSOrigins = getOriginsList(*BO->getRHS())) + CurrentBlockFacts.push_back( + FactMgr.createFact<UseFact>(BO->getRHS(), RHSOrigins)); if (BO->isAssignmentOp()) handleAssignment(BO->getLHS(), BO->getRHS()); // TODO: Handle assignments involving dereference like `*p = q`. @@ -582,6 +585,9 @@ void FactsGenerator::handleFunctionCall(const Expr *Call, FD = getDeclWithMergedLifetimeBoundAttrs(FD); if (!FD) return; + for (const Expr *Arg : Args) + if (OriginList *ArgList = getOriginsList(*Arg)) + CurrentBlockFacts.push_back(FactMgr.createFact<UseFact>(Arg, ArgList)); handleInvalidatingCall(Call, FD, Args); handleMovedArgsInCall(FD, Args); diff --git a/clang/test/Sema/warn-lifetime-safety-invalidations.cpp b/clang/test/Sema/warn-lifetime-safety-invalidations.cpp index c9ce0c35c53d2..d7994d35411be 100644 --- a/clang/test/Sema/warn-lifetime-safety-invalidations.cpp +++ b/clang/test/Sema/warn-lifetime-safety-invalidations.cpp @@ -260,9 +260,11 @@ void PointerToVectorElement() { } void SelfInvalidatingMap() { - std::unordered_map<int, int> mp; - mp[1] = 1; - mp[2] = mp[1]; // FIXME: Detect this. We are mising a UseFact for the assignment params. + std::unordered_map<int, std::string> mp; + mp[1] = "42"; + mp[2] = mp[1]; // expected-warning {{object whose reference is captured is later invalidated}} \ + // expected-note {{invalidated here}} \ + // expected-note {{later used here}} } } // namespace ElementReferences _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
