[clang] [LifetimeSafety] Refactor FactGenerator to use RecursiveASTVisitor (PR #153661)

Utkarsh Saxena via cfe-commits cfe-commits at lists.llvm.org
Tue Sep 2 07:24:25 PDT 2025


================
@@ -403,29 +404,17 @@ class FactManager {
   llvm::BumpPtrAllocator FactAllocator;
 };
 
-class FactGenerator : public ConstStmtVisitor<FactGenerator> {
-  using Base = ConstStmtVisitor<FactGenerator>;
+class FactGeneratorVisitor : public ConstStmtVisitor<FactGeneratorVisitor> {
+  using Base = ConstStmtVisitor<FactGeneratorVisitor>;
 
 public:
-  FactGenerator(FactManager &FactMgr, AnalysisDeclContext &AC)
-      : FactMgr(FactMgr), AC(AC) {}
+  FactGeneratorVisitor(FactManager &FactMgr) : FactMgr(FactMgr) {}
 
-  void run() {
-    llvm::TimeTraceScope TimeProfile("FactGenerator");
-    // Iterate through the CFG blocks in reverse post-order to ensure that
-    // initializations and destructions are processed in the correct sequence.
-    for (const CFGBlock *Block : *AC.getAnalysis<PostOrderCFGView>()) {
-      CurrentBlockFacts.clear();
-      for (unsigned I = 0; I < Block->size(); ++I) {
-        const CFGElement &Element = Block->Elements[I];
-        if (std::optional<CFGStmt> CS = Element.getAs<CFGStmt>())
-          Visit(CS->getStmt());
-        else if (std::optional<CFGAutomaticObjDtor> DtorOpt =
-                     Element.getAs<CFGAutomaticObjDtor>())
-          handleDestructor(*DtorOpt);
-      }
-      FactMgr.addBlockFacts(Block, CurrentBlockFacts);
-    }
+  void startBlock() { CurrentBlockFacts.clear(); }
+
+  void endBlock(const CFGBlock *CurrentBlock) {
+    FactMgr.addBlockFacts(CurrentBlock, CurrentBlockFacts);
+    CurrentBlockFacts.clear();
----------------
usx95 wrote:

Removed the clear from the start as it is always a noop.

https://github.com/llvm/llvm-project/pull/153661


More information about the cfe-commits mailing list