clang  6.0.0svn
Classes | Public Types | Public Member Functions | Static Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | Friends | List of all members
clang::ento::CallEvent Class Referenceabstract

Represents an abstract call to a function or method along a particular path. More...

#include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h"

Inheritance diagram for clang::ento::CallEvent:
Inheritance graph
[legend]
Collaboration diagram for clang::ento::CallEvent:
Collaboration graph
[legend]

Public Types

typedef CallEventKind Kind
 
typedef std::pair< Loc, SValFrameBindingTy
 
typedef SmallVectorImpl< FrameBindingTyBindingsTy
 
typedef llvm::mapped_iterator< ArrayRef< ParmVarDecl * >::iterator, GetTypeFn > param_type_iterator
 

Public Member Functions

virtual ~CallEvent ()
 
virtual Kind getKind () const =0
 Returns the kind of call this is. More...
 
virtual const DeclgetDecl () const
 Returns the declaration of the function or method that will be called. More...
 
const ProgramStateRefgetState () const
 The state in which the call is being evaluated. More...
 
const LocationContextgetLocationContext () const
 The context in which the call is being evaluated. More...
 
virtual RuntimeDefinition getRuntimeDefinition () const =0
 Returns the definition of the function or method that will be called. More...
 
const ExprgetOriginExpr () const
 Returns the expression whose value will be the result of this call. More...
 
virtual unsigned getNumArgs () const =0
 Returns the number of arguments (explicit and implicit). More...
 
bool isInSystemHeader () const
 Returns true if the callee is known to be from a system header. More...
 
bool isCalled (const CallDescription &CD) const
 Returns true if the CallEvent is a call to a function that matches the CallDescription. More...
 
virtual SourceRange getSourceRange () const
 Returns a source range for the entire call, suitable for outputting in diagnostics. More...
 
virtual SVal getArgSVal (unsigned Index) const
 Returns the value of a given argument at the time of the call. More...
 
virtual const ExprgetArgExpr (unsigned Index) const
 Returns the expression associated with a given argument. More...
 
virtual SourceRange getArgSourceRange (unsigned Index) const
 Returns the source range for errors associated with this argument. More...
 
QualType getResultType () const
 Returns the result type, adjusted for references. More...
 
SVal getReturnValue () const
 Returns the return value of the call. More...
 
bool hasNonNullArgumentsWithType (bool(*Condition)(QualType)) const
 Returns true if the type of any of the non-null arguments satisfies the condition. More...
 
bool hasNonZeroCallbackArg () const
 Returns true if any of the arguments appear to represent callbacks. More...
 
bool hasVoidPointerToNonConstArg () const
 Returns true if any of the arguments is void*. More...
 
virtual bool argumentsMayEscape () const
 Returns true if any of the arguments are known to escape to long- term storage, even if this method will not modify them. More...
 
bool isGlobalCFunction (StringRef SpecificName=StringRef()) const
 Returns true if the callee is an externally-visible function in the top-level namespace, such as malloc. More...
 
const IdentifierInfogetCalleeIdentifier () const
 Returns the name of the callee, if its name is a simple identifier. More...
 
ProgramPoint getProgramPoint (bool IsPreVisit=false, const ProgramPointTag *Tag=nullptr) const
 Returns an appropriate ProgramPoint for this call. More...
 
ProgramStateRef invalidateRegions (unsigned BlockCount, ProgramStateRef Orig=nullptr) const
 Returns a new state with all argument regions invalidated. More...
 
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 call. More...
 
template<typename T >
CallEventRef< TcloneWithState (ProgramStateRef NewState) const
 Returns a copy of this CallEvent, but using the given state. More...
 
CallEventRef cloneWithState (ProgramStateRef NewState) const
 Returns a copy of this CallEvent, but using the given state. More...
 
virtual ArrayRef< ParmVarDecl * > parameters () const =0
 Return call's formal parameters. More...
 
param_type_iterator param_type_begin () const
 Returns an iterator over the types of the call's formal parameters. More...
 
