https://github.com/usx95 updated https://github.com/llvm/llvm-project/pull/153661
>From 18779377bf68b0fbb88fb849c9c3e2224210bbf7 Mon Sep 17 00:00:00 2001 From: Utkarsh Saxena <u...@google.com> Date: Thu, 14 Aug 2025 06:57:44 +0000 Subject: [PATCH] [LifetimeSafety] Track view types/gsl::Pointer. --- clang/lib/Analysis/LifetimeSafety.cpp | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/clang/lib/Analysis/LifetimeSafety.cpp b/clang/lib/Analysis/LifetimeSafety.cpp index c762f63c45e09..591002692d43b 100644 --- a/clang/lib/Analysis/LifetimeSafety.cpp +++ b/clang/lib/Analysis/LifetimeSafety.cpp @@ -396,18 +396,30 @@ class FactGenerator : public ConstStmtVisitor<FactGenerator> { // initializations and destructions are processed in the correct sequence. for (const CFGBlock *Block : *AC.getAnalysis<PostOrderCFGView>()) { CurrentBlockFacts.clear(); + VisitedStmts.clear(); for (unsigned I = 0; I < Block->size(); ++I) { const CFGElement &Element = Block->Elements[I]; - if (std::optional<CFGStmt> CS = Element.getAs<CFGStmt>()) + if (std::optional<CFGStmt> CS = Element.getAs<CFGStmt>()) { + DEBUG_WITH_TYPE("PrintCFG", + llvm::dbgs() + << "======CFGStmt and ASTStmt========\n"); + DEBUG_WITH_TYPE("PrintCFG", CS->dump()); + DEBUG_WITH_TYPE("PrintCFG", CS->getStmt()->dumpColor()); Visit(CS->getStmt()); - else if (std::optional<CFGAutomaticObjDtor> DtorOpt = - Element.getAs<CFGAutomaticObjDtor>()) + } else if (std::optional<CFGAutomaticObjDtor> DtorOpt = + Element.getAs<CFGAutomaticObjDtor>()) handleDestructor(*DtorOpt); } FactMgr.addBlockFacts(Block, CurrentBlockFacts); } } + void Visit(const Stmt *S) { + if(!S || VisitedStmts.insert(S).second) + return; + Base::Visit(S); + } + void VisitDeclStmt(const DeclStmt *DS) { for (const Decl *D : DS->decls()) if (const auto *VD = dyn_cast<VarDecl>(D)) @@ -551,6 +563,7 @@ class FactGenerator : public ConstStmtVisitor<FactGenerator> { FactManager &FactMgr; AnalysisDeclContext &AC; llvm::SmallVector<Fact *> CurrentBlockFacts; + llvm::DenseSet<const Stmt *> VisitedStmts; }; // ========================================================================= // _______________________________________________ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits