clang API Documentation
Represents an abstract call to a function or method along a particular path. More...
#include <CallEvent.h>
Public Types | |
typedef CallEventKind | Kind |
typedef std::pair< Loc, SVal > | FrameBindingTy |
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 Decl * | getDecl () const |
Returns the declaration of the function or method that will be called. May be null. | |
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. | |
virtual RuntimeDefinition | getRuntimeDefinition () const =0 |
Returns the definition of the function or method that will be called. | |
const Expr * | getOriginExpr () 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 Expr * | getArgExpr (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 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 |
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< SVal > | ValueList |
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 |
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.
typedef SmallVectorImpl<FrameBindingTy> clang::ento::CallEvent::BindingsTy |
Definition at line 312 of file CallEvent.h.
typedef std::pair<Loc, SVal> clang::ento::CallEvent::FrameBindingTy |
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.
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.
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().
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().
CallEventRef clang::ento::CallEvent::cloneWithState | ( | ProgramStateRef | NewState | ) | const [inline] |
Returns a copy of this CallEvent, but using the given state.
Definition at line 324 of file CallEvent.h.
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 |
Definition at line 218 of file CallEvent.cpp.
References getDecl(), getKind(), getOriginExpr(), clang::ASTContext::getPrintingPolicy(), and getState().
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().
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 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().
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 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().
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 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] |
Returns the kind of call this is.
Implemented in clang::ento::SimpleFunctionCall.
Referenced by clang::ento::AnyFunctionCall::classof(), clang::ento::SimpleFunctionCall::classof(), cloneWithState(), describeUninitializedArgumentInCall(), dump(), and mayInlineCallKind().
const LocationContext* clang::ento::CallEvent::getLocationContext | ( | ) | const [inline] |
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] |
Returns the expression whose value will be the result of this call. May be null.
Reimplemented in clang::ento::SimpleFunctionCall.
Definition at line 197 of file CallEvent.h.
Referenced by clang::ento::ExprEngine::bindReturnValue(), dump(), clang::BlockCall::getOriginExpr(), clang::CXXConstructorCall::getOriginExpr(), clang::CXXAllocatorCall::getOriginExpr(), clang::ObjCMethodCall::getOriginExpr(), getProgramPoint(), getResultType(), getReturnValue(), getSourceRange(), invalidateRegions(), and clang::ento::CheckerManager::runCheckersForEvalCall().
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().
QualType CallEvent::getResultType | ( | ) | const |
Returns the result type, adjusted for references.
Definition at line 27 of file CallEvent.cpp.
References clang::ASTContext::getLValueReferenceType(), getOriginExpr(), clang::ASTContext::getRValueReferenceType(), getState(), clang::Expr::getType(), clang::Expr::getValueKind(), clang::VK_LValue, clang::VK_RValue, and clang::VK_XValue.
Referenced by clang::ento::ExprEngine::bindReturnValue().
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 209 of file CallEvent.cpp.
References getOriginExpr(), and getSVal().
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.
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().
const ProgramStateRef& clang::ento::CallEvent::getState | ( | ) | const [inline] |
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().
bool CallEvent::hasNonZeroCallbackArg | ( | ) | const |
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 |
Returns a new state with all argument regions invalidated.
This accepts an alternate state in case some processing has already occurred.
Definition at line 138 of file CallEvent.cpp.
References argumentsMayEscape(), clang::LangAS::Count, findPtrToConstParams(), getArgSVal(), clang::ento::SVal::getAsRegion(), getDecl(), getExtraInvalidatedValues(), getLocationContext(), getNumArgs(), getOriginExpr(), getState(), clang::ento::RegionAndSymbolInvalidationTraits::setTrait(), and clang::ento::RegionAndSymbolInvalidationTraits::TK_PreserveContents.
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().
bool clang::ento::CallEvent::isInSystemHeader | ( | ) | const [inline] |
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().
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 362 of file CallEvent.h.
References clang::ValueDecl::getType(), and parameters().
Referenced by findPtrToConstParams(), and hasNonZeroCallbackArg().
param_type_iterator clang::ento::CallEvent::param_type_end | ( | ) | const [inline] |
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().
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.
const void* clang::ento::CallEvent::Data [protected] |
Definition at line 126 of file CallEvent.h.
SourceLocation clang::ento::CallEvent::Location [protected] |
Definition at line 131 of file CallEvent.h.