param_type_iterator param_type_end () const
 
void dump (raw_ostream &Out) const
 
void dump () const
 
template<typename T >
CallEventRef< TcloneWithState (ProgramStateRef NewState) const
 

Static Public Member Functions

static bool isCallStmt (const Stmt *S)
 Returns true if this is a statement is a function or method call of some kind. More...
 
static QualType getDeclaredResultType (const Decl *D)
 Returns the result type of a function or method declaration. More...
 
static bool isVariadic (const Decl *D)
 Returns true if the given decl is known to be variadic. More...
 

Protected Types

typedef SmallVectorImpl< SValValueList
 

Protected Member Functions

 CallEvent (const Expr *E, ProgramStateRef state, const LocationContext *lctx)
 
 CallEvent (const Decl *D, ProgramStateRef state, const LocationContext *lctx)
 
 CallEvent (const CallEvent &Original)
 
virtual void cloneTo (void *Dest) const =0
 Copies this CallEvent, with vtable intact, into a new block of memory. More...
 
SVal getSVal (const Stmt *S) const
 Get the value of arbitrary expressions at this point in the path. More...
 
virtual void getExtraInvalidatedValues (ValueList &Values, RegionAndSymbolInvalidationTraits *ETraits) const
 Used to specify non-argument regions that will be invalidated as a result of this call. More...
 

Protected Attributes

const void * Data
 
SourceLocation Location
 

Friends

template<typename T >
struct llvm::IntrusiveRefCntPtrInfo
 
class CallEventManager
 

Detailed Description

Represents an abstract call to a function or method along a particular path.

CallEvents are created through the factory methods of CallEventManager.

CallEvents should always be cheap to create and destroy. In order for CallEventManager to be able to re-use CallEvent-sized memory blocks, subclasses of CallEvent may not add any data members to the base class. Use the "Data" and "Location" fields instead.

Definition at line 140 of file CallEvent.h.

Member Typedef Documentation

◆ BindingsTy

Definition at line 354 of file CallEvent.h.

◆ FrameBindingTy

Definition at line 353 of file CallEvent.h.

◆ Kind

Definition at line 142 of file CallEvent.h.

◆ param_type_iterator

typedef llvm::mapped_iterator<ArrayRef<ParmVarDecl*>::iterator, GetTypeFn> clang::ento::CallEvent::param_type_iterator

Definition at line 399 of file CallEvent.h.

◆ ValueList

Definition at line 190 of file CallEvent.h.

Constructor & Destructor Documentation

◆ CallEvent() [1/3]

clang::ento::CallEvent::CallEvent ( const Expr E,
ProgramStateRef  state,
const LocationContext lctx 
)
inlineprotected

Definition at line 170 of file CallEvent.h.

◆ CallEvent() [2/3]

clang::ento::CallEvent::CallEvent ( const Decl D,
ProgramStateRef  state,
const LocationContext lctx 
)
inlineprotected

Definition at line 173 of file CallEvent.h.

◆ CallEvent() [3/3]

clang::ento::CallEvent::CallEvent ( const CallEvent Original)
inlineprotected

Definition at line 177 of file CallEvent.h.

◆ ~CallEvent()

virtual clang::ento::CallEvent::~CallEvent ( )
inlinevirtual

Definition at line 198 of file CallEvent.h.

References getKind().

Member Function Documentation

◆ argumentsMayEscape()

virtual bool clang::ento::CallEvent::argumentsMayEscape ( ) const
inlinevirtual

Returns true if any of the arguments are known to escape to long- term storage, even if this method will not modify them.

Reimplemented in clang::ento::AnyFunctionCall.

Definition at line 306 of file CallEvent.h.

Referenced by clang::ento::AnyFunctionCall::argumentsMayEscape(), clang::ObjCMethodCall::argumentsMayEscape(), and invalidateRegions().

◆ cloneTo()

virtual void clang::ento::CallEvent::cloneTo ( void *  Dest) const
protectedpure virtual

Copies this CallEvent, with vtable intact, into a new block of memory.

