14#ifndef LLVM_CLANG_ANALYSIS_ANALYSES_LIFETIMESAFETY_LOANS_H
15#define LLVM_CLANG_ANALYSIS_ANALYSES_LIFETIMESAFETY_LOANS_H
21#include "llvm/Support/raw_ostream.h"
27 return OS << ID.Value;
65 enum class Kind : uint8_t {
79 virtual void dump(llvm::raw_ostream &OS)
const = 0;
91 const Expr *IssueExpr;
95 :
Loan(
Kind::Path, ID), Path(Path), IssueExpr(IssueExpr) {}
100 void dump(llvm::raw_ostream &OS)
const override;
122 llvm::PointerUnion<const ParmVarDecl *, const CXXMethodDecl *> ParamOrMethod;
132 return ParamOrMethod.dyn_cast<
const ParmVarDecl *>();
139 void dump(llvm::raw_ostream &OS)
const override;
151 template <
typename LoanType,
typename... Args>
154 std::is_same_v<LoanType, PathLoan> ||
155 std::is_same_v<LoanType, PlaceholderLoan>,
156 "createLoan can only be used with PathLoan or PlaceholderLoan");
157 void *Mem = LoanAllocator.Allocate<LoanType>();
159 new (Mem) LoanType(getNextLoanID(), std::forward<Args>(args)...);
160 AllLoans.push_back(NewLoan);
165 assert(ID.Value < AllLoans.size());
166 return AllLoans[ID.Value];
171 LoanID getNextLoanID() {
return NextLoanID++; }
177 llvm::BumpPtrAllocator LoanAllocator;
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
Defines the clang::Expr interface and subclasses for C++ expressions.
Represents a static or instance method of a struct/union/class.
This represents one expression.
Represents a prvalue temporary that is written into memory so that a reference can bind to it.
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 ...
Represents the storage location being borrowed, e.g., a specific stack variable.
AccessPath(const clang::ValueDecl *D)
const clang::ValueDecl * getAsValueDecl() const
bool operator==(const AccessPath &RHS) const
AccessPath(const clang::MaterializeTemporaryExpr *MTE)
const clang::MaterializeTemporaryExpr * getAsMaterializeTemporaryExpr() const
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
PlaceholderLoan(LoanID ID, const CXXMethodDecl *MD)
void dump(llvm::raw_ostream &OS) const override
static bool classof(const Loan *L)
PlaceholderLoan(LoanID ID, const ParmVarDecl *PVD)
const CXXMethodDecl * getMethodDecl() const
const ParmVarDecl * getParmVarDecl() const
utils::ID< struct LoanTag > LoanID
llvm::raw_ostream & operator<<(llvm::raw_ostream &OS, LoanID ID)
A generic, type-safe wrapper for an ID, distinguished by its Tag type.