14#ifndef LLVM_CLANG_ANALYSIS_ANALYSES_LIFETIMESAFETY_LOANS_H
15#define LLVM_CLANG_ANALYSIS_ANALYSES_LIFETIMESAFETY_LOANS_H
19#include "llvm/Support/raw_ostream.h"
25 return OS << ID.Value;
44 enum class Kind : uint8_t {
58 virtual void dump(llvm::raw_ostream &OS)
const = 0;
70 const Expr *IssueExpr;
74 :
Loan(
Kind::Path, ID), Path(Path), IssueExpr(IssueExpr) {}
79 void dump(llvm::raw_ostream &OS)
const override;
107 void dump(llvm::raw_ostream &OS)
const override;
119 template <
typename LoanType,
typename... Args>
122 std::is_same_v<LoanType, PathLoan> ||
123 std::is_same_v<LoanType, PlaceholderLoan>,
124 "createLoan can only be used with PathLoan or PlaceholderLoan");
125 void *Mem = LoanAllocator.Allocate<LoanType>();
127 new (Mem) LoanType(getNextLoanID(), std::forward<Args>(args)...);
128 AllLoans.push_back(NewLoan);
133 assert(ID.Value < AllLoans.size());
134 return AllLoans[ID.Value];
139 LoanID getNextLoanID() {
return NextLoanID++; }
145 llvm::BumpPtrAllocator LoanAllocator;
This represents one expression.
Represents a parameter to a function.
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
llvm::ArrayRef< const Loan * > getLoans() const
const Loan * getLoan(LoanID ID) const
LoanType * createLoan(Args &&...args)
An abstract base class for a single "Loan" which represents lending a storage in memory.
Kind
TODO: Represent opaque loans.
@ Placeholder
A non-expiring placeholder loan for a parameter, representing a borrow from the function's caller.
@ Path
A loan with an access path to a storage location.
virtual void dump(llvm::raw_ostream &OS) const =0
const Expr * getIssueExpr() const
PathLoan(LoanID ID, AccessPath Path, const Expr *IssueExpr)
const AccessPath & getAccessPath() const
static bool classof(const Loan *L)
void dump(llvm::raw_ostream &OS) const override
void dump(llvm::raw_ostream &OS) const override
static bool classof(const Loan *L)
PlaceholderLoan(LoanID ID, const ParmVarDecl *PVD)
const ParmVarDecl * getParmVarDecl() const
utils::ID< struct LoanTag > LoanID
llvm::raw_ostream & operator<<(llvm::raw_ostream &OS, LoanID ID)
Represents the storage location being borrowed, e.g., a specific stack variable.
AccessPath(const clang::ValueDecl *D)
const clang::ValueDecl * D
A generic, type-safe wrapper for an ID, distinguished by its Tag type.