clang
7.0.0
|
#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
Public Member Functions | |
CheckerContext (NodeBuilder &builder, ExprEngine &eng, ExplodedNode *pred, const ProgramPoint &loc, bool wasInlined=false) | |
AnalysisManager & | getAnalysisManager () |
ConstraintManager & | getConstraintManager () |
StoreManager & | getStoreManager () |
ExplodedNode * | getPredecessor () |
Returns the previous node in the exploded graph, which includes the state of the program before the checker ran. More... | |
const ProgramStateRef & | getState () const |
bool | isDifferent () |
Check if the checker changed the state of the execution; ex: added a new transition or a bug report. More... | |
unsigned | blockCount () const |
Returns the number of times the current block has been visited along the analyzed path. More... | |
ASTContext & | getASTContext () |
const LangOptions & | getLangOpts () const |
const LocationContext * | getLocationContext () const |
const StackFrameContext * | getStackFrame () const |
bool | inTopFrame () const |
Return true if the current LocationContext has no caller context. More... | |
BugReporter & | getBugReporter () |
SourceManager & | getSourceManager () |
SValBuilder & | getSValBuilder () |
SymbolManager & | getSymbolManager () |
bool | isObjCGCEnabled () const |
ProgramStateManager & | getStateManager () |
AnalysisDeclContext * | getCurrentAnalysisDeclContext () const |
unsigned | getBlockID () const |
Get the blockID. More... | |
SVal | getSVal (const Stmt *S) const |
Get the value of arbitrary expressions at this point in the path. More... | |
bool | isGreaterOrEqual (const Expr *E, unsigned long long Val) |
Returns true if the value of E is greater than or equal to Val under unsigned comparison. More... | |
bool | isNegative (const Expr *E) |
Returns true if the value of E is negative. More... | |
ExplodedNode * | addTransition (ProgramStateRef State=nullptr, const ProgramPointTag *Tag=nullptr) |
Generates a new transition in the program state graph (ExplodedGraph). More... | |
ExplodedNode * | addTransition (ProgramStateRef State, ExplodedNode *Pred, const ProgramPointTag *Tag=nullptr) |
Generates a new transition with the given predecessor. More... | |
ExplodedNode * | generateSink (ProgramStateRef State, ExplodedNode *Pred, const ProgramPointTag *Tag=nullptr) |
Generate a sink node. More... | |
ExplodedNode * | generateErrorNode (ProgramStateRef State=nullptr, const ProgramPointTag *Tag=nullptr) |
Generate a transition to a node that will be used to report an error. More... | |
ExplodedNode * | generateNonFatalErrorNode (ProgramStateRef State=nullptr, const ProgramPointTag *Tag=nullptr) |
Generate a transition to a node that will be used to report an error. More... | |
void | emitReport (std::unique_ptr< BugReport > R) |
Emit the diagnostics report. More... | |
StringRef | getDeclDescription (const Decl *D) |
Returns the word that should be used to refer to the declaration in the report. More... | |
const FunctionDecl * | getCalleeDecl (const CallExpr *CE) const |
Get the declaration of the called function (path-sensitive). More... | |
StringRef | getCalleeName (const FunctionDecl *FunDecl) const |
Get the name of the called function (path-sensitive). More... | |
const IdentifierInfo * | getCalleeIdentifier (const CallExpr *CE) const |
Get the identifier of the called function (path-sensitive). More... | |
StringRef | getCalleeName (const CallExpr *CE) const |
Get the name of the called function (path-sensitive). More... | |
StringRef | getMacroNameOrSpelling (SourceLocation &Loc) |
Depending on wither the location corresponds to a macro, return either the macro name or the token spelling. More... | |
Static Public Member Functions | |
static const MemRegion * | getLocationRegionIfPostStore (const ExplodedNode *N) |
If the given node corresponds to a PostStore program point, retrieve the location region as it was uttered in the code. More... | |
static bool | isCLibraryFunction (const FunctionDecl *FD, StringRef Name=StringRef()) |
Returns true if the callee is an externally-visible function in the top-level namespace, such as malloc . More... | |
Public Attributes | |
const bool | wasInlined |
If we are post visiting a call, this flag will be set if the call was inlined. More... | |
Definition at line 70 of file CheckerContext.h.
|
inline |
Definition at line 87 of file CheckerContext.h.
References clang::ento::ExplodedNode::getState().
|
inline |
Generates a new transition in the program state graph (ExplodedGraph).
Uses the default CheckerContext predecessor node.
State | The state of the generated node. If not specified, the state will not be changed, but the new node will have the checker's tag. |
Tag | The tag is used to uniquely identify the creation site. If no tag is specified, a default tag, unique to the given checker, will be used. Tags are used to prevent states generated at different sites from caching out. |
Definition at line 215 of file CheckerContext.h.
References getState(), and State.
Referenced by addSelfFlag(), assumeNoOverflow(), clang::ento::mpi::MPIChecker::checkDoubleNonblocking(), checkInvariantViolation(), clang::ento::mpi::MPIChecker::checkMissingWaits(), clang::ento::mpi::MPIChecker::checkUnmatchedWaits(), emitBug(), generateNonFatalErrorNode(), getArgumentValueString(), getAsPointeeSymbol(), GetCFNumberSize(), getNonNullAttrs(), GetReturnType(), getReturnTypeForMethod(), getSimplifiedOffsets(), isDebuggingContext(), isVirtualCall(), recordFixedType(), setFlag(), supportsNilWithFloatRet(), and updateOutParameter().
|
inline |
Generates a new transition with the given predecessor.
Allows checkers to generate a chain of nodes.
State | The state of the generated node. |
Pred | The transition will be generated from the specified Pred node to the newly generated node. |
Tag | The tag to uniquely identify the creation site. |
Definition at line 227 of file CheckerContext.h.
|
inline |
Returns the number of times the current block has been visited along the analyzed path.
Definition at line 126 of file CheckerContext.h.
References clang::ento::NodeBuilderContext::blockCount(), and clang::ento::NodeBuilder::getContext().
Referenced by assumeNoOverflow().
|
inline |
Emit the diagnostics report.
Definition at line 268 of file CheckerContext.h.
References clang::ento::BugReporter::emitReport(), clang::ento::ExprEngine::getBugReporter(), getCalleeDecl(), getCalleeName(), and getDeclDescription().
Referenced by assumeNoOverflow(), describeUninitializedArgumentInCall(), emitBug(), getAsPointeeSymbol(), GetCFNumberSize(), getNonNullAttrs(), getPrintfFormatArgumentNum(), getReturnTypeForMethod(), getSimplifiedOffsets(), isDebuggingContext(), and isVirtualCall().
|
inline |
Generate a transition to a node that will be used to report an error.
This node will be a sink. That is, it will stop exploration of the given path.
State | The state of the generated node. |
Tag | The tag to uniquely identify the creation site. If null, the default tag for the checker will be used. |
Definition at line 248 of file CheckerContext.h.
References generateSink(), clang::ProgramPoint::getTag(), and State.
Referenced by describeUninitializedArgumentInCall(), emitBug(), GetCFNumberSize(), getNonNullAttrs(), getSimplifiedOffsets(), isLeftShiftResultUnrepresentable(), isVirtualCall(), IsZeroByteAllocation(), and supportsNilWithFloatRet().
|
inline |
Generate a transition to a node that will be used to report an error.
This node will not be a sink. That is, exploration will continue along this path.
State | The state of the generated node. |
Tag | The tag to uniquely identify the creation site. If null, the default tag for the checker will be used. |
Definition at line 262 of file CheckerContext.h.
References addTransition(), clang::ProgramPoint::getTag(), and State.
Referenced by assumeNoOverflow(), clang::ento::mpi::MPIChecker::checkDoubleNonblocking(), clang::ento::mpi::MPIChecker::checkMissingWaits(), clang::ento::mpi::MPIChecker::checkUnmatchedWaits(), getArgumentValueString(), getAsPointeeSymbol(), GetCFNumberSize(), getPrintfFormatArgumentNum(), and isVirtualCall().
|
inline |
Generate a sink node.
Generating a sink stops exploration of the given path. To create a sink node for the purpose of reporting an error, checkers should use generateErrorNode() instead.
Definition at line 236 of file CheckerContext.h.
References getState().
Referenced by generateErrorNode(), and getNonNullAttrs().
|
inline |
Definition at line 102 of file CheckerContext.h.
References clang::ento::ExprEngine::getAnalysisManager().
|
inline |
Definition at line 130 of file CheckerContext.h.
References clang::ento::ExprEngine::getContext().
Referenced by assumeNoOverflow(), clang::ento::mpi::MPIChecker::checkMissingWaits(), describeUninitializedArgumentInCall(), clang::ento::mpi::MPIChecker::dynamicInit(), GetAllocationSite(), getArgumentValueString(), getAsPointeeSymbol(), GetCFNumberSize(), getReturnTypeForMethod(), hasDefinition(), isARCNilInitializedLocal(), isDebuggingContext(), isNSStringType(), isShiftOverflow(), recordFixedType(), supportsNilWithFloatRet(), and updateOutParameter().
|
inline |
Get the blockID.
Definition at line 178 of file CheckerContext.h.
References clang::ento::NodeBuilderContext::getBlock(), clang::CFGBlock::getBlockID(), and clang::ento::NodeBuilder::getContext().
|
inline |
Definition at line 149 of file CheckerContext.h.
References clang::ento::ExprEngine::getBugReporter().
Referenced by clang::ento::mpi::MPIChecker::checkDoubleNonblocking(), checkInvariantViolation(), clang::ento::mpi::MPIChecker::checkMissingWaits(), clang::ento::mpi::MPIChecker::checkUnmatchedWaits(), getArgumentValueString(), getNonNullAttrs(), and getSourceManager().
const FunctionDecl * CheckerContext::getCalleeDecl | ( | const CallExpr * | CE | ) | const |
Get the declaration of the called function (path-sensitive).
Definition at line 22 of file CheckerContext.cpp.
References clang::ento::SVal::getAsFunctionDecl(), clang::CallExpr::getCallee(), and clang::ento::ExplodedNode::getSVal().
Referenced by emitReport(), getAsPointeeSymbol(), getCalleeIdentifier(), getCalleeName(), GetCFNumberSize(), and getPrintfFormatArgumentNum().
|
inline |
Get the identifier of the called function (path-sensitive).
Definition at line 284 of file CheckerContext.h.
References getCalleeDecl(), and clang::NamedDecl::getIdentifier().
StringRef CheckerContext::getCalleeName | ( | const FunctionDecl * | FunDecl | ) | const |
Get the name of the called function (path-sensitive).
Definition at line 28 of file CheckerContext.cpp.
References clang::NamedDecl::getIdentifier(), and clang::IdentifierInfo::getName().
Referenced by emitReport(), getAsPointeeSymbol(), getCalleeName(), getPrintfFormatArgumentNum(), and isLeftShiftResultUnrepresentable().
|
inline |
Get the name of the called function (path-sensitive).
Definition at line 293 of file CheckerContext.h.
References getCalleeDecl(), getCalleeName(), and isCLibraryFunction().
|
inline |
Definition at line 106 of file CheckerContext.h.
References clang::ento::ExprEngine::getConstraintManager().
Referenced by getNonNullAttrs().
|
inline |
Definition at line 173 of file CheckerContext.h.
References clang::LocationContext::getAnalysisDeclContext(), and clang::ento::ExplodedNode::getLocationContext().
Referenced by isDebuggingContext(), and isSelfVar().
StringRef CheckerContext::getDeclDescription | ( | const Decl * | D | ) |
Returns the word that should be used to refer to the declaration in the report.
Definition at line 37 of file CheckerContext.cpp.
Referenced by emitReport().
|
inline |
Definition at line 134 of file CheckerContext.h.
References clang::ento::ExprEngine::getContext(), and clang::ASTContext::getLangOpts().
Referenced by getMacroNameOrSpelling(), and getReturnTypeForMethod().
|
inline |
Definition at line 138 of file CheckerContext.h.
References clang::ento::ExplodedNode::getLocationContext().
Referenced by assumeNoOverflow(), checkElementNonNil(), checkInvariantViolation(), GetAllocationSite(), getArgumentValueString(), getAsPointeeSymbol(), getPrintfFormatArgumentNum(), inTopFrame(), isCalledByConstructor(), isVirtualCall(), recordFixedType(), and supportsNilWithFloatRet().
|
inlinestatic |
If the given node corresponds to a PostStore program point, retrieve the location region as it was uttered in the code.
This utility can be useful for generating extensive diagnostics, for example, for finding variables that the given symbol was assigned to.
Definition at line 187 of file CheckerContext.h.
References clang::ProgramPoint::getAs(), and clang::ento::ExplodedNode::getLocation().
StringRef CheckerContext::getMacroNameOrSpelling | ( | SourceLocation & | Loc | ) |
Depending on wither the location corresponds to a macro, return either the macro name or the token spelling.
This could be useful when checkers' logic depends on whether a function is called with a given macro argument. For example: s = socket(AF_INET,..) If AF_INET is a macro, the result should be treated as a source of taint.
Definition at line 93 of file CheckerContext.cpp.
References clang::Lexer::getImmediateMacroName(), getLangOpts(), getSourceManager(), clang::Lexer::getSpelling(), and clang::SourceLocation::isMacroID().
|
inline |
Returns the previous node in the exploded graph, which includes the state of the program before the checker ran.
Note, checkers should not retain the node in their state since the nodes might get invalidated.
Definition at line 117 of file CheckerContext.h.
Referenced by getArgumentValueString(), getNonNullAttrs(), getReturnTypeForMethod(), isDebuggingContext(), recordFixedType(), and updateOutParameter().
|
inline |
Definition at line 153 of file CheckerContext.h.
References getBugReporter(), and clang::ento::BugReporter::getSourceManager().
Referenced by GetAllocationSite(), getAsPointeeSymbol(), and getMacroNameOrSpelling().
|
inline |
Definition at line 142 of file CheckerContext.h.
References clang::ento::ExplodedNode::getStackFrame().
Referenced by getObjectVal(), isLeftShiftResultUnrepresentable(), parameterTypeFromSVal(), and recordFixedType().
|
inline |
Definition at line 118 of file CheckerContext.h.
References clang::ento::ExplodedNode::getState().
Referenced by addTransition(), assumeNoOverflow(), clang::ento::mpi::MPIChecker::checkDoubleNonblocking(), checkInvariantViolation(), clang::ento::mpi::MPIChecker::checkMissingWaits(), clang::ento::mpi::MPIChecker::checkUnmatchedWaits(), describeUninitializedArgumentInCall(), emitBug(), generateSink(), getArgumentValueString(), getAsPointeeSymbol(), GetCFNumberSize(), getNonNullAttrs(), getObjectVal(), getPrintfFormatArgumentNum(), getReceiverNullability(), GetReturnType(), getReturnTypeForMethod(), getSelfFlags(), getSimplifiedOffsets(), hasDefinition(), isArrayIndexOutOfBounds(), isDebuggingContext(), isLeaked(), isLeftShiftResultUnrepresentable(), isVirtualCall(), recordFixedType(), and updateOutParameter().
|
inline |
Definition at line 169 of file CheckerContext.h.
References clang::ento::ExprEngine::getStateManager().
Referenced by GetAllocationSite().
|
inline |
Definition at line 110 of file CheckerContext.h.
References clang::ento::ExprEngine::getStoreManager().
Referenced by clang::ento::mpi::MPIChecker::checkMissingWaits(), getAsPointeeSymbol(), and isArrayIndexOutOfBounds().
Get the value of arbitrary expressions at this point in the path.
Definition at line 195 of file CheckerContext.h.
Referenced by assumeCollectionNonEmpty(), checkCollectionNonNil(), getArgumentValueString(), getAsPointeeSymbol(), GetCFNumberSize(), getPrintfFormatArgumentNum(), hasDefinition(), isArrayIndexOutOfBounds(), isLeftShiftResultUnrepresentable(), isNSStringType(), and recordFixedType().
|
inline |
Definition at line 157 of file CheckerContext.h.
References clang::ento::ExprEngine::getSValBuilder().
Referenced by assumeCollectionNonEmpty(), assumeNoOverflow(), clang::ento::mpi::MPIChecker::checkMissingWaits(), getArgumentValueString(), GetCFNumberSize(), getObjectVal(), getSimplifiedOffsets(), getSymbolManager(), isLeftShiftResultUnrepresentable(), isVirtualCall(), and supportsNilWithFloatRet().
|
inline |
Definition at line 161 of file CheckerContext.h.
References getSValBuilder(), and clang::ento::SValBuilder::getSymbolManager().
Referenced by assumeNoOverflow(), and getAsPointeeSymbol().
|
inline |
Return true if the current LocationContext has no caller context.
Definition at line 147 of file CheckerContext.h.
References getLocationContext(), and clang::LocationContext::inTopFrame().
|
static |
Returns true if the callee is an externally-visible function in the top-level namespace, such as malloc
.
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 45 of file CheckerContext.cpp.
Referenced by getCalleeName(), and clang::ento::CallEvent::isGlobalCFunction().
|
inline |
Check if the checker changed the state of the execution; ex: added a new transition or a bug report.
Definition at line 122 of file CheckerContext.h.
Returns true if the value of E
is greater than or equal to Val
under unsigned comparison.
Definition at line 124 of file CheckerContext.cpp.
Referenced by isShiftOverflow().
Returns true if the value of E
is negative.
Definition at line 129 of file CheckerContext.cpp.
Referenced by isLeftShiftResultUnrepresentable().
|
inline |
Definition at line 165 of file CheckerContext.h.
References clang::ento::ExprEngine::isObjCGCEnabled().
Referenced by GetAllocationSite().
const bool clang::ento::CheckerContext::wasInlined |
If we are post visiting a call, this flag will be set if the call was inlined.
In all other cases it will be false.
Definition at line 85 of file CheckerContext.h.