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;
59 unsigned RequiredArgs;
71 : II(nullptr), FuncName(FuncName), RequiredArgs(RequiredArgs) {}
77 template<
typename T = CallEvent>
84 return this->
get()->
template cloneWithState<T>(State);
89 template <
typename SuperT>
145 llvm::PointerUnion<const Expr *, const Decl *> Origin;
147 void operator=(
const CallEvent &) =
delete;
159 mutable unsigned RefCount;
162 void Retain()
const { ++RefCount; }
163 void Release()
const;
169 :
State(std::move(state)), LCtx(lctx), Origin(E), RefCount(0) {}
172 :
State(std::move(state)), LCtx(lctx), Origin(D), RefCount(0) {}
176 :
State(Original.
State), LCtx(Original.LCtx), Origin(Original.Origin),
180 virtual void cloneTo(
void *Dest)
const = 0;
204 return Origin.dyn_cast<
const Decl *>();
224 return Origin.dyn_cast<
const Expr *>();
243 getState()->getStateManager().getContext().getSourceManager();
250 return FD->isOverloadedOperator() && FD->isImplicit() && FD->isGlobal();
360 template <
typename T>
365 return cloneWithState<CallEvent>(NewState);
384 typedef std::const_mem_fun_t<QualType, ParmVarDecl> get_type_fun;
413 void dump(raw_ostream &Out)
const;
444 getManager()->getContext(FD);
515 void getExtraInvalidatedValues(
ValueList &Values,
516 RegionAndSymbolInvalidationTraits *ETraits)
const override;
523 unsigned getNumArgs()
const override {
return getOriginExpr()->getNumArgs(); }
526 return getOriginExpr()->getArg(Index);
532 const BlockDataRegion *getBlockRegion()
const;
535 const BlockDataRegion *BR = getBlockRegion();
538 return BR->getDecl();
552 assert(isConversionFromLambda());
553 const BlockDataRegion *BR = getBlockRegion();
554 assert(BR &&
"Block converted from lambda must have a block region");
556 auto I = BR->referenced_vars_begin();
557 assert(
I != BR->referenced_vars_end());
559 return I.getCapturedRegion();
563 if (!isConversionFromLambda())
564 return RuntimeDefinition(getDecl());
585 const VarDecl *LambdaVD = getRegionStoringCapturedLambda()->getDecl();
589 return RuntimeDefinition(LambdaCallOperator);
597 BindingsTy &Bindings)
const override;
612 void getExtraInvalidatedValues(
ValueList &Values,
613 RegionAndSymbolInvalidationTraits *ETraits)
const override;
630 virtual SVal getCXXThisVal()
const;
634 RuntimeDefinition getRuntimeDefinition()
const override;
637 BindingsTy &Bindings)
const override;
661 return cast<CXXMemberCallExpr>(CXXInstanceCall::getOriginExpr());
665 if (
const CallExpr *CE = getOriginExpr())
666 return CE->getNumArgs();
671 return getOriginExpr()->getArg(Index);
674 const Expr *getCXXThisExpr()
const override;
676 RuntimeDefinition getRuntimeDefinition()
const override;
705 return cast<CXXOperatorCallExpr>(CXXInstanceCall::getOriginExpr());
709 return getOriginExpr()->getNumArgs() - 1;
712 return getOriginExpr()->getArg(Index + 1);
715 const Expr *getCXXThisExpr()
const override;
732 typedef llvm::PointerIntPair<const MemRegion *, 1, bool>
DtorDataTy;
742 const MemRegion *Target,
bool IsBaseDestructor,
745 Data =
DtorDataTy(Target, IsBaseDestructor).getOpaqueValue();
746 Location = Trigger->getLocEnd();
756 RuntimeDefinition getRuntimeDefinition()
const override;
759 SVal getCXXThisVal()
const override;
763 return DtorDataTy::getFromOpaqueValue(Data).getInt();
796 void getExtraInvalidatedValues(
ValueList &Values,
797 RegionAndSymbolInvalidationTraits *ETraits)
const override;
805 return getOriginExpr()->getConstructor();
808 unsigned getNumArgs()
const override {
return getOriginExpr()->getNumArgs(); }
811 return getOriginExpr()->getArg(Index);
815 SVal getCXXThisVal()
const;
818 BindingsTy &Bindings)
const override;
847 return getOriginExpr()->getOperatorNew();
851 return getOriginExpr()->getNumPlacementArgs() + 1;
858 return getOriginExpr()->getPlacementArg(Index - 1);
896 void getExtraInvalidatedValues(
ValueList &Values,
897 RegionAndSymbolInvalidationTraits *ETraits)
const override;
908 return getOriginExpr()->getMethodDecl();
911 return getOriginExpr()->getNumArgs();
914 return getOriginExpr()->getArg(Index);
918 return getOriginExpr()->isInstanceMessage();
921 return getOriginExpr()->getMethodFamily();
924 return getOriginExpr()->getSelector();
930 SVal getReceiverSVal()
const;
933 SVal getSelfSVal()
const;
940 return getOriginExpr()->getReceiverInterface();
944 bool isReceiverSelfOrSuper()
const;
953 switch (getMessageKind()) {
955 llvm_unreachable(
"This is not a pseudo-object access!");
961 llvm_unreachable(
"Unknown message kind");
969 RuntimeDefinition getRuntimeDefinition()
const override;
971 bool argumentsMayEscape()
const override;
974 BindingsTy &Bindings)
const override;
996 llvm::BumpPtrAllocator &Alloc;
998 typedef SimpleFunctionCall CallEventTemplateTy;
1000 void reclaim(
const void *Memory) {
1001 Cache.push_back(const_cast<void *>(Memory));
1007 return Alloc.Allocate<CallEventTemplateTy>();
1009 return Cache.pop_back_val();
1012 template <
typename T,
typename Arg>
1014 static_assert(
sizeof(T) ==
sizeof(CallEventTemplateTy),
1015 "CallEvent subclasses are not all the same size");
1016 return new (allocate()) T(A, St, LCtx);
1019 template <
typename T,
typename Arg1,
typename Arg2>
1021 static_assert(
sizeof(T) ==
sizeof(CallEventTemplateTy),
1022 "CallEvent subclasses are not all the same size");
1023 return new (allocate()) T(A1, A2, St, LCtx);
1026 template <
typename T,
typename Arg1,
typename Arg2,
typename Arg3>
1028 const LocationContext *LCtx) {
1029 static_assert(
sizeof(T) ==
sizeof(CallEventTemplateTy),
1030 "CallEvent subclasses are not all the same size");
1031 return new (allocate()) T(A1, A2, A3, St, LCtx);
1034 template <
typename T,
typename Arg1,
typename Arg2,
typename Arg3,
1037 const LocationContext *LCtx) {
1038 static_assert(
sizeof(T) ==
sizeof(CallEventTemplateTy),
1039 "CallEvent subclasses are not all the same size");
1040 return new (allocate()) T(A1, A2, A3, A4, St, LCtx);
1055 CallEventRef<ObjCMethodCall>
1058 return create<ObjCMethodCall>(
E,
State, LCtx);
1061 CallEventRef<CXXConstructorCall>
1064 return create<CXXConstructorCall>(
E, Target,
State, LCtx);
1067 CallEventRef<CXXDestructorCall>
1069 const MemRegion *Target,
bool IsBase,
1071 return create<CXXDestructorCall>(DD, Trigger, Target, IsBase,
State, LCtx);
1074 CallEventRef<CXXAllocatorCall>
1077 return create<CXXAllocatorCall>(
E,
State, LCtx);
1082 template <
typename T>
1084 assert(isa<T>(*
this) &&
"Cloning to unrelated type");
1085 static_assert(
sizeof(T) ==
sizeof(
CallEvent),
1086 "Subclasses may not add fields");
1088 if (NewState ==
State)
1089 return cast<T>(
this);
1092 T *Copy =
static_cast<T *
>(Mgr.allocate());
1094 assert(Copy->getKind() == this->
getKind() &&
"Bad copy");
1096 Copy->State = NewState;
1100 inline void CallEvent::Release()
const {
1101 assert(RefCount > 0 &&
"Reference count is already zero.");
1118 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
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
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)
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
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.
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 TemplateArgument * iterator
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
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
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.
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.
unsigned getNumArgs() const
Retrieve the number of template arguments.
CallEventRef(const CallEventRef &Orig)
Kind getKind() const override
ArrayRef< SVal > ValueList