Implemented in clang::ento::SimpleFunctionCall.

◆ cloneWithState() [1/3]

template<typename T >
CallEventRef<T> clang::ento::CallEvent::cloneWithState ( ProgramStateRef  NewState) const

Returns a copy of this CallEvent, but using the given state.

Referenced by clang::ento::ExprEngine::defaultEvalCall(), and clang::ento::CheckerManager::runCheckersForObjCMessage().

◆ cloneWithState() [2/3]

CallEventRef clang::ento::CallEvent::cloneWithState ( ProgramStateRef  NewState) const
inline

Returns a copy of this CallEvent, but using the given state.

Definition at line 366 of file CallEvent.h.

◆ cloneWithState() [3/3]

template<typename T >
CallEventRef<T> clang::ento::CallEvent::cloneWithState ( ProgramStateRef  NewState) const

Definition at line 1072 of file CallEvent.h.

References getKind(), State, and clang::T.

◆ dump() [1/2]

void CallEvent::dump ( raw_ostream &  Out) const

Definition at line 249 of file CallEvent.cpp.

References getState().

◆ dump() [2/2]

LLVM_DUMP_METHOD void CallEvent::dump ( ) const

Definition at line 247 of file CallEvent.cpp.

◆ getArgExpr()

virtual const Expr* clang::ento::CallEvent::getArgExpr ( unsigned  Index) const
inlinevirtual

Returns the expression associated with a given argument.

May be null if this expression does not appear in the source.

Reimplemented in clang::ento::SimpleFunctionCall.

Definition at line 275 of file CallEvent.h.

Referenced by clang::ento::mpi::MPIChecker::checkMissingWaits(), getArgSourceRange(), and getArgSVal().

◆ getArgSourceRange()

SourceRange CallEvent::getArgSourceRange ( unsigned  Index) const
virtual

Returns the source range for errors associated with this argument.

May be invalid if the argument is not written in the source.

Definition at line 233 of file CallEvent.cpp.

References getArgExpr(), and clang::Stmt::getSourceRange().

Referenced by updateOutParameter().

◆ getArgSVal()

SVal CallEvent::getArgSVal ( unsigned  Index) const
virtual

◆ getCalleeIdentifier()

const IdentifierInfo* clang::ento::CallEvent::getCalleeIdentifier ( ) const
inline

Returns the name of the callee, if its name is a simple identifier.

Note that this will fail for Objective-C methods, blocks, and C++ overloaded operators. The former is named by a Selector rather than a simple identifier, and the latter two do not have names.

Definition at line 335 of file CallEvent.h.

Referenced by clang::ento::mpi::MPIChecker::checkDoubleNonblocking(), clang::ento::mpi::MPIChecker::checkMissingWaits(), clang::ento::mpi::MPIChecker::checkUnmatchedWaits(), isCalled(), and isNSStringType().

◆ getDecl()

virtual const Decl* clang::ento::CallEvent::getDecl ( ) const
inlinevirtual

◆ getDeclaredResultType()

QualType CallEvent::getDeclaredResultType ( const Decl D)
static

Returns the result type of a function or method declaration.

This will return a null QualType if the result type cannot be determined.

Definition at line 274 of file CallEvent.cpp.

References clang::Type::getAs(), and clang::Type::isDependentType().

Referenced by clang::ento::ExprEngine::processCallExit().

◆ getExtraInvalidatedValues()

virtual void clang::ento::CallEvent::getExtraInvalidatedValues ( ValueList Values,
RegionAndSymbolInvalidationTraits ETraits 
) const
inlineprotectedvirtual

Used to specify non-argument regions that will be invalidated as a result of this call.

Definition at line 194 of file CallEvent.h.

Referenced by invalidateRegions().

◆ getInitialStackFrameContents()

virtual void clang::ento::CallEvent::getInitialStackFrameContents ( const StackFrameContext CalleeCtx,
BindingsTy Bindings 
) const
pure virtual

Populates the given SmallVector with the bindings in the callee's stack frame at the start of this call.

