clang: clang::ento::CallEvent Class Reference (original) (raw)

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

#include "[clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h](CallEvent%5F8h%5Fsource.html)"

Public Types
using Kind = CallEventKind
using FrameBindingTy = std::pair< SVal, SVal >
using BindingsTy = SmallVectorImpl< FrameBindingTy >
using param_type_iterator = llvm::mapped_iterator< ArrayRef< ParmVarDecl * >::iterator, GetTypeFn >
Public Member Functions
CallEvent & operator= (const CallEvent &)=delete
virtual ~CallEvent ()=default
virtual Kind getKind () const =0
Returns the kind of call this is.
virtual StringRef getKindAsString () const =0
virtual const Decl * getDecl () const
Returns the declaration of the function or method that will be called.
bool isForeign () const
void setForeign (bool B) const
const ProgramStateRef & getState () const
The state in which the call is being evaluated.
const LocationContext * getLocationContext () const
The context in which the call is being evaluated.
const CFGBlock::ConstCFGElementRef & getCFGElementRef () const
virtual RuntimeDefinition getRuntimeDefinition () const =0
Returns the definition of the function or method that will be called.
virtual const Expr * getOriginExpr () const
Returns the expression whose value will be the result of this call.
virtual unsigned getNumArgs () const =0
Returns the number of arguments (explicit and implicit).
bool isInSystemHeader () const
Returns true if the callee is known to be from a system header.
virtual SourceRange getSourceRange () const
Returns a source range for the entire call, suitable for outputting in diagnostics.
virtual SVal getArgSVal (unsigned Index) const
Returns the value of a given argument at the time of the call.
virtual const Expr * getArgExpr (unsigned Index) const
Returns the expression associated with a given argument.
virtual SourceRange getArgSourceRange (unsigned Index) const
Returns the source range for errors associated with this argument.
QualType getResultType () const
Returns the result type, adjusted for references.
SVal getReturnValue () const
Returns the return value of the call.
bool hasNonNullArgumentsWithType (bool(*Condition)(QualType)) const
Returns true if the type of any of the non-null arguments satisfies the condition.
bool hasNonZeroCallbackArg () const
Returns true if any of the arguments appear to represent callbacks.
bool hasVoidPointerToNonConstArg () const
Returns true if any of the arguments is void*.
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.
bool isGlobalCFunction (StringRef SpecificName=StringRef()) const
Returns true if the callee is an externally-visible function in the top-level namespace, such as malloc.
const IdentifierInfo * getCalleeIdentifier () const
Returns the name of the callee, if its name is a simple identifier.
ProgramPoint getProgramPoint (bool IsPreVisit=false, const ProgramPointTag *Tag=nullptr) const
Returns an appropriate ProgramPoint for this call.
ProgramStateRef invalidateRegions (unsigned BlockCount, ProgramStateRef Orig=nullptr) const
Returns a new state with all argument regions invalidated.
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.
template<typename T >
CallEventRef< T > cloneWithState (ProgramStateRef NewState) const
Returns a copy of this CallEvent, but using the given state.
CallEventRef cloneWithState (ProgramStateRef NewState) const
Returns a copy of this CallEvent, but using the given state.
AnalysisDeclContext * getCalleeAnalysisDeclContext () const
Returns AnalysisDeclContext for the callee stack frame.
const StackFrameContext * getCalleeStackFrame (unsigned BlockCount) const
Returns the callee stack frame.
const ParamVarRegion * getParameterLocation (unsigned Index, unsigned BlockCount) const
Returns memory location for a parameter variable within the callee stack frame.
bool isArgumentConstructedDirectly (unsigned Index) const
Returns true if on the current path, the argument was constructed by calling a C++ constructor over it.
virtual std::optional< unsigned > getAdjustedParameterIndex (unsigned ASTArgumentIndex) const
Some calls have parameter numbering mismatched from argument numbering.
virtual unsigned getASTArgumentIndex (unsigned CallArgumentIndex) const
Some call event sub-classes conveniently adjust mismatching AST indices to match parameter indices.
const ConstructionContext * getConstructionContext () const
Returns the construction context of the call, if it is a C++ constructor call or a call of a function returning a C++ class instance.
std::optional< SVal > getReturnValueUnderConstruction () const
If the call returns a C++ record type then the region of its return value can be retrieved from its construction context.
const CallEventRef getCaller () const
bool isCalledFromSystemHeader () const
virtual ArrayRef< ParmVarDecl * > parameters () const =0
Return call's formal parameters.
param_type_iterator param_type_begin () const
Returns an iterator over the types of the call's formal parameters.
param_type_iterator param_type_end () const
void dump (raw_ostream &Out) const
void dump () 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.
static QualType getDeclaredResultType (const Decl *D)
Returns the result type of a function or method declaration.
static bool isVariadic (const Decl *D)
Returns true if the given decl is known to be variadic.
Protected Member Functions
CallEvent (const Expr *E, ProgramStateRef state, const LocationContext *lctx, CFGBlock::ConstCFGElementRef ElemRef)
CallEvent (const Decl *D, ProgramStateRef state, const LocationContext *lctx, CFGBlock::ConstCFGElementRef ElemRef)
CallEvent (const CallEvent &Original)
virtual void cloneTo (void *Dest) const =0
Copies this CallEvent, with vtable intact, into a new block of memory.
SVal getSVal (const Stmt *S) const
Get the value of arbitrary expressions at this point in the path.
virtual void getExtraInvalidatedValues (ValueList &Values, RegionAndSymbolInvalidationTraits *ETraits) const
Used to specify non-argument regions that will be invalidated as a result of this call.
Friends
template<typename T >
struct llvm::IntrusiveRefCntPtrInfo
class CallEventManager

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

BindingsTy

FrameBindingTy

Kind

param_type_iterator

ValueList

CallEvent() [2/3]

CallEvent() [3/3]

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

~CallEvent()

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

argumentsMayEscape()

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

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, clang::ento::BlockCall, clang::ento::CXXStaticOperatorCall, clang::ento::CXXMemberCall, clang::ento::CXXMemberOperatorCall, clang::ento::CXXDestructorCall, clang::ento::CXXConstructorCall, clang::ento::CXXInheritedConstructorCall, clang::ento::CXXAllocatorCall, clang::ento::CXXDeallocatorCall, and clang::ento::ObjCMethodCall.

Referenced by cloneWithState().

cloneWithState() [1/2]

cloneWithState() [2/2]

dump() [1/2]

LLVM_DUMP_METHOD void CallEvent::dump ( ) const

dump() [2/2]

void CallEvent::dump ( raw_ostream & Out ) const

getAdjustedParameterIndex()

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

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, clang::ento::BlockCall, clang::ento::CXXStaticOperatorCall, clang::ento::CXXMemberCall, clang::ento::CXXMemberOperatorCall, clang::ento::CXXConstructorCall, clang::ento::CXXInheritedConstructorCall, clang::ento::CXXAllocatorCall, clang::ento::CXXDeallocatorCall, and clang::ento::ObjCMethodCall.

Definition at line 293 of file CallEvent.h.

Referenced by getArgSourceRange(), and getArgSVal().

getArgSourceRange()

getArgSVal()

getASTArgumentIndex()

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

getCalleeAnalysisDeclContext()

getCalleeIdentifier()

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

getCalleeStackFrame()

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

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

Referenced by getConstructionContext(), and getParameterLocation().

getCaller()

getCFGElementRef()

getConstructionContext()

getDecl()

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

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

May be null.

Reimplemented in clang::ento::AnyFunctionCall, clang::ento::SimpleFunctionCall, clang::ento::BlockCall, clang::ento::CXXInstanceCall, clang::ento::CXXConstructorCall, clang::ento::CXXInheritedConstructorCall, clang::ento::CXXAllocatorCall, clang::ento::CXXDeallocatorCall, and clang::ento::ObjCMethodCall.

Definition at line 224 of file CallEvent.h.

Referenced by dump(), getCalleeAnalysisDeclContext(), getCalleeIdentifier(), clang::ento::AnyFunctionCall::getDecl(), getProgramPoint(), hasNonNullArgumentsWithType(), invalidateRegions(), isGlobalCFunction(), and isInSystemHeader().

getDeclaredResultType()

QualType CallEvent::getDeclaredResultType ( const Decl * D) static

getExtraInvalidatedValues()

getInitialStackFrameContents()

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

getKind()

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

Returns the kind of call this is.

Implemented in clang::ento::SimpleFunctionCall, clang::ento::BlockCall, clang::ento::CXXStaticOperatorCall, clang::ento::CXXMemberCall, clang::ento::CXXMemberOperatorCall, clang::ento::CXXDestructorCall, clang::ento::CXXConstructorCall, clang::ento::CXXInheritedConstructorCall, clang::ento::CXXAllocatorCall, clang::ento::CXXDeallocatorCall, and clang::ento::ObjCMethodCall.

Referenced by clang::ento::AnyFunctionCall::classof(), clang::ento::SimpleFunctionCall::classof(), clang::ento::BlockCall::classof(), clang::ento::CXXInstanceCall::classof(), clang::ento::CXXStaticOperatorCall::classof(), clang::ento::CXXMemberCall::classof(), clang::ento::CXXMemberOperatorCall::classof(), clang::ento::CXXDestructorCall::classof(), clang::ento::CXXConstructorCall::classof(), clang::ento::CXXInheritedConstructorCall::classof(), clang::ento::ObjCMethodCall::classof(), clang::ento::CXXAllocatorCall::classof(), clang::ento::CXXDeallocatorCall::classof(), and invalidateRegions().

getKindAsString()

virtual StringRef clang::ento::CallEvent::getKindAsString ( ) const pure virtual

Implemented in clang::ento::SimpleFunctionCall, clang::ento::BlockCall, clang::ento::CXXStaticOperatorCall, clang::ento::CXXMemberCall, clang::ento::CXXMemberOperatorCall, clang::ento::CXXDestructorCall, clang::ento::CXXConstructorCall, clang::ento::CXXInheritedConstructorCall, clang::ento::CXXAllocatorCall, clang::ento::CXXDeallocatorCall, and clang::ento::ObjCMethodCall.

Referenced by dump().

getLocationContext()

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

The context in which the call is being evaluated.

Definition at line 238 of file CallEvent.h.

Referenced by clang::ento::CXXAllocatorCall::getArraySizeVal(), getCaller(), clang::ento::CXXInheritedConstructorCall::getInheritingStackFrame(), clang::ento::ObjCMethodCall::getMessageKind(), clang::ento::CXXAllocatorCall::getObjectUnderConstruction(), getProgramPoint(), clang::ento::ObjCMethodCall::getReceiverSVal(), getReturnValueUnderConstruction(), clang::ento::AnyFunctionCall::getRuntimeDefinition(), clang::ento::ObjCMethodCall::getRuntimeDefinition(), getSVal(), invalidateRegions(), isArgumentConstructedDirectly(), and clang::ento::ObjCMethodCall::isReceiverSelfOrSuper().

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, clang::ento::BlockCall, clang::ento::CXXStaticOperatorCall, clang::ento::CXXMemberCall, clang::ento::CXXMemberOperatorCall, clang::ento::CXXDestructorCall, clang::ento::CXXConstructorCall, clang::ento::CXXInheritedConstructorCall, clang::ento::CXXAllocatorCall, clang::ento::CXXDeallocatorCall, and clang::ento::ObjCMethodCall.

Referenced by clang::ento::mpi::MPIChecker::checkDoubleNonblocking(), clang::ento::retaincountchecker::RetainCountChecker::checkSummary(), hasNonNullArgumentsWithType(), invalidateRegions(), clang::ento::retaincountchecker::RetainCountChecker::processSummaryOfInlined(), and updateOutParameters().

getOriginExpr()

virtual const Expr * clang::ento::CallEvent::getOriginExpr ( ) const inlinevirtual

Returns the expression whose value will be the result of this call.

May be null.

Reimplemented in clang::ento::SimpleFunctionCall, clang::ento::BlockCall, clang::ento::CXXStaticOperatorCall, clang::ento::CXXMemberCall, clang::ento::CXXMemberOperatorCall, clang::ento::CXXConstructorCall, clang::ento::CXXInheritedConstructorCall, clang::ento::CXXAllocatorCall, clang::ento::CXXDeallocatorCall, and clang::ento::ObjCMethodCall.

Definition at line 250 of file CallEvent.h.

Referenced by clang::ento::retaincountchecker::RetainCountChecker::checkSummary(), dump(), getCalleeStackFrame(), clang::ento::CXXInstanceCall::getDecl(), clang::ento::SimpleFunctionCall::getOriginExpr(), clang::ento::BlockCall::getOriginExpr(), clang::ento::CXXMemberCall::getOriginExpr(), clang::ento::CXXMemberOperatorCall::getOriginExpr(), clang::ento::CXXConstructorCall::getOriginExpr(), clang::ento::CXXInheritedConstructorCall::getOriginExpr(), clang::ento::CXXAllocatorCall::getOriginExpr(), clang::ento::CXXDeallocatorCall::getOriginExpr(), clang::ento::ObjCMethodCall::getOriginExpr(), getParameterLocation(), getProgramPoint(), getResultType(), getReturnValue(), getReturnValueUnderConstruction(), getSourceRange(), invalidateRegions(), and isArgumentConstructedDirectly().

getParameterLocation()

getProgramPoint()

getResultType()

QualType CallEvent::getResultType ( ) const

getReturnValue()

SVal CallEvent::getReturnValue ( ) const

getReturnValueUnderConstruction()

std::optional< SVal > CallEvent::getReturnValueUnderConstruction ( ) const

getRuntimeDefinition()

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

getSourceRange()

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

getState()

The state in which the call is being evaluated.

Definition at line 235 of file CallEvent.h.

Referenced by clang::ento::ObjCMethodCall::canBeOverridenInSubclass(), dump(), clang::ento::CXXInheritedConstructorCall::getArgSVal(), clang::ento::CXXAllocatorCall::getArraySizeVal(), clang::ento::CXXInstanceCall::getCXXThisVal(), clang::ento::CXXInstanceCall::getDeclForDynamicType(), clang::ento::ObjCMethodCall::getExtraInvalidatedValues(), clang::ento::AnyFunctionCall::getInitialStackFrameContents(), clang::ento::BlockCall::getInitialStackFrameContents(), clang::ento::CXXInstanceCall::getInitialStackFrameContents(), clang::ento::AnyCXXConstructorCall::getInitialStackFrameContents(), clang::ento::ObjCMethodCall::getInitialStackFrameContents(), clang::ento::CXXAllocatorCall::getObjectUnderConstruction(), clang::ento::ObjCMethodCall::getReceiverSVal(), getResultType(), getReturnValueUnderConstruction(), clang::ento::AnyFunctionCall::getRuntimeDefinition(), clang::ento::ObjCMethodCall::getRuntimeDefinition(), getSVal(), invalidateRegions(), isArgumentConstructedDirectly(), isInSystemHeader(), and clang::ento::ObjCMethodCall::isReceiverSelfOrSuper().

getSVal()

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

hasNonNullArgumentsWithType()

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

hasNonZeroCallbackArg()

bool CallEvent::hasNonZeroCallbackArg ( ) const

hasVoidPointerToNonConstArg()

bool CallEvent::hasVoidPointerToNonConstArg ( ) const

invalidateRegions()

Returns a new state with all argument regions invalidated.

This accepts an alternate state in case some processing has already occurred.

Definition at line 234 of file CallEvent.cpp.

References argumentsMayEscape(), clang::ento::CE_CXXAllocator, findPtrToConstParams(), getAdjustedParameterIndex(), getArgSVal(), getDecl(), getExtraInvalidatedValues(), getKind(), getLocationContext(), getNumArgs(), getOriginExpr(), getParameterLocation(), getState(), isArgumentConstructedDirectly(), clang::Result, clang::ento::RegionAndSymbolInvalidationTraits::setTrait(), and clang::ento::RegionAndSymbolInvalidationTraits::TK_PreserveContents.

isArgumentConstructedDirectly()

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

isCalledFromSystemHeader()

bool CallEvent::isCalledFromSystemHeader ( ) const

isCallStmt()

bool CallEvent::isCallStmt ( const Stmt * S) static

isForeign()

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

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

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

isInSystemHeader()

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

isVariadic()

bool CallEvent::isVariadic ( const Decl * D) static

operator=()

param_type_begin()

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

References parameters().

Referenced by hasNonNullArgumentsWithType().

param_type_end()

parameters()

setForeign()

void clang::ento::CallEvent::setForeign ( bool B) const inline

CallEventManager

llvm::IntrusiveRefCntPtrInfo

Data

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

Location


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