16#ifndef LLVM_CLANG_ANALYSIS_CONSTRUCTIONCONTEXT_H
17#define LLVM_CLANG_ANALYSIS_CONSTRUCTIONCONTEXT_H
51 case VariableKind:
return "construct into local variable";
53 case ReturnKind:
return "construct into return address";
60 return "construct into lambda captured variable";
63 llvm_unreachable(
"Unknown ItemKind");
67 const void *
const Data;
69 const unsigned Index = 0;
71 bool hasStatement()
const {
76 bool hasIndex()
const {
81 bool hasInitializer()
const {
103 bool IsElided =
false)
125 assert(isa<CallExpr>(
E) || isa<CXXConstructExpr>(
E) ||
126 isa<CXXDeleteExpr>(
E) || isa<CXXInheritedCtorInitExpr>(
E) ||
127 isa<ObjCMessageExpr>(
E));
147 assert(hasStatement());
148 return static_cast<const Stmt *
>(
Data);
152 return hasStatement() ?
getStmt() :
nullptr;
159 assert(hasInitializer());
177 ID.AddInteger(Index);
184 return std::make_tuple(
Data, Kind, Index) ==
189 return std::make_tuple(
Data, Kind, Index) <
276 template <
typename T,
typename... ArgTypes>
278 auto *CC =
C.getAllocator().Allocate<
T>();
279 return new (CC)
T(Args...);
285 static const ConstructionContext *createMaterializedTemporaryFromLayers(
286 BumpVectorContext &
C,
const MaterializeTemporaryExpr *MTE,
287 const CXXBindTemporaryExpr *BTE,
288 const ConstructionContextLayer *ParentLayer);
294 static const ConstructionContext *
295 createBoundTemporaryFromLayers(
296 BumpVectorContext &
C,
const CXXBindTemporaryExpr *BTE,
297 const ConstructionContextLayer *ParentLayer);
303 static const ConstructionContext *
305 const ConstructionContextLayer *TopLayer);
332 return dyn_cast<ArrayInitLoopExpr>(Var->getInit());
403 return dyn_cast<ArrayInitLoopExpr>(I->
getInit());
561 ElidedCE(ElidedCE), ElidedCC(ElidedCC) {
565 assert(ElidedCE && ElidedCE->
isElidable() && ElidedCC);
668 Index(Index), BTE(BTE) {
669 assert(isa<CallExpr>(CE) || isa<CXXConstructExpr>(CE) ||
670 isa<ObjCMessageExpr>(CE));
702 return *(LE->capture_init_begin() + Index);
706 auto It = LE->getLambdaClass()->field_begin();
707 std::advance(It, Index);
Defines the clang::Expr interface and subclasses for C++ expressions.
static bool classof(const ConstructionContext *CC)
const Expr * getCallLikeExpr() const
unsigned getIndex() const
const CXXBindTemporaryExpr * getCXXBindTemporaryExpr() const
Represents a loop initializing the elements of an array.
Represents construction into a field or a base class within a bigger object via a constructor initial...
const CXXBindTemporaryExpr * getCXXBindTemporaryExpr() const
static bool classof(const ConstructionContext *CC)
Represents a temporary object that is being immediately returned from a function by value,...
static bool classof(const ConstructionContext *CC)
const CXXBindTemporaryExpr * getCXXBindTemporaryExpr() const
Represents construction into a simple variable with an initializer syntax, with a single constructor,...
static bool classof(const ConstructionContext *CC)
const CXXBindTemporaryExpr * getCXXBindTemporaryExpr() const
Represents binding an expression to a temporary.
Represents a call to a C++ constructor.
bool isElidable() const
Whether this construction is elidable.
Represents a C++ base or member initializer.
Expr * getInit() const
Get the initializer.
Represents a call to an inherited base class constructor from an inheriting constructor.
Represents a new-expression for memory allocation and constructor calls, e.g: "new CXXNewExpr(foo)".
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
Represents a single point (AST node) in the program that requires attention during construction of an...
ConstructionContextItem(const ReturnStmt *RS)
ConstructionContextItem(const CXXInheritedCtorInitExpr *CE, unsigned Index)
ConstructionContextItem(const CallExpr *CE, unsigned Index)
ConstructionContextItem(const CXXCtorInitializer *Init)
ConstructionContextItem(const LambdaExpr *LE, unsigned Index)
unsigned getIndex() const
If a single trigger statement triggers multiple constructors, they are usually being enumerated.
bool operator==(const ConstructionContextItem &Other) const
bool operator<(const ConstructionContextItem &Other) const
const CXXCtorInitializer * getCXXCtorInitializer() const
The construction site is not necessarily a statement.
void Profile(llvm::FoldingSetNodeID &ID) const
ConstructionContextItem(const MaterializeTemporaryExpr *MTE)
ConstructionContextItem(const CXXConstructExpr *CE, unsigned Index)
ConstructionContextItem(const ObjCMessageExpr *ME, unsigned Index)
ConstructionContextItem(const CXXConstructExpr *CE)
ConstructionContextItem(const DeclStmt *DS)
ConstructionContextItem(const CXXNewExpr *NE)
@ STATEMENT_WITH_INDEX_KIND_END
@ STATEMENT_WITH_INDEX_KIND_BEGIN
@ TemporaryDestructorKind
@ ElidableConstructorKind
LLVM_DUMP_METHOD StringRef getKindAsString() const
const Stmt * getStmtOrNull() const
static LLVM_DUMP_METHOD StringRef getKindAsString(ItemKind K)
ConstructionContextItem(const Expr *E, unsigned Index)
ConstructionContextItem(const CXXBindTemporaryExpr *BTE, bool IsElided=false)
const Stmt * getStmt() const
The construction site - the statement that triggered the construction for one of its parts.
Construction context can be seen as a linked list of multiple layers.
static const ConstructionContextLayer * create(BumpVectorContext &C, const ConstructionContextItem &Item, const ConstructionContextLayer *Parent=nullptr)
const ConstructionContextItem & getItem() const
const ConstructionContextLayer * getParent() const
bool isStrictlyMoreSpecificThan(const ConstructionContextLayer *Other) const
See if Other is a proper initial segment of this construction context in terms of the parent chain - ...
ConstructionContext's subclasses describe different ways of constructing an object in C++.
virtual const ArrayInitLoopExpr * getArrayInitLoop() const
virtual ~ConstructionContext()=default
static const ConstructionContext * createFromLayers(BumpVectorContext &C, const ConstructionContextLayer *TopLayer)
Consume the construction context layer, together with its parent layers, and wrap it up into a comple...
ConstructionContext(Kind K)
@ CXX17ElidedCopyVariableKind
@ ElidedTemporaryObjectKind
@ SimpleTemporaryObjectKind
@ CXX17ElidedCopyConstructorInitializerKind
@ SimpleConstructorInitializerKind
@ SimpleReturnedValueKind
@ CXX17ElidedCopyReturnedValueKind
const CXXCtorInitializer * getCXXCtorInitializer() const
ConstructorInitializerConstructionContext(ConstructionContext::Kind K, const CXXCtorInitializer *I)
const ArrayInitLoopExpr * getArrayInitLoop() const override
static bool classof(const ConstructionContext *CC)
DeclStmt - Adaptor class for mixing declarations with statements and expressions.
const Decl * getSingleDecl() const
Represents a temporary object that is constructed for the sole purpose of being immediately copied by...
static bool classof(const ConstructionContext *CC)
const ConstructionContext * getConstructionContextAfterElision() const
const CXXConstructExpr * getConstructorAfterElision() const
This represents one expression.
Represents a member of a struct/union/class.
const Expr * getInitializer() const
const LambdaExpr * getLambdaExpr() const
unsigned getIndex() const
const ArrayInitLoopExpr * getArrayInitLoop() const override
const FieldDecl * getFieldDecl() const
static bool classof(const ConstructionContext *CC)
A C++ lambda expression, which produces a function object (of unspecified type) that can be invoked l...
Represents a prvalue temporary that is written into memory so that a reference can bind to it.
Represents immediate initialization of memory allocated by operator new, eg.
const CXXNewExpr * getCXXNewExpr() const
static bool classof(const ConstructionContext *CC)
An expression that sends a message to the given Objective-C object or class.
ReturnStmt - This represents a return, optionally of an expression: return; return 4;.
ReturnedValueConstructionContext(ConstructionContext::Kind K, const ReturnStmt *RS)
static bool classof(const ConstructionContext *CC)
const ReturnStmt * getReturnStmt() const
Represents construction into a field or a base class within a bigger object via a constructor initial...
static bool classof(const ConstructionContext *CC)
Represents a temporary object that is being immediately returned from a function by value,...
static bool classof(const ConstructionContext *CC)
Represents a temporary object that is not constructed for the purpose of being immediately copied/mov...
static bool classof(const ConstructionContext *CC)
Represents construction into a simple local variable, eg.
static bool classof(const ConstructionContext *CC)
Stmt - This represents one statement.
Represents a temporary object, eg.
const CXXBindTemporaryExpr * getCXXBindTemporaryExpr() const
CXXBindTemporaryExpr here is non-null as long as the temporary has a non-trivial destructor.
const MaterializeTemporaryExpr * getMaterializedTemporaryExpr() const
MaterializeTemporaryExpr is non-null as long as the temporary is actually used after construction,...
static bool classof(const ConstructionContext *CC)
TemporaryObjectConstructionContext(ConstructionContext::Kind K, const CXXBindTemporaryExpr *BTE, const MaterializeTemporaryExpr *MTE)
An abstract base class for local variable constructors.
static bool classof(const ConstructionContext *CC)
const ArrayInitLoopExpr * getArrayInitLoop() const override
VariableConstructionContext(ConstructionContext::Kind K, const DeclStmt *DS)
const DeclStmt * getDeclStmt() const
The JSON file list parser is used to communicate input to InstallAPI.
LambdaCaptureKind
The different capture forms in a lambda introducer.
const FunctionProtoType * T
@ Other
Other implicit parameter.