clang API Documentation

Public Types | Public Member Functions | Static Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | Friends
clang::ento::CallEvent Class Reference

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

#include <CallEvent.h>

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

List of all members.

Public Types

typedef CallEventKind Kind
typedef std::pair< Loc, SValFrameBindingTy
typedef SmallVectorImpl
< FrameBindingTy
BindingsTy
typedef llvm::mapped_iterator
< ArrayRef< ParmVarDecl * >
::iterator, get_type_fun > 
param_type_iterator

Public Member Functions

virtual ~CallEvent ()
virtual Kind getKind () const =0
 Returns the kind of call this is.
virtual const DeclgetDecl () const
 Returns the declaration of the function or method that will be called. May be null.
const ProgramStateRefgetState () const
 The state in which the call is being evaluated.
const LocationContextgetLocationContext () const
 The context in which the call is being evaluated.
virtual RuntimeDefinition getRuntimeDefinition () const =0
 Returns the definition of the function or method that will be called.
const ExprgetOriginExpr () const
 Returns the expression whose value will be the result of this call. May be null.
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 ExprgetArgExpr (unsigned Index) const
 Returns the expression associated with a given argument. May be null if this expression does not appear in the source.
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 hasNonZeroCallbackArg () const
 Returns true if any of the arguments appear to represent callbacks.
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 IdentifierInfogetCalleeIdentifier () 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
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.
virtual ArrayRef< ParmVarDecl * > parameters () const =0
param_type_iterator param_type_begin () const
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.
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 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.
SVal getSVal (const Stmt *S) const
 Get the value of arbitrary expressions at this point in the path.
virtual void getExtraInvalidatedValues (ValueList &Values) const
 Used to specify non-argument regions that will be invalidated as a result of this call.

Protected Attributes

const void * Data
SourceLocation Location

Friends

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


Member Typedef Documentation

Definition at line 312 of file CallEvent.h.

Definition at line 311 of file CallEvent.h.

Definition at line 115 of file CallEvent.h.

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

Definition at line 355 of file CallEvent.h.

typedef SmallVectorImpl<SVal> clang::ento::CallEvent::ValueList [protected]

Definition at line 163 of file CallEvent.h.


Constructor & Destructor Documentation

clang::ento::CallEvent::CallEvent ( const Expr E,
ProgramStateRef  state,
const LocationContext lctx 
) [inline, protected]

Definition at line 143 of file CallEvent.h.

clang::ento::CallEvent::CallEvent ( const Decl D,
ProgramStateRef  state,
const LocationContext lctx 
) [inline, protected]

Definition at line 146 of file CallEvent.h.

clang::ento::CallEvent::CallEvent ( const CallEvent Original) [inline, protected]

Definition at line 150 of file CallEvent.h.

virtual clang::ento::CallEvent::~CallEvent ( ) [inline, virtual]

Definition at line 170 of file CallEvent.h.


Member Function Documentation

virtual bool clang::ento::CallEvent::argumentsMayEscape ( ) const [inline, virtual]

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

References hasNonZeroCallbackArg().

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

virtual void clang::ento::CallEvent::cloneTo ( void *  Dest) const [protected, pure virtual]

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

Implemented in clang::ento::SimpleFunctionCall.

Referenced by cloneWithState().

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().

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

Definition at line 324 of file CallEvent.h.

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

Definition at line 987 of file CallEvent.h.

References cloneTo(), getKind(), State, and clang::SrcMgr::static_assert().

void CallEvent::dump ( raw_ostream &  Out) const
LLVM_DUMP_METHOD void CallEvent::dump ( ) const

Definition at line 216 of file CallEvent.cpp.

virtual const Expr* clang::ento::CallEvent::getArgExpr ( unsigned  Index) const [inline, virtual]

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

Referenced by getArgSourceRange(), and getArgSVal().

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

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

SVal CallEvent::getArgSVal ( unsigned  Index) const [virtual]

Returns the value of a given argument at the time of the call.

Definition at line 195 of file CallEvent.cpp.

References getArgExpr(), and getSVal().

Referenced by addParameterValuesToBindings(), hasNonZeroCallbackArg(), and invalidateRegions().

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

References getDecl(), and clang::NamedDecl::getIdentifier().

virtual const Decl* clang::ento::CallEvent::getDecl ( ) const [inline, virtual]

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

Reimplemented in clang::ento::SimpleFunctionCall, and clang::ento::AnyFunctionCall.

Definition at line 177 of file CallEvent.h.

Referenced by dump(), getCalleeIdentifier(), getProgramPoint(), hasNonZeroCallbackArg(), invalidateRegions(), isGlobalCFunction(), and isInSystemHeader().

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

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

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

virtual void clang::ento::CallEvent::getExtraInvalidatedValues ( ValueList Values) const [inline, protected, virtual]

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

Definition at line 167 of file CallEvent.h.

Referenced by invalidateRegions().

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().

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

The context in which the call is being evaluated.

Definition at line 187 of file CallEvent.h.

Referenced by getProgramPoint(), clang::ento::AnyFunctionCall::getRuntimeDefinition(), getSVal(), and invalidateRegions().

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(), hasNonZeroCallbackArg(), and invalidateRegions().

const Expr* clang::ento::CallEvent::getOriginExpr ( ) const [inline]
ProgramPoint CallEvent::getProgramPoint ( bool  IsPreVisit = false,
const ProgramPointTag Tag = nullptr 
) const

Returns an appropriate ProgramPoint for this call.

Definition at line 178 of file CallEvent.cpp.

References clang::SourceRange::getBegin(), getDecl(), getLocationContext(), getOriginExpr(), and getSourceRange().

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

References getOriginExpr(), and getSVal().

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

Implemented in clang::ento::AnyFunctionCall.

virtual SourceRange clang::ento::CallEvent::getSourceRange ( ) const [inline, virtual]

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

Definition at line 231 of file CallEvent.h.

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

Referenced by getProgramPoint().

The state in which the call is being evaluated.

Definition at line 182 of file CallEvent.h.

References State.

Referenced by dump(), clang::ento::AnyFunctionCall::getInitialStackFrameContents(), getResultType(), getSVal(), invalidateRegions(), and isInSystemHeader().

SVal clang::ento::CallEvent::getSVal ( const Stmt S) const [inline, protected]

Get the value of arbitrary expressions at this point in the path.

Definition at line 158 of file CallEvent.h.

References getLocationContext(), and getState().

Referenced by getArgSVal(), clang::ento::SimpleFunctionCall::getDecl(), and getReturnValue().

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

Definition at line 81 of file CallEvent.cpp.

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

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

ProgramStateRef CallEvent::invalidateRegions ( unsigned  BlockCount,
ProgramStateRef  Orig = nullptr 
) const
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 237 of file CallEvent.cpp.

References S.

Referenced by shouldRemoveDeadBindings(), and clang::ento::bugreporter::trackNullOrUndefValue().

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

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

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

Definition at line 209 of file CallEvent.h.

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

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

Referenced by mayInlineDecl().

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

References clang::ValueDecl::getType(), and parameters().

Referenced by findPtrToConstParams(), and hasNonZeroCallbackArg().

See also:
param_type_begin()

Definition at line 367 of file CallEvent.h.

References clang::ValueDecl::getType(), and parameters().

Referenced by findPtrToConstParams(), and hasNonZeroCallbackArg().

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 param_type_begin(), and param_type_end().


Friends And Related Function Documentation

friend class CallEventManager [friend]

Reimplemented in clang::ento::SimpleFunctionCall.

Definition at line 141 of file CallEvent.h.

friend struct llvm::IntrusiveRefCntPtrInfo [friend]

Definition at line 136 of file CallEvent.h.


Member Data Documentation

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

Definition at line 126 of file CallEvent.h.

Definition at line 131 of file CallEvent.h.


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