16 #ifndef LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_CALLEVENT_H
17 #define LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_CALLEVENT_H
26 #include "llvm/ADT/PointerIntPair.h"
30 class ProgramPointTag;
52 template<
typename T = CallEvent>
59 return this->
get()->
template cloneWithState<T>(State);
64 template <
typename SuperT>
120 llvm::PointerUnion<const Expr *, const Decl *> Origin;
122 void operator=(
const CallEvent &) =
delete;
134 mutable unsigned RefCount;
137 void Retain()
const { ++RefCount; }
138 void Release()
const;
144 :
State(state), LCtx(lctx), Origin(E), RefCount(0) {}
147 :
State(state), LCtx(lctx), Origin(D), RefCount(0) {}
151 :
State(Original.
State), LCtx(Original.LCtx), Origin(Original.Origin),
155 virtual void cloneTo(
void *Dest)
const = 0;
178 return Origin.dyn_cast<
const Decl *>();
198 return Origin.dyn_cast<
const Expr *>();
217 getState()->getStateManager().getContext().getSourceManager();
224 return FD->isOverloadedOperator() && FD->isImplicit() && FD->isGlobal();
320 template <
typename T>
325 return cloneWithState<CallEvent>(NewState);
344 typedef std::const_mem_fun_t<QualType, ParmVarDecl> get_type_fun;
354 typedef llvm::mapped_iterator<ArrayRef<ParmVarDecl*>::iterator, get_type_fun>
363 return llvm::map_iterator(
parameters().begin(),
373 void dump(raw_ostream &Out)
const;
404 getManager()->getContext(FD);
475 void getExtraInvalidatedValues(
ValueList &Values)
const override;
482 unsigned getNumArgs()
const override {
return getOriginExpr()->getNumArgs(); }
485 return getOriginExpr()->getArg(Index);
491 const BlockDataRegion *getBlockRegion()
const;
494 const BlockDataRegion *BR = getBlockRegion();
497 return BR->getDecl();
501 return RuntimeDefinition(getDecl());
509 BindingsTy &Bindings)
const override;
524 void getExtraInvalidatedValues(
ValueList &Values)
const override;
541 virtual SVal getCXXThisVal()
const;
545 RuntimeDefinition getRuntimeDefinition()
const override;
548 BindingsTy &Bindings)
const override;
572 return cast<CXXMemberCallExpr>(CXXInstanceCall::getOriginExpr());
576 if (
const CallExpr *CE = getOriginExpr())
577 return CE->getNumArgs();
582 return getOriginExpr()->getArg(Index);
585 const Expr *getCXXThisExpr()
const override;
587 RuntimeDefinition getRuntimeDefinition()
const override;
616 return cast<CXXOperatorCallExpr>(CXXInstanceCall::getOriginExpr());
620 return getOriginExpr()->getNumArgs() - 1;
623 return getOriginExpr()->getArg(Index + 1);
626 const Expr *getCXXThisExpr()
const override;
643 typedef llvm::PointerIntPair<const MemRegion *, 1, bool>
DtorDataTy;
653 const MemRegion *Target,
bool IsBaseDestructor,
656 Data =
DtorDataTy(Target, IsBaseDestructor).getOpaqueValue();
657 Location = Trigger->getLocEnd();
667 RuntimeDefinition getRuntimeDefinition()
const override;
670 SVal getCXXThisVal()
const override;
674 return DtorDataTy::getFromOpaqueValue(Data).getInt();
707 void getExtraInvalidatedValues(
ValueList &Values)
const override;
715 return getOriginExpr()->getConstructor();
718 unsigned getNumArgs()
const override {
return getOriginExpr()->getNumArgs(); }
721 return getOriginExpr()->getArg(Index);
725 SVal getCXXThisVal()
const;
728 BindingsTy &Bindings)
const override;
757 return getOriginExpr()->getOperatorNew();
761 return getOriginExpr()->getNumPlacementArgs() + 1;
768 return getOriginExpr()->getPlacementArg(Index - 1);
806 void getExtraInvalidatedValues(
ValueList &Values)
const override;
817 return getOriginExpr()->getMethodDecl();
820 return getOriginExpr()->getNumArgs();
823 return getOriginExpr()->getArg(Index);
827 return getOriginExpr()->isInstanceMessage();
830 return getOriginExpr()->getMethodFamily();
833 return getOriginExpr()->getSelector();
839 SVal getReceiverSVal()
const;
842 SVal getSelfSVal()
const;
849 return getOriginExpr()->getReceiverInterface();
853 bool isReceiverSelfOrSuper()
const;
862 switch (getMessageKind()) {
864 llvm_unreachable(
"This is not a pseudo-object access!");
866 return getNumArgs() > 0;
868 return getNumArgs() > 1;
870 llvm_unreachable(
"Unknown message kind");
873 RuntimeDefinition getRuntimeDefinition()
const override;
875 bool argumentsMayEscape()
const override;
878 BindingsTy &Bindings)
const override;
900 llvm::BumpPtrAllocator &Alloc;
902 typedef SimpleFunctionCall CallEventTemplateTy;
904 void reclaim(
const void *Memory) {
905 Cache.push_back(const_cast<void *>(Memory));
911 return Alloc.Allocate<CallEventTemplateTy>();
913 return Cache.pop_back_val();
916 template <
typename T,
typename Arg>
918 static_assert(
sizeof(T) ==
sizeof(CallEventTemplateTy),
919 "CallEvent subclasses are not all the same size");
920 return new (allocate()) T(A, St, LCtx);
923 template <
typename T,
typename Arg1,
typename Arg2>
925 static_assert(
sizeof(T) ==
sizeof(CallEventTemplateTy),
926 "CallEvent subclasses are not all the same size");
927 return new (allocate()) T(A1, A2, St, LCtx);
930 template <
typename T,
typename Arg1,
typename Arg2,
typename Arg3>
932 const LocationContext *LCtx) {
933 static_assert(
sizeof(T) ==
sizeof(CallEventTemplateTy),
934 "CallEvent subclasses are not all the same size");
935 return new (allocate()) T(A1, A2, A3, St, LCtx);
938 template <
typename T,
typename Arg1,
typename Arg2,
typename Arg3,
941 const LocationContext *LCtx) {
942 static_assert(
sizeof(T) ==
sizeof(CallEventTemplateTy),
943 "CallEvent subclasses are not all the same size");
944 return new (allocate()) T(A1, A2, A3, A4, St, LCtx);
959 CallEventRef<ObjCMethodCall>
962 return create<ObjCMethodCall>(E,
State, LCtx);
965 CallEventRef<CXXConstructorCall>
968 return create<CXXConstructorCall>(E, Target,
State, LCtx);
971 CallEventRef<CXXDestructorCall>
973 const MemRegion *Target,
bool IsBase,
975 return create<CXXDestructorCall>(DD, Trigger, Target, IsBase,
State, LCtx);
978 CallEventRef<CXXAllocatorCall>
981 return create<CXXAllocatorCall>(E,
State, LCtx);
986 template <
typename T>
988 assert(isa<T>(*
this) &&
"Cloning to unrelated type");
989 static_assert(
sizeof(T) ==
sizeof(
CallEvent),
990 "Subclasses may not add fields");
992 if (NewState ==
State)
993 return cast<T>(
this);
996 T *Copy =
static_cast<T *
>(Mgr.allocate());
998 assert(Copy->getKind() == this->
getKind() &&
"Bad copy");
1000 Copy->State = NewState;
1004 inline void CallEvent::Release()
const {
1005 assert(RefCount > 0 &&
"Reference count is already zero.");
1022 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
RuntimeDefinition(const Decl *InD, const MemRegion *InR)
Smart pointer class that efficiently represents Objective-C method names.
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
CXXInstanceCall(const FunctionDecl *D, ProgramStateRef St, const LocationContext *LCtx)
static SimpleType getSimplifiedValue(clang::ento::CallEventRef< T > Val)
void cloneTo(void *Dest) const override
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
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)
static bool classof(const CallEvent *CA)
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)
ArrayRef< ParmVarDecl * > parameters() const override
Represents a C++ overloaded operator call where the operator is implemented as a non-static member fu...
param_type_iterator param_type_end() const
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.
unsigned getNumArgs() const override
SmallVectorImpl< FrameBindingTy > BindingsTy
ObjCMethodFamily
A family of Objective-C methods.
virtual const CXXOperatorCallExpr * getOriginExpr() const
AnalysisDeclContext * getAnalysisDeclContext() const
const Expr * getOriginExpr() const
Returns the expression whose value will be the result of this call. May be null.
const BlockDecl * getDecl() const override
virtual const CallExpr * getOriginExpr() const
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
const FunctionDecl * getDecl() const override
Returns the declaration of the function or method that will be called. May be null.
ProgramPoint getProgramPoint(bool IsPreVisit=false, const ProgramPointTag *Tag=nullptr) const
Returns an appropriate ProgramPoint for this call.
const Decl * getDecl() const
Represents an ObjC class declaration.
static bool isVariadic(const Decl *D)
Returns true if the given decl is known to be variadic.
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.
RuntimeDefinition getRuntimeDefinition() const override
ObjCMessageKind
Represents the ways an Objective-C message send can occur.
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.
Stmt * getBody() const
Get the body of the Declaration.
virtual const Expr * getArgExpr(unsigned Index) const
Returns the expression associated with a given argument. May be null if this expression does not appe...
CallEventManager(llvm::BumpPtrAllocator &alloc)
const Expr * getArgExpr(unsigned Index) const override
virtual ArrayRef< ParmVarDecl * > parameters() const =0
unsigned getNumArgs() const override
const FunctionDecl * getDecl() const override
Returns the declaration of the function or method that will be called. May be null.
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.
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
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)
CallEventRef< ObjCMethodCall > getObjCMethodCall(const ObjCMessageExpr *E, ProgramStateRef State, const LocationContext *LCtx)
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
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)
CallEventRef< CXXAllocatorCall > getCXXAllocatorCall(const CXXNewExpr *E, ProgramStateRef State, const LocationContext *LCtx)
Encodes a location in the source. The SourceManager can decode this to get at the full include stack...
const Expr * getArgExpr(unsigned Index) const override
CallEventRef(const T *Call)
virtual void getInitialStackFrameContents(const StackFrameContext *CalleeCtx, BindingsTy &Bindings) const =0
static bool isCallStmt(const Stmt *S)
Returns true if this is a statement is a function or method call of some kind.
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)
const Expr * getArgExpr(unsigned Index) const override
Returns the expression associated with a given argument. May be null if this expression does not appe...
Selector getSelector() const
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()
virtual void getExtraInvalidatedValues(ValueList &Values) const
Used to specify non-argument regions that will be invalidated as a result of this call...
const ObjCMethodDecl * getDecl() const override
CXXConstructorCall(const CXXConstructExpr *CE, const MemRegion *Target, ProgramStateRef St, const LocationContext *LCtx)
virtual const Decl * getDecl() const
Returns the declaration of the function or method that will be called. May be null.
void cloneTo(void *Dest) const override
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)
unsigned getNumArgs() const
bool mayHaveOtherDefinitions()
Check if the definition we have is precise. If not, it is possible that the call dispatches to anothe...
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.
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
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
CallEvent(const Expr *E, ProgramStateRef state, const LocationContext *lctx)
AnyFunctionCall(const AnyFunctionCall &Other)
std::pair< Loc, SVal > FrameBindingTy
llvm::mapped_iterator< ArrayRef< ParmVarDecl * >::iterator, get_type_fun > param_type_iterator
AnyFunctionCall(const Expr *E, ProgramStateRef St, const LocationContext *LCtx)
A trivial tuple used to represent a source range.
SourceLocation getLocation() const
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)
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