Skip to content

Commit 4742560

Browse files
committed
make the dataflow algorithm generic to avoid duplication
1 parent eb33d75 commit 4742560

File tree

1 file changed

+7
-15
lines changed

1 file changed

+7
-15
lines changed

clang/lib/Analysis/LifetimeSafety.cpp

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,7 @@ class LifetimeDataflow {
737737
struct ExpiredLattice {
738738
LoanSet Expired;
739739

740-
ExpiredLattice() = default;
740+
ExpiredLattice() : Expired(nullptr) {};
741741
explicit ExpiredLattice(LoanSet S) : Expired(S) {}
742742

743743
bool operator==(const ExpiredLattice &Other) const {
@@ -814,10 +814,10 @@ class ExpiredLoansAnalysis {
814814
: Cfg(C), AC(AC), Xfer(FS, SetFactory) {}
815815

816816
void run() {
817-
llvm::TimeTraceScope TimeProfile("Expired Loans Analysis");
817+
llvm::TimeTraceScope TimeProfile("ExpiredLoansAnalysis");
818818
ForwardDataflowWorklist Worklist(Cfg, AC);
819819
const CFGBlock *Entry = &Cfg.getEntry();
820-
BlockEntryStates[Entry] = ExpiredLattice(SetFactory.getEmptySet());
820+
BlockEntryStates[Entry] = ExpiredLattice{};
821821
Worklist.enqueueBlock(Entry);
822822
while (const CFGBlock *B = Worklist.dequeue()) {
823823
ExpiredLattice EntryState = getEntryState(B);
@@ -849,24 +849,16 @@ class ExpiredLoansAnalysis {
849849
}
850850

851851
ExpiredLattice getEntryState(const CFGBlock *B) const {
852-
auto It = BlockEntryStates.find(B);
853-
if (It != BlockEntryStates.end()) {
854-
return It->second;
855-
}
856-
return ExpiredLattice(SetFactory.getEmptySet());
852+
return BlockEntryStates.lookup(B);
857853
}
858854

859855
ExpiredLattice getExitState(const CFGBlock *B) const {
860-
auto It = BlockExitStates.find(B);
861-
if (It != BlockExitStates.end()) {
862-
return It->second;
863-
}
864-
return ExpiredLattice(SetFactory.getEmptySet());
856+
return BlockExitStates.lookup(B);
865857
}
866858
};
867859

868860
// ========================================================================= //
869-
// TODO: Analysing dataflow results and error reporting.
861+
// TODO: Liveness analysis, analysing dataflow results and error reporting.
870862
// ========================================================================= //
871863
} // anonymous namespace
872864

@@ -895,6 +887,6 @@ void runLifetimeSafetyAnalysis(const DeclContext &DC, const CFG &Cfg,
895887

896888
ExpiredLoansAnalysis ExpiredAnalysis(Cfg, FactMgr, AC);
897889
ExpiredAnalysis.run();
898-
DEBUG_WITH_TYPE("ExpiredLoans", ExpiredAnalysis.dump());
890+
DEBUG_WITH_TYPE("LifetimeExpiredLoans", ExpiredAnalysis.dump());
899891
}
900892
} // namespace clang

0 commit comments

Comments
 (0)