clang
7.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 | |
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 | |
CallEvent & | operator= (const CallEvent &)=delete |
virtual | ~CallEvent ()=default |
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... | |
AnalysisDeclContext * | getCalleeAnalysisDeclContext () const |
Returns AnalysisDeclContext for the callee stack frame. More... | |
const StackFrameContext * | getCalleeStackFrame () const |
Returns the callee stack frame. More... | |
const VarRegion * | getParameterLocation (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... | |
Optional< unsigned > | getAdjustedParameterIndex (unsigned ArgumentIndex) const |
Some calls have parameter numbering mismatched from argument numbering. 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 |
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 165 of file CallEvent.h.
Definition at line 378 of file CallEvent.h.
using clang::ento::CallEvent::FrameBindingTy = std::pair<Loc, SVal> |
Definition at line 377 of file CallEvent.h.
Definition at line 167 of file CallEvent.h.
using clang::ento::CallEvent::param_type_iterator = llvm::mapped_iterator<ArrayRef<ParmVarDecl *>::iterator, GetTypeFn> |
Definition at line 463 of file CallEvent.h.
|
protected |
Definition at line 213 of file CallEvent.h.
|
inlineprotected |
Definition at line 194 of file CallEvent.h.
|
inlineprotected |
Definition at line 197 of file CallEvent.h.
|
inlineprotected |
Definition at line 201 of file CallEvent.h.
|
virtualdefault |
|
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 330 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 390 of file CallEvent.h.
CallEventRef<T> clang::ento::CallEvent::cloneWithState | ( | ProgramStateRef | NewState | ) | const |
Definition at line 1138 of file CallEvent.h.
void CallEvent::dump | ( | raw_ostream & | Out | ) | const |
Definition at line 354 of file CallEvent.cpp.
References getState().
LLVM_DUMP_METHOD void CallEvent::dump | ( | ) | const |
Definition at line 352 of file CallEvent.cpp.
|
inline |
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 438 of file CallEvent.h.
References clang::ValueDecl::getType(), and None.
|
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 299 of file CallEvent.h.
Referenced by clang::ento::mpi::MPIChecker::checkMissingWaits(), getNonNullAttrs(), 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 338 of file CallEvent.cpp.
Referenced by getNonNullAttrs(), and updateOutParameter().
|
virtual |
Returns the value of a given argument at the time of the call.
Definition at line 331 of file CallEvent.cpp.
Referenced by clang::ento::mpi::MPIChecker::checkDoubleNonblocking(), clang::ento::mpi::MPIChecker::checkMissingWaits(), clang::ento::ExprEngine::CreateCXXTemporaryObject(), getNonNullAttrs(), GetReturnType(), invalidateRegions(), isNSStringType(), and updateOutParameter().
AnalysisDeclContext * CallEvent::getCalleeAnalysisDeclContext | ( | ) | const |
Returns AnalysisDeclContext for the callee stack frame.
Currently may fail; returns null on failure.
Definition at line 170 of file CallEvent.cpp.
References clang::LocationContext::getAnalysisDeclContext(), clang::AnalysisDeclContextManager::getContext(), getDecl(), clang::AnalysisDeclContext::getManager(), and getRuntimeDefinition().
Referenced by getCalleeStackFrame().
|
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 359 of file CallEvent.h.
Referenced by clang::ento::mpi::MPIChecker::checkDoubleNonblocking(), clang::ento::mpi::MPIChecker::checkMissingWaits(), clang::ento::mpi::MPIChecker::checkUnmatchedWaits(), isCalled(), and isNSStringType().
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 186 of file CallEvent.cpp.
References getCalleeAnalysisDeclContext().
|
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 229 of file CallEvent.h.
Referenced by clang::ento::AnyFunctionCall::argumentsMayEscape(), clang::ento::ExprEngine::CreateCXXTemporaryObject(), clang::ObjCMethodCall::getAccessedProperty(), getCalleeAnalysisDeclContext(), clang::ento::AnyFunctionCall::getDecl(), clang::CXXInstanceCall::getExtraInvalidatedValues(), clang::CXXInstanceCall::getInitialStackFrameContents(), getNonNullAttrs(), 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 378 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 217 of file CallEvent.h.
References getKind().
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(), and REGISTER_TRAIT_WITH_PROGRAMSTATE().
|
inline |
The context in which the call is being evaluated.
Definition at line 239 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(), getNonNullAttrs(), 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 249 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().
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 215 of file CallEvent.cpp.
ProgramPoint CallEvent::getProgramPoint | ( | bool | IsPreVisit = false , |
const ProgramPointTag * | Tag = nullptr |
||
) | const |
Returns an appropriate ProgramPoint for this call.
Definition at line 299 of file CallEvent.cpp.
Referenced by clang::ento::CheckerManager::runCheckersForObjCMessage().
QualType CallEvent::getResultType | ( | ) | const |
Returns the result type, adjusted for references.
Definition at line 70 of file CallEvent.cpp.
References getState().
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 345 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.
Referenced by getCalleeAnalysisDeclContext().
|
inlinevirtual |
Returns a source range for the entire call, suitable for outputting in diagnostics.
Definition at line 290 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 234 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(), getResultType(), clang::ento::AnyFunctionCall::getRuntimeDefinition(), clang::CXXInstanceCall::getRuntimeDefinition(), clang::ObjCMethodCall::getSelfSVal(), invalidateRegions(), and isCalled().
Get the value of arbitrary expressions at this point in the path.
Definition at line 209 of file CallEvent.h.
Referenced by 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 131 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 154 of file CallEvent.cpp.
References hasNonNullArgumentsWithType(), and isCallback().
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().
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 259 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.
|
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 428 of file CallEvent.h.
References clang::ento::ExprEngine::getObjectUnderConstruction().
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 316 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 372 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 162 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 261 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 407 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 470 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(), and getNonNullAttrs().
|
friend |
Definition at line 192 of file CallEvent.h.
|
friend |
Definition at line 184 of file CallEvent.h.
|
protected |
Definition at line 176 of file CallEvent.h.
Referenced by clang::CXXDestructorCall::getCXXThisVal(), clang::CXXConstructorCall::getCXXThisVal(), clang::CXXConstructorCall::getExtraInvalidatedValues(), and clang::ObjCMethodCall::getMessageKind().
|
protected |
Definition at line 181 of file CallEvent.h.