[clang] [LifetimeSafety] Make the dataflow analysis generic (PR #148222)
Gábor Horváth via cfe-commits
cfe-commits at lists.llvm.org
Tue Jul 15 03:21:30 PDT 2025
================
@@ -596,143 +709,66 @@ struct LifetimeLattice {
}
};
-// ========================================================================= //
-// The Transfer Function
-// ========================================================================= //
-class Transferer {
- FactManager &AllFacts;
+/// The analysis that tracks which loans belong to which origins.
+class LoanPropagationAnalysis
+ : public DataflowAnalysis<LoanPropagationAnalysis, LoanPropagationLattice> {
+
LifetimeFactory &Factory;
public:
- explicit Transferer(FactManager &F, LifetimeFactory &Factory)
- : AllFacts(F), Factory(Factory) {}
+ LoanPropagationAnalysis(const CFG &C, AnalysisDeclContext &AC, FactManager &F,
+ LifetimeFactory &Factory)
+ : DataflowAnalysis(C, AC, F), Factory(Factory) {}
- /// Computes the exit state of a block by applying all its facts sequentially
- /// to a given entry state.
- /// TODO: We might need to store intermediate states per-fact in the block for
- /// later analysis.
- LifetimeLattice transferBlock(const CFGBlock *Block,
- LifetimeLattice EntryState) {
- LifetimeLattice BlockState = EntryState;
- llvm::ArrayRef<const Fact *> Facts = AllFacts.getFacts(Block);
+ using DataflowAnalysis<LoanPropagationAnalysis, Lattice>::transfer;
- for (const Fact *F : Facts) {
- BlockState = transferFact(BlockState, F);
- }
- return BlockState;
- }
+ const char *getAnalysisName() const { return "LoanPropagation"; }
----------------
Xazax-hun wrote:
I'd prefer these to return a StringRef.
https://github.com/llvm/llvm-project/pull/148222
More information about the cfe-commits
mailing list