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),
179 Data(Original.Data), Location(Original.Location), RefCount(0) {}
182 virtual void cloneTo(
void *Dest)
const = 0;
186 return getState()->getSVal(S, getLocationContext());
201 virtual Kind
getKind()
const = 0;
206 return Origin.dyn_cast<
const Decl *>();
226 return Origin.dyn_cast<
const Expr *>();
234 virtual unsigned getNumArgs()
const = 0;
238 const Decl *D = getDecl();
245 getState()->getStateManager().getContext().getSourceManager();
252 return FD->isOverloadedOperator() && FD->isImplicit() && FD->isGlobal();
267 return getOriginExpr()->getSourceRange();
271 virtual SVal getArgSVal(
unsigned Index)
const;
280 virtual SourceRange getArgSourceRange(
unsigned Index)
const;
289 SVal getReturnValue()
const;
293 bool hasNonNullArgumentsWithType(
bool (*Condition)(
QualType))
const;
296 bool hasNonZeroCallbackArg()
const;
299 bool hasVoidPointerToNonConstArg()
const;
307 return hasNonZeroCallbackArg();
326 bool isGlobalCFunction(StringRef SpecificName = StringRef())
const;
336 const NamedDecl *ND = dyn_cast_or_null<NamedDecl>(getDecl());
359 BindingsTy &Bindings)
const = 0;
362 template <
typename T>
367 return cloneWithState<CallEvent>(NewState);
372 static bool isCallStmt(
const Stmt *S);
382 static bool isVariadic(
const Decl *D);
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;
441 bool argumentsMayEscape()
const override;
477 unsigned getNumArgs()
const override {
return getOriginExpr()->getNumArgs(); }
480 return getOriginExpr()->getArg(Index);
504 void getExtraInvalidatedValues(
ValueList &Values,
505 RegionAndSymbolInvalidationTraits *ETraits)
const override;
512 unsigned getNumArgs()
const override {
return getOriginExpr()->getNumArgs(); }
515 return getOriginExpr()->getArg(Index);
521 const BlockDataRegion *getBlockRegion()
const;
524 const BlockDataRegion *BR = getBlockRegion();
527 return BR->getDecl();
541 assert(isConversionFromLambda());
542 const BlockDataRegion *BR = getBlockRegion();
543 assert(BR &&
"Block converted from lambda must have a block region");
545 auto I = BR->referenced_vars_begin();
546 assert(I != BR->referenced_vars_end());
548 return I.getCapturedRegion();
552 if (!isConversionFromLambda())
553 return RuntimeDefinition(getDecl());
574 const VarDecl *LambdaVD = getRegionStoringCapturedLambda()->getDecl();
578 return RuntimeDefinition(LambdaCallOperator);
586 BindingsTy &Bindings)
const override;
601 void getExtraInvalidatedValues(
ValueList &Values,
602 RegionAndSymbolInvalidationTraits *ETraits)
const override;
619 virtual SVal getCXXThisVal()
const;
623 RuntimeDefinition getRuntimeDefinition()
const override;
626 BindingsTy &Bindings)
const override;
650 return cast<CXXMemberCallExpr>(CXXInstanceCall::getOriginExpr());
654 if (
const CallExpr *CE = getOriginExpr())
655 return CE->getNumArgs();
660 return getOriginExpr()->getArg(Index);
663 const Expr *getCXXThisExpr()
const override;
665 RuntimeDefinition getRuntimeDefinition()
const override;
694 return cast<CXXOperatorCallExpr>(CXXInstanceCall::getOriginExpr());
698 return getOriginExpr()->getNumArgs() - 1;
701 return getOriginExpr()->getArg(Index + 1);
704 const Expr *getCXXThisExpr()
const override;
721 typedef llvm::PointerIntPair<const MemRegion *, 1, bool>
DtorDataTy;
731 const MemRegion *Target,
bool IsBaseDestructor,
734 Data = DtorDataTy(Target, IsBaseDestructor).getOpaqueValue();
745 RuntimeDefinition getRuntimeDefinition()
const override;
748 SVal getCXXThisVal()
const override;
752 return DtorDataTy::getFromOpaqueValue(Data).getInt();
785 void getExtraInvalidatedValues(
ValueList &Values,
786 RegionAndSymbolInvalidationTraits *ETraits)
const override;
794 return getOriginExpr()->getConstructor();
797 unsigned getNumArgs()
const override {
return getOriginExpr()->getNumArgs(); }
800 return getOriginExpr()->getArg(Index);
804 SVal getCXXThisVal()
const;
807 BindingsTy &Bindings)
const override;
836 return getOriginExpr()->getOperatorNew();
840 return getOriginExpr()->getNumPlacementArgs() + 1;
847 return getOriginExpr()->getPlacementArg(Index - 1);
885 void getExtraInvalidatedValues(
ValueList &Values,
886 RegionAndSymbolInvalidationTraits *ETraits)
const override;
897 return getOriginExpr()->getMethodDecl();
900 return getOriginExpr()->getNumArgs();
903 return getOriginExpr()->getArg(Index);
907 return getOriginExpr()->isInstanceMessage();
910 return getOriginExpr()->getMethodFamily();
913 return getOriginExpr()->getSelector();
919 SVal getReceiverSVal()
const;
922 SVal getSelfSVal()
const;
929 return getOriginExpr()->getReceiverInterface();
933 bool isReceiverSelfOrSuper()
const;
942 switch (getMessageKind()) {
944 llvm_unreachable(
"This is not a pseudo-object access!");
946 return getNumArgs() > 0;
948 return getNumArgs() > 1;
950 llvm_unreachable(
"Unknown message kind");
958 RuntimeDefinition getRuntimeDefinition()
const override;
960 bool argumentsMayEscape()
const override;
963 BindingsTy &Bindings)
const override;
985 llvm::BumpPtrAllocator &Alloc;
987 typedef SimpleFunctionCall CallEventTemplateTy;
989 void reclaim(
const void *Memory) {
990 Cache.push_back(const_cast<void *>(Memory));
996 return Alloc.Allocate<CallEventTemplateTy>();
998 return Cache.pop_back_val();
1001 template <
typename T,
typename Arg>
1003 static_assert(
sizeof(
T) ==
sizeof(CallEventTemplateTy),
1004 "CallEvent subclasses are not all the same size");
1005 return new (allocate())
T(A, St, LCtx);
1008 template <
typename T,
typename Arg1,
typename Arg2>
1010 static_assert(
sizeof(
T) ==
sizeof(CallEventTemplateTy),
1011 "CallEvent subclasses are not all the same size");
1012 return new (allocate())
T(A1, A2, St, LCtx);
1015 template <
typename T,
typename Arg1,
typename Arg2,
typename Arg3>
1018 static_assert(
sizeof(
T) ==
sizeof(CallEventTemplateTy),
1019 "CallEvent subclasses are not all the same size");
1020 return new (allocate())
T(A1, A2, A3, St, LCtx);
1023 template <
typename T,
typename Arg1,
typename Arg2,
typename Arg3,
1027 static_assert(
sizeof(
T) ==
sizeof(CallEventTemplateTy),
1028 "CallEvent subclasses are not all the same size");
1029 return new (allocate())
T(A1, A2, A3, A4, St, LCtx);
1044 CallEventRef<ObjCMethodCall>
1047 return create<ObjCMethodCall>(E,
State, LCtx);
1050 CallEventRef<CXXConstructorCall>
1053 return create<CXXConstructorCall>(E, Target,
State, LCtx);
1056 CallEventRef<CXXDestructorCall>
1058 const MemRegion *Target,
bool IsBase,
1060 return create<CXXDestructorCall>(DD, Trigger, Target, IsBase,
State, LCtx);
1063 CallEventRef<CXXAllocatorCall>
1066 return create<CXXAllocatorCall>(E,
State, LCtx);
1071 template <
typename T>
1073 assert(isa<T>(*
this) &&
"Cloning to unrelated type");
1074 static_assert(
sizeof(
T) ==
sizeof(
CallEvent),
1075 "Subclasses may not add fields");
1077 if (NewState ==
State)
1078 return cast<T>(
this);
1081 T *Copy =
static_cast<T *
>(Mgr.allocate());
1083 assert(Copy->getKind() == this->
getKind() &&
"Bad copy");
1085 Copy->State = NewState;
1089 inline void CallEvent::Release()
const {
1090 assert(RefCount > 0 &&
"Reference count is already zero.");
1107 template<
class T>
struct simplify_type<
clang::ento::CallEventRef<T> > {
A call to an overloaded operator written using operator syntax.
CallEvent(const CallEvent &Original)
Kind getKind() const override
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.
CallEventRef< T > cloneWithState(ProgramStateRef NewState) const
Returns a copy of this CallEvent, but using the given state.
const CXXConstructorDecl * getDecl() const override
DominatorTree GraphTraits specialization so the DominatorTree can be iterable by generic graph iterat...
CXXInstanceCall(const FunctionDecl *D, ProgramStateRef St, const LocationContext *LCtx)
static SimpleType getSimplifiedValue(clang::ento::CallEventRef< T > Val)
TypePropertyCache< Private > Cache
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)
Defines the SourceManager interface.
void cloneTo(void *Dest) const override
Decl - This represents one declaration (or definition), e.g.
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)
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.
CXXAllocatorCall(const CXXAllocatorCall &Other)
Represents a C++ constructor within a class.
bool isBaseDestructor() const
Returns true if this is a call to a base class destructor.
const Expr * getOriginExpr() const
Returns the expression whose value will be the result of this call.
CXXConstructorCall(const CXXConstructorCall &Other)
VarDecl - An instance of this class is created to represent a variable declaration or definition...
static bool classof(const CallEvent *CA)
SVal getSVal(const Stmt *S) const
Get the value of arbitrary expressions at this point in the path.
ObjCMethodDecl - Represents an instance or class method declaration.
static bool classof(const CallEvent *CA)
llvm::mapped_iterator< ArrayRef< ParmVarDecl * >::iterator, GetTypeFn > param_type_iterator
Represents a C++ overloaded operator call where the operator is implemented as a non-static member fu...
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)
IdentifierInfo * getIdentifier() const
getIdentifier - Get the identifier that names this declaration, if there is one.
One of these records is kept for each identifier that is lexed.
unsigned getNumArgs() const override
SmallVectorImpl< FrameBindingTy > BindingsTy
param_type_iterator param_type_end() const
ObjCMethodFamily
A family of Objective-C methods.
virtual const CallExpr * getOriginExpr() const
const BlockDecl * getDecl() const override
const ObjCInterfaceDecl * getReceiverInterface() const
Get the interface for the receiver.
virtual const Expr * getArgExpr(unsigned Index) const
Returns the expression associated with a given argument.
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
virtual const CXXOperatorCallExpr * getOriginExpr() const
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.
const FunctionDecl * getDecl() const override
static void dump(llvm::raw_ostream &OS, StringRef FunctionName, ArrayRef< CounterExpression > Expressions, ArrayRef< CounterMappingRegion > Regions)
bool isSetter() const
Returns true if this property access or subscript is a setter (has the form of an assignment)...
virtual const CXXConstructExpr * getOriginExpr() const
const FunctionDecl * getDecl() const override
Returns the declaration of the function or method that will be called.
param_type_iterator param_type_begin() const
Returns an iterator over the types of the call's formal parameters.
Represents an ObjC class declaration.
CXXInstanceCall(const CXXInstanceCall &Other)
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.
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
Represents a non-static C++ member function call, no matter how it is written.
SourceLocation getLocEnd() const LLVM_READONLY
const LocationContext * getLocationContext() const
The context in which the call is being evaluated.
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
unsigned getNumArgs() const override
bool isInSystemHeader(SourceLocation Loc) const
Returns if a SourceLocation is in a system header.
const FunctionProtoType * T
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
virtual const CXXNewExpr * getOriginExpr() const
Represents a call to any sort of function that might have a FunctionDecl.
bool isInSystemHeader() const
Returns true if the callee is known to be from a system header.
const IdentifierInfo * getCalleeIdentifier() const
Returns the name of the callee, if its name is a simple identifier.
Kind getKind() const override
Returns the kind of call this is.
virtual const CallExpr * getOriginExpr() const
StringRef getFunctionName() const
Get the name of the function that this object matches.
virtual const Decl * getDecl() const
Returns the declaration of the function or method that will be called.
Kind getKind() const override
CallEvent(const Decl *D, ProgramStateRef state, const LocationContext *lctx)
An expression that sends a message to the given Objective-C object or class.
BlockCall(const BlockCall &Other)
virtual const Expr * getCXXThisExpr() const
Returns the expression representing the implicit 'this' object.
CallEventRef< ObjCMethodCall > getObjCMethodCall(const ObjCMessageExpr *E, ProgramStateRef State, const LocationContext *LCtx)
Represents a C function or static C++ member function call.
const VarRegion * getRegionStoringCapturedLambda() const
For a block converted from a C++ lambda, returns the block VarRegion for the variable holding the cap...
CXXMemberOperatorCall(const CXXMemberOperatorCall &Other)
unsigned getNumArgs() const override
virtual bool argumentsMayEscape() const
Returns true if any of the arguments are known to escape to long- term storage, even if this method w...
static bool classof(const CallEvent *CA)
const Expr * getArgExpr(unsigned Index) const override
virtual SourceRange getSourceRange() const
Returns a source range for the entire call, suitable for outputting in diagnostics.
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)
ProgramPoints can be "tagged" as representing points specific to a given analysis entity...
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.
bool isConversionFromLambda() const
SVal - This represents a symbolic expression, which can be either an L-value or an R-value...
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
const Expr * getArgExpr(unsigned Index) const override
CXXDestructorCall(const CXXDestructorCall &Other)
virtual void getExtraInvalidatedValues(ValueList &Values, RegionAndSymbolInvalidationTraits *ETraits) const
Used to specify non-argument regions that will be invalidated as a result of this call...
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.
void cloneTo(void *Dest) const override
virtual const ObjCMessageExpr * getOriginExpr() const
static const unsigned NoArgRequirement
Selector getSelector() const
Dataflow Directional Tag Classes.
bool isValid() const
Return true if this is a valid SourceLocation object.
CXXMethodDecl * getLambdaCallOperator() const
Retrieve the lambda call operator of the closure type if this is a closure type.
static bool classof(const CallEvent *CA)
bool isConversionFromLambda() const
static bool classof(const CallEvent *CA)
virtual const CXXMemberCallExpr * getOriginExpr() const
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)
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
bool isInstanceMessage() const
CXXInstanceCall(const CallExpr *CE, ProgramStateRef St, const LocationContext *LCtx)
CallEventRef cloneWithState(ProgramStateRef NewState) const
Returns a copy of this CallEvent, but using the given state.
llvm::PointerIntPair< const MemRegion *, 1, bool > DtorDataTy
ObjCMethodFamily getMethodFamily() const
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 ProgramStateRef & getState() const
The state in which the call is being evaluated.
const Expr * getArgExpr(unsigned Index) const override
Represents a C++ struct/union/class.
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]).
static Decl::Kind getKind(const Decl *D)
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.
NamedDecl - This represents a decl with a name.
CXXDestructorCall(const CXXDestructorDecl *DD, const Stmt *Trigger, const MemRegion *Target, bool IsBaseDestructor, ProgramStateRef St, const LocationContext *LCtx)
Creates an implicit destructor.
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.
SourceLocation getLocation() const
CallEventRef(const CallEventRef &Orig)
Kind getKind() const override
CallEventRef< T > cloneWithState(ProgramStateRef State) const
ArrayRef< SVal > ValueList