Implemented in clang::ento::AnyFunctionCall.

Referenced by clang::ento::StoreManager::enterStackFrame().

◆ getKind()

virtual Kind clang::ento::CallEvent::getKind ( ) const
pure virtual

◆ getLocationContext()

const LocationContext* clang::ento::CallEvent::getLocationContext ( ) const
inline

The context in which the call is being evaluated.

Definition at line 215 of file CallEvent.h.

Referenced by clang::ObjCMethodCall::getMessageKind(), clang::ento::AnyFunctionCall::getRuntimeDefinition(), clang::ObjCMethodCall::getSelfSVal(), and invalidateRegions().

◆ getNumArgs()

virtual unsigned clang::ento::CallEvent::getNumArgs ( ) const
pure virtual

Returns the number of arguments (explicit and implicit).

Note that this may be greater than the number of parameters in the callee's declaration, and that it may include arguments not written in the source.

Implemented in clang::ento::SimpleFunctionCall.

Referenced by addParameterValuesToBindings(), clang::ento::mpi::MPIChecker::checkDoubleNonblocking(), GetReturnType(), hasNonNullArgumentsWithType(), invalidateRegions(), isCalled(), isNSStringType(), and updateOutParameter().

◆ getOriginExpr()

const Expr* clang::ento::CallEvent::getOriginExpr ( ) const
inline

◆ getProgramPoint()

ProgramPoint CallEvent::getProgramPoint ( bool  IsPreVisit = false,
const ProgramPointTag Tag = nullptr 
) const

Returns an appropriate ProgramPoint for this call.

Definition at line 196 of file CallEvent.cpp.

Referenced by clang::ento::CheckerManager::runCheckersForObjCMessage().

◆ getResultType()

QualType CallEvent::getResultType ( ) const

Returns the result type, adjusted for references.

Definition at line 31 of file CallEvent.cpp.

Referenced by isNSStringType(), and updateOutParameter().

◆ getReturnValue()

SVal CallEvent::getReturnValue ( ) const

Returns the return value of the call.

This should only be called if the CallEvent was created using a state in which the return value has already been bound to the origin expression.

Definition at line 240 of file CallEvent.cpp.

Referenced by GetReturnType(), isNSStringType(), recordFixedType(), and updateOutParameter().

◆ getRuntimeDefinition()

virtual RuntimeDefinition clang::ento::CallEvent::getRuntimeDefinition ( ) const
pure virtual

Returns the definition of the function or method that will be called.

Implemented in clang::ento::AnyFunctionCall.

◆ getSourceRange()

virtual SourceRange clang::ento::CallEvent::getSourceRange ( ) const
inlinevirtual

Returns a source range for the entire call, suitable for outputting in diagnostics.

Definition at line 266 of file CallEvent.h.

Referenced by clang::ento::mpi::MPIBugReporter::reportDoubleNonblocking(), and clang::ento::mpi::MPIBugReporter::reportUnmatchedWait().

◆ getState()

const ProgramStateRef& clang::ento::CallEvent::getState ( ) const
inline

◆ getSVal()

SVal clang::ento::CallEvent::getSVal ( const Stmt S) const
inlineprotected

◆ hasNonNullArgumentsWithType()

