================
@@ -34,46 +34,98 @@ struct AccessPath {
AccessPath(const clang::ValueDecl *D) : D(D) {}
};
-/// Information about a single borrow, or "Loan". A loan is created when a
-/// reference or pointer is created.
-struct Loan {
+/// An abstract base class for a single borrow, or "Loan".
+class Loan {
/// TODO: Represent opaque loans.
/// TODO: Represent nullptr: loans to no path. Accessing it UB! Currently it
/// is represented as empty LoanSet
- LoanID ID;
+public:
+ enum class Kind : uint8_t {
+ /// A regular borrow of a variable within the function that has a path and
+ /// can expire.
+ Borrow,
+ /// A non-expiring placeholder loan for a parameter, representing a borrow
+ /// from the function's caller.
+ Placeholder
+ };
+
+ Loan(Kind K, LoanID ID) : K(K), ID(ID) {}
+ virtual ~Loan() = default;
+
+ Kind getKind() const { return K; }
+ LoanID getID() const { return ID; }
+
+ virtual void dump(llvm::raw_ostream &OS) const = 0;
+
+private:
+ const Kind K;
+ const LoanID ID;
+};
+
+/// Information about a single borrow, or "Loan". A loan is created when a
+/// reference or pointer is created.
+class BorrowLoan : public Loan {
AccessPath Path;
- /// The expression that creates the loan, e.g., &x.
const Expr *IssueExpr;
- Loan(LoanID id, AccessPath path, const Expr *IssueExpr)
- : ID(id), Path(path), IssueExpr(IssueExpr) {}
+public:
+ BorrowLoan(LoanID ID, AccessPath Path, const Expr *IssueExpr)
+ : Loan(Kind::Borrow, ID), Path(Path), IssueExpr(IssueExpr) {}
+
+ const AccessPath &getAccessPath() const { return Path; }
+ const Expr *getIssueExpr() const { return IssueExpr; }
+
+ void dump(llvm::raw_ostream &OS) const override;
+
+ static bool classof(const Loan *L) { return L->getKind() == Kind::Borrow; }
+};
+
+/// A concrete loan type for placeholder loans on parameters, representing a
+/// borrow from the function's caller.
+class ParameterLoan : public Loan {
----------------
kashika0112 wrote:
Done
https://github.com/llvm/llvm-project/pull/169767
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits