clang  8.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

using Kind = CallEventKind
 
using FrameBindingTy = std::pair< Loc, SVal >
 
using BindingsTy = SmallVectorImpl< FrameBindingTy >
 
using param_type_iterator = llvm::mapped_iterator< ArrayRef< ParmVarDecl * >::iterator, GetTypeFn >
 

Public Member Functions

CallEventoperator= (const CallEvent &)=delete
 
virtual ~CallEvent ()=default
 
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< T > cloneWithState (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...
 
AnalysisDeclContextgetCalleeAnalysisDeclContext () const
 Returns AnalysisDeclContext for the callee stack frame. More...
 
const StackFrameContextgetCalleeStackFrame () const
 Returns the callee stack frame. More...
 
const VarRegiongetParameterLocation (unsigned Index) const
 Returns memory location for a parameter variable within the callee stack frame. More...
 
bool isArgumentConstructedDirectly (unsigned Index) const
 Returns true if on the current path, the argument was constructed by calling a C++ constructor over it. More...
 
virtual Optional< unsigned > getAdjustedParameterIndex (unsigned ASTArgumentIndex) const
 Some calls have parameter numbering mismatched from argument numbering. More...
 
virtual unsigned getASTArgumentIndex (unsigned CallArgumentIndex) const
 Some call event sub-classes conveniently adjust mismatching AST indices to match parameter indices. 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< T > cloneWithState (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

using ValueList = SmallVectorImpl< SVal >
 

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 171 of file CallEvent.h.

Member Typedef Documentation

◆ BindingsTy

Definition at line 384 of file CallEvent.h.

◆ FrameBindingTy

Definition at line 383 of file CallEvent.h.

◆ Kind

Definition at line 173 of file CallEvent.h.

◆ param_type_iterator

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

Definition at line 471 of file CallEvent.h.

◆ ValueList

Definition at line 219 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 200 of file CallEvent.h.

◆ CallEvent() [2/3]

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

Definition at line 203 of file CallEvent.h.

◆ CallEvent() [3/3]

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

Definition at line 207 of file CallEvent.h.

◆ ~CallEvent()

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

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 336 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 396 of file CallEvent.h.

◆ cloneWithState() [3/3]

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

Definition at line 1175 of file CallEvent.h.

References getKind(), and State.

◆ dump() [1/2]

void CallEvent::dump ( raw_ostream &  Out) const

◆ dump() [2/2]

LLVM_DUMP_METHOD void CallEvent::dump ( ) const

Definition at line 422 of file CallEvent.cpp.

◆ getAdjustedParameterIndex()

virtual Optional<unsigned> clang::ento::CallEvent::getAdjustedParameterIndex ( unsigned  ASTArgumentIndex) const
inlinevirtual

Some calls have parameter numbering mismatched from argument numbering.

This function converts an argument index to the corresponding parameter index. Returns None is the argument doesn't correspond to any parameter variable.

Definition at line 445 of file CallEvent.h.

Referenced by invalidateRegions().

◆ 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 305 of file CallEvent.h.

Referenced by clang::ento::mpi::MPIChecker::checkMissingWaits().

◆ 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 408 of file CallEvent.cpp.

Referenced by clang::ento::retaincountchecker::RetainCountChecker::checkSummary().

◆ getArgSVal()

SVal CallEvent::getArgSVal ( unsigned  Index) const
virtual

◆ getASTArgumentIndex()

virtual unsigned clang::ento::CallEvent::getASTArgumentIndex ( unsigned  CallArgumentIndex) const
inlinevirtual

Some call event sub-classes conveniently adjust mismatching AST indices to match parameter indices.

This function converts an argument index as understood by CallEvent to the argument index as understood by the AST.

Definition at line 452 of file CallEvent.h.

References clang::ValueDecl::getType().

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

◆ getCalleeAnalysisDeclContext()

AnalysisDeclContext * CallEvent::getCalleeAnalysisDeclContext ( ) const

◆ 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 365 of file CallEvent.h.

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

◆ getCalleeStackFrame()

const StackFrameContext * CallEvent::getCalleeStackFrame ( ) const

Returns the callee stack frame.

That stack frame will only be entered during analysis if the call is inlined, but it may still be useful in intermediate calculations even if the call isn't inlined. May fail; returns null on failure.

Definition at line 195 of file CallEvent.cpp.

References clang::LocationContext::getAnalysisDeclContext(), clang::CFGStmtMap::getBlock(), getCalleeAnalysisDeclContext(), clang::AnalysisDeclContext::getCFGStmtMap(), clang::AnalysisDeclContext::getManager(), getOriginExpr(), clang::AnalysisDeclContextManager::getStackFrame(), and clang::CFGBlock::size().

◆ 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 448 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 223 of file CallEvent.h.

References getKind().

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

◆ 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 clang::ento::mpi::MPIChecker::checkDoubleNonblocking(), clang::ento::retaincountchecker::RetainCountChecker::checkSummary(), hasNonNullArgumentsWithType(), invalidateRegions(), isCalled(), clang::ento::retaincountchecker::RetainCountChecker::processSummaryOfInlined(), and clang::ento::ExprEngine::VisitCallExpr().

◆ getOriginExpr()

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

◆ getParameterLocation()

const VarRegion * CallEvent::getParameterLocation ( unsigned  Index) const

Returns memory location for a parameter variable within the callee stack frame.

May fail; returns null on failure.

Definition at line 224 of file CallEvent.cpp.

Referenced by invalidateRegions().

◆ getProgramPoint()

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

◆ getResultType()

QualType CallEvent::getResultType ( ) const

◆ 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 415 of file CallEvent.cpp.

References getOriginExpr(), and getSVal().

Referenced by clang::ento::retaincountchecker::RetainCountChecker::checkSummary(), and clang::ento::retaincountchecker::RetainCountChecker::processSummaryOfInlined().

◆ 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.

Referenced by getCalleeAnalysisDeclContext().

◆ 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 296 of file CallEvent.h.

Referenced by getProgramPoint(), 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 131 of file CallEvent.cpp.

References getArgSVal(), getDecl(), getNumArgs(), param_type_begin(), and param_type_end().

Referenced by hasNonZeroCallbackArg(), and hasVoidPointerToNonConstArg().

◆ hasNonZeroCallbackArg()

bool CallEvent::hasNonZeroCallbackArg ( ) const

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

Definition at line 154 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 158 of file CallEvent.cpp.

References hasNonNullArgumentsWithType(), and isVoidPointerToNonConst().

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

◆ invalidateRegions()

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

◆ isArgumentConstructedDirectly()

bool clang::ento::CallEvent::isArgumentConstructedDirectly ( unsigned  Index) const
inline

Returns true if on the current path, the argument was constructed by calling a C++ constructor over it.

This is an internal detail of the analysis which doesn't necessarily represent the program semantics: if we are supposed to construct an argument directly, we may still not do that because we don't know how (i.e., construction context is unavailable in the CFG or not supported by the analyzer).

Definition at line 434 of file CallEvent.h.

References clang::ento::ExprEngine::getObjectUnderConstruction().

Referenced by invalidateRegions().

◆ 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 356 of file CallEvent.cpp.

References clang::ento::CE_ObjCMessage, getCalleeIdentifier(), getDecl(), clang::Decl::getDeclContext(), clang::ento::CallDescription::getFunctionName(), getKind(), getNumArgs(), clang::DeclContext::getParent(), 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 442 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 162 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 267 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 477 of file CallEvent.cpp.

Referenced by clang::ento::ExprEngine::CreateCXXTemporaryObject(), and mayInlineDecl().

◆ operator=()

CallEvent& clang::ento::CallEvent::operator= ( const CallEvent )
delete

◆ 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 478 of file CallEvent.h.

Referenced by hasNonNullArgumentsWithType().

◆ param_type_end()

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

Definition at line 482 of file CallEvent.h.

References dump().

Referenced by hasNonNullArgumentsWithType().

◆ 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(), and shouldEscapeArgumentOnCall().

Friends And Related Function Documentation

◆ CallEventManager

friend class CallEventManager
friend

Definition at line 198 of file CallEvent.h.

◆ llvm::IntrusiveRefCntPtrInfo

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

Definition at line 190 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 187 of file CallEvent.h.


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