14#ifndef LLVM_CLANG_ANALYSIS_ANALYSES_LIFETIMESAFETY_LOANS_H
15#define LLVM_CLANG_ANALYSIS_ANALYSES_LIFETIMESAFETY_LOANS_H
21#include "llvm/ADT/FoldingSet.h"
22#include "llvm/ADT/SmallVector.h"
23#include "llvm/Support/raw_ostream.h"
29 return OS << ID.Value;
60 void dump(llvm::raw_ostream &OS)
const {
62 OS <<
"." << FD->getNameAsString();
78 llvm::PointerUnion<const ParmVarDecl *, const CXXMethodDecl *> ParamOrMethod;
85 return ParamOrMethod.dyn_cast<
const ParmVarDecl *>();
92 void Profile(llvm::FoldingSetNodeID &ID)
const {
93 ID.AddPointer(ParamOrMethod.getOpaqueValue());
132 : Base(
Other.Base), Elements(
Other.Elements) {
133 Elements.push_back(E);
153 return Base == RHS.Base && Elements == RHS.Elements;
163 if (Base !=
Other.Base || Elements.size() >
Other.Elements.size())
165 return std::equal(Elements.begin(), Elements.end(),
Other.Elements.begin());
176 void dump(llvm::raw_ostream &OS)
const;
196 const Expr *IssueExpr;
200 : ID(ID), Path(Path), IssueExpr(IssueExpr) {}
206 void dump(llvm::raw_ostream &OS)
const;
216 void *Mem = LoanAllocator.Allocate<
Loan>();
217 auto *NewLoan =
new (Mem)
Loan(getNextLoanID(), Path, IssueExpr);
218 AllLoans.push_back(NewLoan);
230 assert(ID.Value < AllLoans.size());
231 return AllLoans[ID.Value];
237 LoanID getNextLoanID() {
return NextLoanID++; }
240 const PlaceholderBase *getOrCreatePlaceholderBase(
const ParmVarDecl *PVD);
241 const PlaceholderBase *getOrCreatePlaceholderBase(
const CXXMethodDecl *MD);
245 llvm::FoldingSet<PlaceholderBase> PlaceholderBases;
250 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.
Represents a new-expression for memory allocation and constructor calls, e.g: "new CXXNewExpr(foo)".
This represents one expression.
Represents a member of a struct/union/class.
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 or a field within it:...
bool isStrictPrefixOf(const AccessPath &Other) const
Returns true if this path is a strict prefix of Other.
const clang::CXXNewExpr * getAsNewAllocation() const
bool isPrefixOf(const AccessPath &Other) const
Returns true if this path is a prefix of Other (or same as Other).
bool operator!=(const AccessPath &RHS) const
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< PathElement > getElements() const
const PlaceholderBase * getAsPlaceholderBase() const
void dump(llvm::raw_ostream &OS) const
AccessPath(const PlaceholderBase *PB)
AccessPath(const AccessPath &Other, PathElement E)
Creates an extended access path by appending a path element.
AccessPath(const clang::CXXNewExpr *New)
Loan * createPlaceholderLoan(const ParmVarDecl *PVD)
llvm::ArrayRef< const Loan * > getLoans() const
const Loan * getLoan(LoanID ID) const
Loan * createLoan(AccessPath Path, const Expr *IssueExpr=nullptr)
Loan * createPlaceholderLoan(const CXXMethodDecl *MD)
Represents a component of an access path: either a named field access or an abstract unnamed interior...
const Expr * getIssueExpr() const
Loan(LoanID ID, AccessPath Path, const Expr *IssueExpr=nullptr)
const AccessPath & getAccessPath() const
void dump(llvm::raw_ostream &OS) const
Represents one step in an access path: either a field access or an access to an unnamed interior regi...
static PathElement getInterior()
const FieldDecl * getFieldDecl() const
void dump(llvm::raw_ostream &OS) const
bool operator==(const PathElement &Other) const
bool operator!=(const PathElement &Other) const
static PathElement getField(const FieldDecl &FD)
Represents the base of a placeholder access path, which is either a function parameter or the implici...
PlaceholderBase(const ParmVarDecl *PVD)
PlaceholderBase(const CXXMethodDecl *MD)
const ParmVarDecl * getParmVarDecl() const
const CXXMethodDecl * getImplicitThisParent() const
void Profile(llvm::FoldingSetNodeID &ID) const
utils::ID< struct LoanTag > LoanID
llvm::raw_ostream & operator<<(llvm::raw_ostream &OS, LoanID ID)
@ Other
Other implicit parameter.
A generic, type-safe wrapper for an ID, distinguished by its Tag type.