[clang] [LifetimeSafety] Refactor FactGenerator to use RecursiveASTVisitor (PR #153661)
Gábor Horváth via cfe-commits
cfe-commits at lists.llvm.org
Tue Sep 2 06:58:15 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();
----------------
Xazax-hun wrote:
Do we need to clear both at start and end?
https://github.com/llvm/llvm-project/pull/153661
More information about the cfe-commits
mailing list