================
@@ -0,0 +1,121 @@
+
+#include "clang/Analysis/Analyses/LifetimeSafety/MovedLoans.h"
+#include "Dataflow.h"
+#include "clang/Analysis/Analyses/LifetimeSafety/Facts.h"
+#include "clang/Analysis/Analyses/LifetimeSafety/LoanPropagation.h"
+#include "clang/Analysis/Analyses/LifetimeSafety/Loans.h"
+#include "clang/Analysis/Analyses/LifetimeSafety/Utils.h"
+
+namespace clang::lifetimes::internal {
+namespace {
+struct Lattice {
+ LoanSet ReachableLoans = LoanSet(nullptr);
+ MovedLoansMap MovedLoans = MovedLoansMap(nullptr);
+
+ explicit Lattice(LoanSet ReachableLoans, MovedLoansMap MovedLoans)
+ : ReachableLoans(ReachableLoans), MovedLoans(MovedLoans) {}
+
+ Lattice() = default;
+
+ bool operator==(const Lattice &Other) const {
+ return ReachableLoans == Other.ReachableLoans &&
+ MovedLoans == Other.MovedLoans;
+ }
+ bool operator!=(const Lattice &Other) const { return !(*this == Other); }
+};
+
+class AnalysisImpl
+ : public DataflowAnalysis<AnalysisImpl, Lattice, Direction::Forward> {
+public:
+ AnalysisImpl(const CFG &C, AnalysisDeclContext &AC, FactManager &F,
+ const LoanPropagationAnalysis &LoanPropagation,
+ const LoanManager &LoanMgr, LoanSet::Factory &LoanSetFactory,
+ MovedLoansMap::Factory &MovedLoansMapFactory)
+ : DataflowAnalysis(C, AC, F), LoanPropagation(LoanPropagation),
+ LoanMgr(LoanMgr), LoanSetFactory(LoanSetFactory),
+ MovedLoansMapFactory(MovedLoansMapFactory) {}
+
+ using Base::transfer;
+
+ StringRef getAnalysisName() const { return "MovedLoans"; }
+
+ Lattice getInitialState() { return Lattice{}; }
+
+ // TODO: Doc.
+ Lattice join(Lattice A, Lattice B) {
+ LoanSet ReachableLoans =
+ utils::join(A.ReachableLoans, B.ReachableLoans, LoanSetFactory);
+ MovedLoansMap MovedLoans = utils::join(
+ A.MovedLoans, B.MovedLoans, MovedLoansMapFactory,
+ [](const Expr *const *MoveA, const Expr *const *MoveB) -> const Expr *
{
+ assert(MoveA || MoveB);
+ if (!MoveA)
+ return *MoveB;
+ if (!MoveB)
+ return *MoveA;
+ return (*MoveA)->getExprLoc() < (*MoveB)->getExprLoc() ? *MoveA
+ : *MoveB;
+ },
+ utils::JoinKind::Asymmetric);
+ return Lattice(ReachableLoans, MovedLoans);
+ }
+
+ Lattice transfer(Lattice In, const IssueFact &F) {
+ LoanSet ReachableLoans =
+ LoanSetFactory.add(In.ReachableLoans, F.getLoanID());
+ return Lattice(ReachableLoans, In.MovedLoans);
+ }
----------------
usx95 wrote:
I am slightly worried about ReachableLoans. This is going to be expensive as at
the end of function, this set would contain all the loans in this set. At merge
points, all loans from both branches merge into.
A better approach would be to compute this lazily when we process a
`MovedOriginFact`!
https://github.com/llvm/llvm-project/pull/178670
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits