16 #ifndef LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_CALLEVENT_H
17 #define LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_CALLEVENT_H
26 #include "llvm/ADT/PointerIntPair.h"
31 class ProgramPointTag;
58 mutable bool IsLookupDone;
60 unsigned RequiredArgs;
72 : II(nullptr), IsLookupDone(
false), FuncName(FuncName),
73 RequiredArgs(RequiredArgs) {}
79 template<
typename T = CallEvent>
86 return this->
get()->
template cloneWithState<T>(State);
91 template <
typename SuperT>
147 llvm::PointerUnion<const Expr *, const Decl *> Origin;
149 void operator=(
const CallEvent &) =
delete;
161 mutable unsigned RefCount;
164 void Retain()
const { ++RefCount; }
165 void Release()
const;
171 :
State(std::move(state)), LCtx(lctx), Origin(E), RefCount(0) {}
174 :
State(std::move(state)), LCtx(lctx), Origin(D), RefCount(0) {}
178 :
State(Original.
State), LCtx(Original.LCtx), Origin(Original.Origin),
182 virtual void cloneTo(
void *Dest)
const = 0;
206 return Origin.dyn_cast<
const Decl *>();
226 return Origin.dyn_cast<
const Expr *>();
245 getState()->getStateManager().getContext().getSourceManager();
252 return FD->isOverloadedOperator() && FD->isImplicit() && FD->isGlobal();
362 template <
typename T>
367 return cloneWithState<CallEvent>(NewState);
396 virtual ArrayRef<ParmVarDecl*>
parameters()
const = 0;
398 typedef llvm::mapped_iterator<ArrayRef<ParmVarDecl*>::iterator, GetTypeFn>
407 return llvm::map_iterator(
parameters().begin(), GetTypeFn());
411 return llvm::map_iterator(
parameters().end(), GetTypeFn());
415 void dump(raw_ostream &Out)
const;
446 getManager()->getContext(FD);
517 void getExtraInvalidatedValues(
ValueList &Values,
518 RegionAndSymbolInvalidationTraits *ETraits)
const override;
525 unsigned getNumArgs()
const override {
return getOriginExpr()->getNumArgs(); }
528 return getOriginExpr()->getArg(Index);
534 const BlockDataRegion *getBlockRegion()
const;
537 const BlockDataRegion *BR = getBlockRegion();
540 return BR->getDecl();
554 assert(isConversionFromLambda());
555 const BlockDataRegion *BR = getBlockRegion();
556 assert(BR &&
"Block converted from lambda must have a block region");
558 auto I = BR->referenced_vars_begin();
559 assert(
I != BR->referenced_vars_end());
561 return I.getCapturedRegion();
565 if (!isConversionFromLambda())
566 return RuntimeDefinition(getDecl());
587 const VarDecl *LambdaVD = getRegionStoringCapturedLambda()->getDecl();
591 return RuntimeDefinition(LambdaCallOperator);
599 BindingsTy &Bindings)
const override;
614 void getExtraInvalidatedValues(
ValueList &Values,
615 RegionAndSymbolInvalidationTraits *ETraits)
const override;
632 virtual SVal getCXXThisVal()
const;
636 RuntimeDefinition getRuntimeDefinition()
const override;
639 BindingsTy &Bindings)
const override;
663 return cast<CXXMemberCallExpr>(CXXInstanceCall::getOriginExpr());
667 if (
const CallExpr *CE = getOriginExpr())
668 return CE->getNumArgs();
673 return getOriginExpr()->getArg(Index);
676 const Expr *getCXXThisExpr()
const override;
678 RuntimeDefinition getRuntimeDefinition()
const override;
707 return cast<CXXOperatorCallExpr>(CXXInstanceCall::getOriginExpr());
711 return getOriginExpr()->getNumArgs() - 1;
714 return getOriginExpr()->getArg(Index + 1);
717 const Expr *getCXXThisExpr()
const override;
734 typedef llvm::PointerIntPair<const MemRegion *, 1, bool>
DtorDataTy;
744 const MemRegion *Target,
bool IsBaseDestructor,
747 Data =
DtorDataTy(Target, IsBaseDestructor).getOpaqueValue();
758 RuntimeDefinition getRuntimeDefinition()
const override;
761 SVal getCXXThisVal()
const override;
765 return DtorDataTy::getFromOpaqueValue(Data).getInt();
798 void getExtraInvalidatedValues(
ValueList &Values,
799 RegionAndSymbolInvalidationTraits *ETraits)
const override;
807 return getOriginExpr()->getConstructor();
810 unsigned getNumArgs()
const override {
return getOriginExpr()->getNumArgs(); }
813 return getOriginExpr()->getArg(Index);
817 SVal getCXXThisVal()
const;
820 BindingsTy &Bindings)
const override;
849 return getOriginExpr()->getOperatorNew();
853 return getOriginExpr()->getNumPlacementArgs() + 1;
860 return getOriginExpr()->getPlacementArg(Index - 1);
898 void getExtraInvalidatedValues(
ValueList &Values,
899 RegionAndSymbolInvalidationTraits *ETraits)
const override;
910 return getOriginExpr()->getMethodDecl();
913 return getOriginExpr()->getNumArgs();
916 return getOriginExpr()->getArg(Index);
920 return getOriginExpr()->isInstanceMessage();
923 return getOriginExpr()->getMethodFamily();
926 return getOriginExpr()->getSelector();
932 SVal getReceiverSVal()
const;
935 SVal getSelfSVal()
const;
942 return getOriginExpr()->getReceiverInterface();
946 bool isReceiverSelfOrSuper()
const;
955 switch (getMessageKind()) {
957 llvm_unreachable(
"This is not a pseudo-object access!");
959 return getNumArgs() > 0;
961 return getNumArgs() > 1;
963 llvm_unreachable(
"Unknown message kind");
971 RuntimeDefinition getRuntimeDefinition()
const override;
973 bool argumentsMayEscape()
const override;
976 BindingsTy &Bindings)
const override;
998 llvm::BumpPtrAllocator &Alloc;
1000 typedef SimpleFunctionCall CallEventTemplateTy;
1002 void reclaim(
const void *Memory) {
1003 Cache.push_back(const_cast<void *>(Memory));
1009 return Alloc.Allocate<CallEventTemplateTy>();
1011 return Cache.pop_back_val();
1014 template <
typename T,
typename Arg>
1016 static_assert(
sizeof(T) ==
sizeof(CallEventTemplateTy),
1017 "CallEvent subclasses are not all the same size");
1018 return new (allocate()) T(A, St, LCtx);
1021 template <
typename T,
typename Arg1,
typename Arg2>
1023 static_assert(
sizeof(T) ==
sizeof(CallEventTemplateTy),
1024 "CallEvent subclasses are not all the same size");
1025 return new (allocate()) T(A1, A2, St, LCtx);
1028 template <
typename T,
typename Arg1,
typename Arg2,
typename Arg3>
1030 const LocationContext *LCtx) {
1031 static_assert(
sizeof(T) ==
sizeof(CallEventTemplateTy),
1032 "CallEvent subclasses are not all the same size");
1033 return new (allocate()) T(A1, A2, A3, St, LCtx);
1036 template <
typename T,
typename Arg1,
typename Arg2,
typename Arg3,
1039 const LocationContext *LCtx) {
1040 static_assert(
sizeof(T) ==
sizeof(CallEventTemplateTy),
1041 "CallEvent subclasses are not all the same size");
1042 return new (allocate()) T(A1, A2, A3, A4, St, LCtx);
1057 CallEventRef<ObjCMethodCall>
1060 return create<ObjCMethodCall>(
E,
State, LCtx);
1063 CallEventRef<CXXConstructorCall>
1066 return create<CXXConstructorCall>(
E, Target,
State, LCtx);
1069 CallEventRef<CXXDestructorCall>
1071 const MemRegion *Target,
bool IsBase,
1073 return create<CXXDestructorCall>(DD, Trigger, Target, IsBase,
State, LCtx);
1076 CallEventRef<CXXAllocatorCall>
1079 return create<CXXAllocatorCall>(
E,
State, LCtx);
1084 template <
typename T>
1086 assert(isa<T>(*
this) &&
"Cloning to unrelated type");
1087 static_assert(
sizeof(T) ==
sizeof(
CallEvent),
1088 "Subclasses may not add fields");
1090 if (NewState ==
State)
1091 return cast<T>(
this);
1094 T *Copy =
static_cast<T *
>(Mgr.allocate());
1096 assert(Copy->getKind() == this->
getKind() &&
"Bad copy");
1098 Copy->State = NewState;
1102 inline void CallEvent::Release()
const {
1103 assert(RefCount > 0 &&
"Reference count is already zero.");
1120 template<
class T>
struct simplify_type< clang::ento::CallEventRef<T> > {
virtual SVal getArgSVal(unsigned Index) const
Returns the value of a given argument at the time of the call.
A call to an overloaded operator written using operator syntax.
CallEvent(const CallEvent &Original)
Kind getKind() const override
FunctionDecl - An instance of this class is created to represent a function declaration or definition...
RuntimeDefinition(const Decl *InD, const MemRegion *InR)
Smart pointer class that efficiently represents Objective-C method names.
A (possibly-)qualified type.
MemRegion - The root abstract class for all memory regions.
bool argumentsMayEscape() const override
Returns true if any of the arguments are known to escape to long- term storage, even if this method w...
bool isInSystemHeader() const
Returns true if the callee is known to be from a system header.
Expr * getArg(unsigned Arg)
getArg - Return the specified argument.
const CXXConstructorDecl * getDecl() const override
bool isInstanceMessage() const
IdentifierInfo * getIdentifier() const
getIdentifier - Get the identifier that names this declaration, if there is one.
CXXInstanceCall(const FunctionDecl *D, ProgramStateRef St, const LocationContext *LCtx)
static SimpleType getSimplifiedValue(clang::ento::CallEventRef< T > Val)
bool hasVoidPointerToNonConstArg() const
Returns true if any of the arguments is void*.
void cloneTo(void *Dest) const override
Stmt - This represents one statement.
Information about invalidation for a particular region/symbol.
SimpleFunctionCall(const CallExpr *CE, ProgramStateRef St, const LocationContext *LCtx)
AnyFunctionCall(const Decl *D, ProgramStateRef St, const LocationContext *LCtx)
static bool classof(const CallEvent *CA)
virtual bool argumentsMayEscape() const
Returns true if any of the arguments are known to escape to long- term storage, even if this method w...
Defines the SourceManager interface.
const ProgramStateRef & getState() const
The state in which the call is being evaluated.
void cloneTo(void *Dest) const override
Decl - This represents one declaration (or definition), e.g.
CallEventRef cloneWithState(ProgramStateRef NewState) const
Returns a copy of this CallEvent, but using the given state.
virtual const CXXNewExpr * getOriginExpr() const
CXXMemberOperatorCall(const CXXOperatorCallExpr *CE, ProgramStateRef St, const LocationContext *LCtx)
Manages the lifetime of CallEvent objects.
IntrusiveRefCntPtr< const ProgramState > ProgramStateRef
static bool classof(const CallEvent *CA)
TypePropertyCache< Private > Cache
ObjCMethodCall(const ObjCMessageExpr *Msg, ProgramStateRef St, const LocationContext *LCtx)
CallEventRef< CXXDestructorCall > getCXXDestructorCall(const CXXDestructorDecl *DD, const Stmt *Trigger, const MemRegion *Target, bool IsBase, ProgramStateRef State, const LocationContext *LCtx)
Represents a call to a C++ constructor.
virtual const CXXConstructExpr * getOriginExpr() const
CXXAllocatorCall(const CXXAllocatorCall &Other)
virtual RuntimeDefinition getRuntimeDefinition() const =0
Returns the definition of the function or method that will be called.
Represents a C++ constructor within a class.
CallEventRef< T > cloneWithState(ProgramStateRef NewState) const
Returns a copy of this CallEvent, but using the given state.
CXXConstructorCall(const CXXConstructorCall &Other)
VarDecl - An instance of this class is created to represent a variable declaration or definition...
bool isCalled(const CallDescription &CD) const
Returns true if the CallEvent is a call to a function that matches the CallDescription.
static bool classof(const CallEvent *CA)
ObjCMethodDecl - Represents an instance or class method declaration.
virtual void cloneTo(void *Dest) const =0
Copies this CallEvent, with vtable intact, into a new block of memory.
static bool classof(const CallEvent *CA)
llvm::mapped_iterator< ArrayRef< ParmVarDecl * >::iterator, GetTypeFn > param_type_iterator
ArrayRef< ParmVarDecl * > parameters() const override
Return call's formal parameters.
Represents a C++ overloaded operator call where the operator is implemented as a non-static member fu...
param_type_iterator param_type_end() const
ParmVarDecl - Represents a parameter to a function.
Defines the clang::Expr interface and subclasses for C++ expressions.
unsigned getNumArgs() const override
Returns the number of arguments (explicit and implicit).
ObjCMethodCall(const ObjCMethodCall &Other)
const ObjCInterfaceDecl * getReceiverInterface() const
Get the interface for the receiver.
One of these records is kept for each identifier that is lexed.
unsigned getNumArgs() const override
SmallVectorImpl< FrameBindingTy > BindingsTy
ObjCMethodFamily
A family of Objective-C methods.
virtual const CXXOperatorCallExpr * getOriginExpr() const
AnalysisDeclContext contains the context data for the function or method under analysis.
virtual void getExtraInvalidatedValues(ValueList &Values, RegionAndSymbolInvalidationTraits *ETraits) const
Used to specify non-argument regions that will be invalidated as a result of this call...
AnalysisDeclContext * getAnalysisDeclContext() const
const Expr * getOriginExpr() const
Returns the expression whose value will be the result of this call.
const BlockDecl * getDecl() const override
virtual const CallExpr * getOriginExpr() const
i32 captured_struct **param SharedsTy A type which contains references the shared variables *param Shareds Context with the list of shared variables from the p *TaskFunction *param Data Additional data for task generation like final * state
bool argumentsMayEscape() const override
static bool classof(const CallEvent *CA)
Represents the memory allocation call in a C++ new-expression.
Kind getKind() const override
Represents any expression that calls an Objective-C method.
static bool classof(const CallEvent *CA)
virtual Kind getKind() const =0
Returns the kind of call this is.
SVal getSVal(const Stmt *S) const
Get the value of arbitrary expressions at this point in the path.
const FunctionDecl * getDecl() const override
bool isSetter() const
Returns true if this property access or subscript is a setter (has the form of an assignment)...
const FunctionDecl * getDecl() const override
Returns the declaration of the function or method that will be called.
ProgramPoint getProgramPoint(bool IsPreVisit=false, const ProgramPointTag *Tag=nullptr) const
Returns an appropriate ProgramPoint for this call.
const Decl * getDecl() const
bool isConversionFromLambda() const
Represents an ObjC class declaration.
static bool isVariadic(const Decl *D)
Returns true if the given decl is known to be variadic.
detail::InMemoryDirectory::const_iterator I
CXXInstanceCall(const CXXInstanceCall &Other)
virtual SourceRange getArgSourceRange(unsigned Index) const
Returns the source range for errors associated with this argument.
BlockCall(const CallExpr *CE, ProgramStateRef St, const LocationContext *LCtx)
Represents a non-static C++ member function call.
StringRef getFunctionName() const
Get the name of the function that this object matches.
RuntimeDefinition getRuntimeDefinition() const override
ObjCMessageKind
Represents the ways an Objective-C message send can occur.
bool isConversionFromLambda() const
bool isGlobalCFunction(StringRef SpecificName=StringRef()) const
Returns true if the callee is an externally-visible function in the top-level namespace, such as malloc.
Represents a non-static C++ member function call, no matter how it is written.
SourceLocation getLocEnd() const LLVM_READONLY
Stmt * getBody() const
Get the body of the Declaration.
virtual const Expr * getArgExpr(unsigned Index) const
Returns the expression associated with a given argument.
CallEventManager(llvm::BumpPtrAllocator &alloc)
BlockDecl - This represents a block literal declaration, which is like an unnamed FunctionDecl...
Expr - This represents one expression.
const Expr * getArgExpr(unsigned Index) const override
virtual ArrayRef< ParmVarDecl * > parameters() const =0
Return call's formal parameters.
unsigned getNumArgs() const override
const FunctionDecl * getDecl() const override
Returns the declaration of the function or method that will be called.
unsigned getNumArgs() const override
Represents an implicit call to a C++ destructor.
Kind getKind() const override
Represents a C++ destructor within a class.
SmallVectorImpl< SVal > ValueList
Represents a call to any sort of function that might have a FunctionDecl.
bool hasNonNullArgumentsWithType(bool(*Condition)(QualType)) const
Returns true if the type of any of the non-null arguments satisfies the condition.
Kind getKind() const override
Returns the kind of call this is.
bool isInSystemHeader(SourceLocation Loc) const
Returns if a SourceLocation is in a system header.
Kind getKind() const override
CallEvent(const Decl *D, ProgramStateRef state, const LocationContext *lctx)
param_type_iterator param_type_begin() const
Returns an iterator over the types of the call's formal parameters.
RuntimeDefinition getRuntimeDefinition() const override
Returns the definition of the function or method that will be called.
An expression that sends a message to the given Objective-C object or class.
BlockCall(const BlockCall &Other)
CXXMethodDecl * getLambdaCallOperator() const
Retrieve the lambda call operator of the closure type if this is a closure type.
CallEventRef< ObjCMethodCall > getObjCMethodCall(const ObjCMessageExpr *E, ProgramStateRef State, const LocationContext *LCtx)
const VarRegion * getRegionStoringCapturedLambda() const
For a block converted from a C++ lambda, returns the block VarRegion for the variable holding the cap...
Represents a C function or static C++ member function call.
virtual const Expr * getCXXThisExpr() const
Returns the expression representing the implicit 'this' object.
CXXMemberOperatorCall(const CXXMemberOperatorCall &Other)
unsigned getNumArgs() const override
static bool classof(const CallEvent *CA)
ObjCMethodFamily getMethodFamily() const
const Expr * getArgExpr(unsigned Index) const override
void getInitialStackFrameContents(const StackFrameContext *CalleeCtx, BindingsTy &Bindings) const override
Populates the given SmallVector with the bindings in the callee's stack frame at the start of this ca...
CallDescription(StringRef FuncName, unsigned RequiredArgs=NoArgRequirement)
Constructs a CallDescription object.
void cloneTo(void *Dest) const override
Defines the runtime definition of the called function.
Kind getKind() const override
CXXMemberCall(const CXXMemberCallExpr *CE, ProgramStateRef St, const LocationContext *LCtx)
PseudoObjectExpr - An expression which accesses a pseudo-object l-value.
This class represents a description of a function call using the number of arguments and the name of ...
CallEventRef< CXXAllocatorCall > getCXXAllocatorCall(const CXXNewExpr *E, ProgramStateRef State, const LocationContext *LCtx)
Encodes a location in the source.
const Expr * getArgExpr(unsigned Index) const override
CallEventRef(const T *Call)
virtual void getInitialStackFrameContents(const StackFrameContext *CalleeCtx, BindingsTy &Bindings) const =0
Populates the given SmallVector with the bindings in the callee's stack frame at the start of this ca...
static bool isCallStmt(const Stmt *S)
Returns true if this is a statement is a function or method call of some kind.
ProgramPoints can be "tagged" as representing points specific to a given analysis entity...
bool isValid() const
Return true if this is a valid SourceLocation object.
Represents a new-expression for memory allocation and constructor calls, e.g: "new CXXNewExpr(foo)"...
CXXAllocatorCall(const CXXNewExpr *E, ProgramStateRef St, const LocationContext *LCtx)
Represents a call to a member function that may be written either with member call syntax (e...
Represents a static or instance method of a struct/union/class.
const Expr * getArgExpr(unsigned Index) const override
Returns the expression associated with a given argument.
SVal - This represents a symbolic expression, which can be either an L-value or an R-value...
Selector getSelector() const
Represents one property declaration in an Objective-C interface.
unsigned getNumArgs() const override
void cloneTo(void *Dest) const override
void cloneTo(void *Dest) const override
virtual SourceRange getSourceRange() const
Returns a source range for the entire call, suitable for outputting in diagnostics.
const Expr * getArgExpr(unsigned Index) const override
CXXDestructorCall(const CXXDestructorCall &Other)
const IdentifierInfo * getCalleeIdentifier() const
Returns the name of the callee, if its name is a simple identifier.
const MemRegion * getDispatchRegion()
When other definitions are possible, returns the region whose runtime type determines the method defi...
const ObjCMethodDecl * getDecl() const override
CXXConstructorCall(const CXXConstructExpr *CE, const MemRegion *Target, ProgramStateRef St, const LocationContext *LCtx)
Creates a constructor call.
virtual const Decl * getDecl() const
Returns the declaration of the function or method that will be called.
void cloneTo(void *Dest) const override
static const unsigned NoArgRequirement
ProgramStateRef invalidateRegions(unsigned BlockCount, ProgramStateRef Orig=nullptr) const
Returns a new state with all argument regions invalidated.
static bool classof(const CallEvent *CA)
static bool classof(const CallEvent *CA)
std::unique_ptr< DiagnosticConsumer > create(StringRef OutputFile, DiagnosticOptions *Diags, bool MergeChildRecords=false)
Returns a DiagnosticConsumer that serializes diagnostics to a bitcode file.
SimpleFunctionCall(const SimpleFunctionCall &Other)
Kind getKind() const override
RuntimeDefinition(const Decl *InD)
detail::InMemoryDirectory::const_iterator E
unsigned getNumArgs() const
getNumArgs - Return the number of actual arguments to this call.
bool mayHaveOtherDefinitions()
Check if the definition we have is precise.
Represents an abstract call to a function or method along a particular path.
CXXMemberCall(const CXXMemberCall &Other)
SourceRange getSourceRange() const override
QualType getResultType() const
Returns the result type, adjusted for references.
CXXInstanceCall(const CallExpr *CE, ProgramStateRef St, const LocationContext *LCtx)
virtual const CXXMemberCallExpr * getOriginExpr() const
llvm::PointerIntPair< const MemRegion *, 1, bool > DtorDataTy
static QualType getDeclaredResultType(const Decl *D)
Returns the result type of a function or method declaration.
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
const Expr * getArgExpr(unsigned Index) const override
unsigned getNumArgs() const override
void cloneTo(void *Dest) const override
static bool classof(const CallEvent *CE)
CallEventRef< CXXConstructorCall > getCXXConstructorCall(const CXXConstructExpr *E, const MemRegion *Target, ProgramStateRef State, const LocationContext *LCtx)
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate.h) and friends (in DeclFriend.h).
const Expr * getArgExpr(unsigned Index) const override
Represents a C++ struct/union/class.
CallEventRef< T > cloneWithState(ProgramStateRef State) const
virtual unsigned getNumArgs() const =0
Returns the number of arguments (explicit and implicit).
virtual const CallExpr * getOriginExpr() const
const LocationContext * getLocationContext() const
The context in which the call is being evaluated.
unsigned getNumArgs() const override
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
CallEvent(const Expr *E, ProgramStateRef state, const LocationContext *lctx)
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
AnyFunctionCall(const AnyFunctionCall &Other)
std::pair< Loc, SVal > FrameBindingTy
AnyFunctionCall(const Expr *E, ProgramStateRef St, const LocationContext *LCtx)
A trivial tuple used to represent a source range.
SourceLocation getLocation() const
NamedDecl - This represents a decl with a name.
bool hasNonZeroCallbackArg() const
Returns true if any of the arguments appear to represent callbacks.
CXXDestructorCall(const CXXDestructorDecl *DD, const Stmt *Trigger, const MemRegion *Target, bool IsBaseDestructor, ProgramStateRef St, const LocationContext *LCtx)
Creates an implicit destructor.
bool isBaseDestructor() const
Returns true if this is a call to a base class destructor.
virtual const ObjCMessageExpr * getOriginExpr() const
SVal getReturnValue() const
Returns the return value of the call.
Represents a call to a C++ constructor.
This class handles loading and caching of source files into memory.
void cloneTo(void *Dest) const override
Copies this CallEvent, with vtable intact, into a new block of memory.
CallEventRef(const CallEventRef &Orig)
Kind getKind() const override
ArrayRef< SVal > ValueList