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;
64 enum class Kind : uint8_t {
78 virtual void dump(llvm::raw_ostream &OS)
const = 0;
90 const Expr *IssueExpr;
94 :
Loan(
Kind::Path, ID), Path(Path), IssueExpr(IssueExpr) {}
99 void dump(llvm::raw_ostream &OS)
const override;
121 llvm::PointerUnion<const ParmVarDecl *, const CXXMethodDecl *> ParamOrMethod;
131 return ParamOrMethod.dyn_cast<
const ParmVarDecl *>();
138 void dump(llvm::raw_ostream &OS)
const override;
150 template <
typename LoanType,
typename... Args>
153 std::is_same_v<LoanType, PathLoan> ||
154 std::is_same_v<LoanType, PlaceholderLoan>,
155 "createLoan can only be used with PathLoan or PlaceholderLoan");
156 void *Mem = LoanAllocator.Allocate<LoanType>();
158 new (Mem) LoanType(getNextLoanID(), std::forward<Args>(args)...);
159 AllLoans.push_back(NewLoan);
164 assert(ID.Value < AllLoans.size());
165 return AllLoans[ID.Value];
170 LoanID getNextLoanID() {
return NextLoanID++; }
176 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 ...
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)
Represents the storage location being borrowed, e.g., a specific stack variable.
AccessPath(const clang::ValueDecl *D)
const clang::ValueDecl * getAsValueDecl() const
AccessPath(const clang::MaterializeTemporaryExpr *MTE)
const clang::MaterializeTemporaryExpr * getAsMaterializeTemporaryExpr() const
A generic, type-safe wrapper for an ID, distinguished by its Tag type.