bool CallEvent::hasNonNullArgumentsWithType ( bool(*)(QualType Condition) const

Returns true if the type of any of the non-null arguments satisfies the condition.

Definition at line 90 of file CallEvent.cpp.

References getDecl(), and getNumArgs().

Referenced by hasNonZeroCallbackArg(), and hasVoidPointerToNonConstArg().

◆ hasNonZeroCallbackArg()

bool CallEvent::hasNonZeroCallbackArg ( ) const

Returns true if any of the arguments appear to represent callbacks.

Definition at line 113 of file CallEvent.cpp.

References hasNonNullArgumentsWithType(), and isCallback().

◆ hasVoidPointerToNonConstArg()

bool CallEvent::hasVoidPointerToNonConstArg ( ) const

Returns true if any of the arguments is void*.

Definition at line 117 of file CallEvent.cpp.

References hasNonNullArgumentsWithType(), and isVoidPointerToNonConst().

Referenced by clang::ento::AnyFunctionCall::argumentsMayEscape().

◆ invalidateRegions()

ProgramStateRef CallEvent::invalidateRegions ( unsigned  BlockCount,
ProgramStateRef  Orig = nullptr 
) const

◆ isCalled()

bool CallEvent::isCalled ( const CallDescription CD) const

Returns true if the CallEvent is a call to a function that matches the CallDescription.

Note that this function is not intended to be used to match Obj-C method calls.

Definition at line 213 of file CallEvent.cpp.

References clang::ento::CE_ObjCMessage, getCalleeIdentifier(), getKind(), getNumArgs(), getState(), and clang::ento::CallDescription::NoArgRequirement.

◆ isCallStmt()

bool CallEvent::isCallStmt ( const Stmt S)
static

Returns true if this is a statement is a function or method call of some kind.

Definition at line 268 of file CallEvent.cpp.

Referenced by clang::ento::ExplodedGraph::isInterestingLValueExpr().

◆ isGlobalCFunction()

bool CallEvent::isGlobalCFunction ( StringRef  SpecificName = StringRef()) const

Returns true if the callee is an externally-visible function in the top-level namespace, such as malloc.

You can use this call to determine that a particular function really is a library function and not, say, a C++ member function with the same name.

If a name is provided, the function must additionally match the given name.

Note that this deliberately excludes C++ library functions in the std namespace, but will include C library functions accessed through the std namespace. This also does not check if the function is declared as 'extern "C"', or if it uses C++ name mangling.

Definition at line 121 of file CallEvent.cpp.

References getDecl(), and clang::ento::CheckerContext::isCLibraryFunction().

◆ isInSystemHeader()

bool clang::ento::CallEvent::isInSystemHeader ( ) const
inline

Returns true if the callee is known to be from a system header.

Definition at line 237 of file CallEvent.h.

References clang::Decl::getLocation(), clang::SourceManager::isInSystemHeader(), clang::SourceLocation::isValid(), and SM.

Referenced by clang::ObjCMethodCall::argumentsMayEscape().

◆ isVariadic()

bool CallEvent::isVariadic ( const Decl D)
static

Returns true if the given decl is known to be variadic.

D must not be null.

Definition at line 303 of file CallEvent.cpp.

Referenced by mayInlineDecl().

◆ param_type_begin()

param_type_iterator clang::ento::CallEvent::param_type_begin ( ) const
inline

Returns an iterator over the types of the call's formal parameters.

This uses the callee decl found by default name lookup rather than the definition because it represents a public interface, and probably has more annotations.

Definition at line 406 of file CallEvent.h.

◆ param_type_end()

param_type_iterator clang::ento::CallEvent::param_type_end ( ) const
inline
See also
param_type_begin()

Definition at line 410 of file CallEvent.h.

References dump().

◆ parameters()

virtual ArrayRef<ParmVarDecl*> clang::ento::CallEvent::parameters ( ) const
pure virtual

Return call's formal parameters.

Remember that the number of formal parameters may not match the number of arguments for all calls. However, the first parameter will always correspond with the argument value returned by getArgSVal(0).

Implemented in clang::ento::AnyFunctionCall.

Referenced by clang::BlockCall::getInitialStackFrameContents().

Friends And Related Function Documentation

◆ CallEventManager

friend class CallEventManager
friend

Definition at line 168 of file CallEvent.h.

◆ llvm::IntrusiveRefCntPtrInfo

template<typename T >
friend struct llvm::IntrusiveRefCntPtrInfo
friend

Definition at line 163 of file CallEvent.h.

Member Data Documentation

◆ Data

const void* clang::ento::CallEvent::Data
protected

◆ Location

SourceLocation clang::ento::CallEvent::Location
protected

Definition at line 158 of file CallEvent.h.


The documentation for this class was generated from the following files: