clang
6.0.0
|
Represents an abstract call to a function or method along a particular path. More...
#include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h"
Public Types | |
typedef CallEventKind | Kind |
typedef std::pair< Loc, SVal > | FrameBindingTy |
typedef SmallVectorImpl< FrameBindingTy > | BindingsTy |
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 Decl * | getDecl () const |
Returns the declaration of the function or method that will be called. More... | |
const ProgramStateRef & | getState () const |
The state in which the call is being evaluated. More... | |
const LocationContext * | getLocationContext () 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 Expr * | getOriginExpr () 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 Expr * | getArgExpr (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 IdentifierInfo * | getCalleeIdentifier () 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... | |
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 | |
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. 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 |
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.
Definition at line 354 of file CallEvent.h.
typedef std::pair<Loc, SVal> clang::ento::CallEvent::FrameBindingTy |
Definition at line 353 of file CallEvent.h.
Definition at line 142 of file CallEvent.h.
typedef llvm::mapped_iterator<ArrayRef<ParmVarDecl*>::iterator, GetTypeFn> clang::ento::CallEvent::param_type_iterator |
Definition at line 399 of file CallEvent.h.
|
protected |
Definition at line 190 of file CallEvent.h.
|
inlineprotected |
Definition at line 170 of file CallEvent.h.
|
inlineprotected |
Definition at line 173 of file CallEvent.h.
|
inlineprotected |
Definition at line 177 of file CallEvent.h.
|
inlinevirtual |
Definition at line 198 of file CallEvent.h.
References getKind().
|
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().
|
protectedpure virtual |
Copies this CallEvent, with vtable intact, into a new block of memory.
Implemented in clang::ento::SimpleFunctionCall.
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().
|
inline |
Returns a copy of this CallEvent, but using the given state.
Definition at line 366 of file CallEvent.h.
CallEventRef<T> clang::ento::CallEvent::cloneWithState | ( | ProgramStateRef | NewState | ) | const |
Definition at line 1072 of file CallEvent.h.
void CallEvent::dump | ( | raw_ostream & | Out | ) | const |
Definition at line 251 of file CallEvent.cpp.
References getState().
LLVM_DUMP_METHOD void CallEvent::dump | ( | ) | const |
Definition at line 249 of file CallEvent.cpp.
|
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(), getArgSVal(), and isDebuggingContext().
|
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 235 of file CallEvent.cpp.
References getArgExpr(), and clang::Stmt::getSourceRange().
Referenced by updateOutParameter().
|
virtual |
Returns the value of a given argument at the time of the call.
Definition at line 228 of file CallEvent.cpp.
References getArgExpr(), and getSVal().
Referenced by clang::ento::mpi::MPIChecker::checkDoubleNonblocking(), clang::ento::mpi::MPIChecker::checkMissingWaits(), clang::ento::ExprEngine::CreateCXXTemporaryObject(), GetReturnType(), invalidateRegions(), isNSStringType(), and updateOutParameter().
|
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.
References clang::NamedDecl::getIdentifier().
Referenced by clang::ento::mpi::MPIChecker::checkDoubleNonblocking(), clang::ento::mpi::MPIChecker::checkMissingWaits(), clang::ento::mpi::MPIChecker::checkUnmatchedWaits(), isCalled(), and isNSStringType().
|
inlinevirtual |
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 205 of file CallEvent.h.
Referenced by clang::ento::AnyFunctionCall::argumentsMayEscape(), clang::ento::ExprEngine::CreateCXXTemporaryObject(), clang::ObjCMethodCall::getAccessedProperty(), clang::ento::AnyFunctionCall::getDecl(), clang::CXXInstanceCall::getExtraInvalidatedValues(), clang::CXXInstanceCall::getInitialStackFrameContents(), clang::ento::AnyFunctionCall::getRuntimeDefinition(), clang::CXXInstanceCall::getRuntimeDefinition(), hasNonNullArgumentsWithType(), invalidateRegions(), isGlobalCFunction(), isNSStringType(), isVirtualCall(), clang::ento::AnyFunctionCall::parameters(), clang::BlockCall::parameters(), and clang::ObjCMethodCall::parameters().
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 276 of file CallEvent.cpp.
References clang::Type::getAs(), and clang::Type::isDependentType().
Referenced by clang::ento::ExprEngine::processCallExit().
|
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().
|
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().
|
pure virtual |
Returns the kind of call this is.
Implemented in clang::ento::SimpleFunctionCall.
Referenced by clang::ento::AnyFunctionCall::classof(), clang::ento::SimpleFunctionCall::classof(), describeUninitializedArgumentInCall(), isCalled(), mayInlineCallKind(), and REGISTER_TRAIT_WITH_PROGRAMSTATE().
|
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().
|
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().
|
inline |
Returns the expression whose value will be the result of this call.
May be null.
Definition at line 225 of file CallEvent.h.
Referenced by clang::ento::ExprEngine::CreateCXXTemporaryObject(), clang::BlockCall::getBlockRegion(), clang::CXXMemberCall::getCXXThisExpr(), clang::CXXMemberOperatorCall::getCXXThisExpr(), clang::ento::SimpleFunctionCall::getDecl(), clang::CXXInstanceCall::getDecl(), clang::ento::SimpleFunctionCall::getOriginExpr(), clang::BlockCall::getOriginExpr(), clang::CXXConstructorCall::getOriginExpr(), clang::CXXAllocatorCall::getOriginExpr(), clang::ObjCMethodCall::getOriginExpr(), clang::ObjCMethodCall::getReceiverSVal(), clang::CXXMemberCall::getRuntimeDefinition(), clang::ObjCMethodCall::getSourceRange(), invalidateRegions(), isNSStringType(), clang::ObjCMethodCall::isReceiverSelfOrSuper(), isVirtualCall(), REGISTER_TRAIT_WITH_PROGRAMSTATE(), clang::ento::CheckerManager::runCheckersForEvalCall(), and updateOutParameter().
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().
QualType CallEvent::getResultType | ( | ) | const |
Returns the result type, adjusted for references.
Definition at line 31 of file CallEvent.cpp.
Referenced by isNSStringType(), and updateOutParameter().
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 242 of file CallEvent.cpp.
Referenced by GetReturnType(), isNSStringType(), recordFixedType(), and updateOutParameter().
|
pure virtual |
Returns the definition of the function or method that will be called.
Implemented in clang::ento::AnyFunctionCall.
|
inlinevirtual |
Returns a source range for the entire call, suitable for outputting in diagnostics.
Definition at line 266 of file CallEvent.h.
Referenced by isDebuggingContext(), clang::ento::mpi::MPIBugReporter::reportDoubleNonblocking(), and clang::ento::mpi::MPIBugReporter::reportUnmatchedWait().
|
inline |
The state in which the call is being evaluated.
Definition at line 210 of file CallEvent.h.
References State.
Referenced by clang::ObjCMethodCall::canBeOverridenInSubclass(), dump(), clang::ObjCMethodCall::getExtraInvalidatedValues(), clang::ento::AnyFunctionCall::getInitialStackFrameContents(), clang::BlockCall::getInitialStackFrameContents(), clang::CXXInstanceCall::getInitialStackFrameContents(), clang::CXXConstructorCall::getInitialStackFrameContents(), clang::ObjCMethodCall::getInitialStackFrameContents(), clang::CXXInstanceCall::getRuntimeDefinition(), clang::ObjCMethodCall::getSelfSVal(), invalidateRegions(), and isCalled().
Get the value of arbitrary expressions at this point in the path.
Definition at line 185 of file CallEvent.h.
Referenced by getArgSVal(), clang::BlockCall::getBlockRegion(), clang::CXXInstanceCall::getCXXThisVal(), clang::ento::SimpleFunctionCall::getDecl(), clang::CXXInstanceCall::getDecl(), clang::ObjCMethodCall::getReceiverSVal(), and clang::ObjCMethodCall::isReceiverSelfOrSuper().
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().
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().
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().
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 156 of file CallEvent.cpp.
References argumentsMayEscape(), findPtrToConstParams(), getArgSVal(), clang::ento::SVal::getAsRegion(), getDecl(), getExtraInvalidatedValues(), getLocationContext(), getNumArgs(), getOriginExpr(), getState(), clang::ento::RegionAndSymbolInvalidationTraits::setTrait(), and clang::ento::RegionAndSymbolInvalidationTraits::TK_PreserveContents.
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.
Returns true if this is a statement is a function or method call of some kind.
Definition at line 270 of file CallEvent.cpp.
Referenced by clang::ento::ExplodedGraph::isInterestingLValueExpr().
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().
|
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().
Returns true if the given decl is known to be variadic.
D
must not be null.
Definition at line 305 of file CallEvent.cpp.
Referenced by mayInlineDecl().
|
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.
|
inline |
|
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().
|
friend |
Definition at line 168 of file CallEvent.h.
|
friend |
Definition at line 163 of file CallEvent.h.
|
protected |
Definition at line 153 of file CallEvent.h.
Referenced by clang::CXXDestructorCall::getCXXThisVal(), clang::CXXConstructorCall::getCXXThisVal(), clang::CXXConstructorCall::getExtraInvalidatedValues(), and clang::ObjCMethodCall::getMessageKind().
|
protected |
Definition at line 158 of file CallEvent.h.