clang
8.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 () |
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 24 of file CheckerContext.h.
|
inline |
Definition at line 41 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 165 of file CheckerContext.h.
References getState(), and State.
Referenced by clang::ento::retaincountchecker::RetainCountChecker::checkBeginFunction(), clang::ento::retaincountchecker::RetainCountChecker::checkBind(), clang::ento::retaincountchecker::RetainCountChecker::checkDeadSymbols(), clang::ento::mpi::MPIChecker::checkDoubleNonblocking(), clang::ento::mpi::MPIChecker::checkMissingWaits(), clang::ento::retaincountchecker::RetainCountChecker::checkPostStmt(), clang::ento::retaincountchecker::RetainCountChecker::checkReturnWithRetEffect(), clang::ento::retaincountchecker::RetainCountChecker::checkSummary(), clang::ento::mpi::MPIChecker::checkUnmatchedWaits(), clang::ento::retaincountchecker::RetainCountChecker::evalCall(), generateNonFatalErrorNode(), clang::ento::retaincountchecker::RetainCountChecker::processLeaks(), clang::ento::retaincountchecker::RetainCountChecker::processObjCLiterals(), and clang::ento::retaincountchecker::RetainCountChecker::processSummaryOfInlined().
|
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 177 of file CheckerContext.h.
|
inline |
Returns the number of times the current block has been visited along the analyzed path.
Definition at line 80 of file CheckerContext.h.
References clang::ento::NodeBuilderContext::blockCount(), and clang::ento::NodeBuilder::getContext().
Referenced by clang::ento::retaincountchecker::RetainCountChecker::evalCall().
|
inline |
Emit the diagnostics report.
Definition at line 218 of file CheckerContext.h.
References clang::ento::BugReporter::emitReport(), clang::ento::ExprEngine::getBugReporter(), getCalleeDecl(), getCalleeName(), and getDeclDescription().
Referenced by clang::ento::retaincountchecker::RetainCountChecker::checkReturnWithRetEffect(), clang::ento::retaincountchecker::RetainCountChecker::handleAutoreleaseCounts(), clang::ento::retaincountchecker::RetainCountChecker::processLeaks(), and clang::ento::retaincountchecker::RetainCountChecker::processNonLeakError().
|
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 198 of file CheckerContext.h.
References generateSink(), clang::ProgramPoint::getTag(), and State.
Referenced by clang::ento::retaincountchecker::RetainCountChecker::processNonLeakError().
|
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 212 of file CheckerContext.h.
References addTransition(), clang::ProgramPoint::getTag(), and State.
Referenced by clang::ento::mpi::MPIChecker::checkDoubleNonblocking(), clang::ento::mpi::MPIChecker::checkMissingWaits(), and clang::ento::mpi::MPIChecker::checkUnmatchedWaits().
|
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 186 of file CheckerContext.h.
References getState().
Referenced by generateErrorNode(), and clang::ento::retaincountchecker::RetainCountChecker::handleAutoreleaseCounts().
|
inline |
Definition at line 56 of file CheckerContext.h.
References clang::ento::ExprEngine::getAnalysisManager().
|
inline |
Definition at line 84 of file CheckerContext.h.
References clang::ento::ExprEngine::getContext().
Referenced by clang::ento::mpi::MPIChecker::checkMissingWaits(), clang::ento::retaincountchecker::RetainCountChecker::checkReturnWithRetEffect(), clang::ento::retaincountchecker::RetainCountChecker::checkSummary(), clang::ento::mpi::MPIChecker::dynamicInit(), clang::ento::retaincountchecker::RetainCountChecker::evalCall(), clang::ento::retaincountchecker::RetainCountChecker::getSummaryManager(), clang::ento::retaincountchecker::RetainCountChecker::handleAutoreleaseCounts(), isGreaterOrEqual(), clang::ento::retaincountchecker::RetainCountChecker::processLeaks(), clang::ento::retaincountchecker::RetainCountChecker::processNonLeakError(), and clang::ento::retaincountchecker::RetainCountChecker::updateSymbol().
|
inline |
Get the blockID.
Definition at line 128 of file CheckerContext.h.
References clang::ento::NodeBuilderContext::getBlock(), clang::CFGBlock::getBlockID(), and clang::ento::NodeBuilder::getContext().
|
inline |
Definition at line 103 of file CheckerContext.h.
References clang::ento::ExprEngine::getBugReporter().
Referenced by clang::ento::mpi::MPIChecker::checkDoubleNonblocking(), clang::ento::mpi::MPIChecker::checkMissingWaits(), clang::ento::mpi::MPIChecker::checkUnmatchedWaits(), 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(), clang::ento::retaincountchecker::RetainCountChecker::evalCall(), getCalleeIdentifier(), and getCalleeName().
|
inline |
Get the identifier of the called function (path-sensitive).
Definition at line 234 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(), and getCalleeName().
|
inline |
Get the name of the called function (path-sensitive).
Definition at line 243 of file CheckerContext.h.
References getCalleeDecl(), getCalleeName(), and isCLibraryFunction().
|
inline |
Definition at line 60 of file CheckerContext.h.
References clang::ento::ExprEngine::getConstraintManager().
|
inline |
Definition at line 123 of file CheckerContext.h.
References clang::LocationContext::getAnalysisDeclContext(), and clang::ento::ExplodedNode::getLocationContext().
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 88 of file CheckerContext.h.
References clang::ento::ExprEngine::getContext(), and clang::ASTContext::getLangOpts().
Referenced by getMacroNameOrSpelling().
|
inline |
Definition at line 92 of file CheckerContext.h.
References clang::ento::ExplodedNode::getLocationContext().
Referenced by clang::ento::retaincountchecker::RetainCountChecker::checkBeginFunction(), clang::ento::retaincountchecker::RetainCountChecker::checkPostStmt(), clang::ento::retaincountchecker::RetainCountChecker::evalCall(), inTopFrame(), and willObjectBeAnalyzedLater().
|
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 137 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 71 of file CheckerContext.h.
Referenced by clang::ento::retaincountchecker::RetainCountChecker::checkDeadSymbols(), clang::ento::retaincountchecker::RetainCountChecker::checkPostStmt(), clang::ento::retaincountchecker::RetainCountChecker::checkSummary(), and clang::ento::retaincountchecker::RetainCountChecker::processObjCLiterals().
|
inline |
Definition at line 107 of file CheckerContext.h.
References getBugReporter(), and clang::ento::BugReporter::getSourceManager().
Referenced by getMacroNameOrSpelling().
|
inline |
Definition at line 96 of file CheckerContext.h.
References clang::ento::ExplodedNode::getStackFrame().
Referenced by clang::ento::retaincountchecker::RetainCountChecker::checkPostStmt(), and getConstructedRegion().
|
inline |
Definition at line 72 of file CheckerContext.h.
References clang::ento::ExplodedNode::getState().
Referenced by addTransition(), clang::ento::retaincountchecker::RetainCountChecker::checkBeginFunction(), clang::ento::retaincountchecker::RetainCountChecker::checkBind(), clang::ento::retaincountchecker::RetainCountChecker::checkDeadSymbols(), clang::ento::mpi::MPIChecker::checkDoubleNonblocking(), clang::ento::mpi::MPIChecker::checkMissingWaits(), clang::ento::retaincountchecker::RetainCountChecker::checkPostCall(), clang::ento::retaincountchecker::RetainCountChecker::checkPostStmt(), clang::ento::retaincountchecker::RetainCountChecker::checkSummary(), clang::ento::mpi::MPIChecker::checkUnmatchedWaits(), clang::ento::retaincountchecker::RetainCountChecker::evalCall(), generateSink(), getConstructedRegion(), isGreaterOrEqual(), isNegative(), clang::ento::retaincountchecker::RetainCountChecker::processObjCLiterals(), and clang::ento::retaincountchecker::RetainCountChecker::processSummaryOfInlined().
|
inline |
Definition at line 119 of file CheckerContext.h.
References clang::ento::ExprEngine::getStateManager().
|
inline |
Definition at line 64 of file CheckerContext.h.
References clang::ento::ExprEngine::getStoreManager().
Referenced by clang::ento::mpi::MPIChecker::checkMissingWaits().
Get the value of arbitrary expressions at this point in the path.
Definition at line 145 of file CheckerContext.h.
Referenced by clang::ento::retaincountchecker::RetainCountChecker::checkPostStmt(), isGreaterOrEqual(), and isNegative().
|
inline |
Definition at line 111 of file CheckerContext.h.
References clang::ento::ExprEngine::getSValBuilder().
Referenced by clang::ento::mpi::MPIChecker::checkMissingWaits(), clang::ento::retaincountchecker::RetainCountChecker::checkPostStmt(), clang::ento::retaincountchecker::RetainCountChecker::evalCall(), getConstructedRegion(), getSymbolManager(), isGreaterOrEqual(), and isNegative().
|
inline |
Definition at line 115 of file CheckerContext.h.
References getSValBuilder(), and clang::ento::SValBuilder::getSymbolManager().
|
inline |
Return true if the current LocationContext has no caller context.
Definition at line 101 of file CheckerContext.h.
References getLocationContext(), and clang::LocationContext::inTopFrame().
Referenced by clang::ento::retaincountchecker::RetainCountChecker::checkBeginFunction().
|
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 76 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.
References evalComparison(), getASTContext(), getState(), getSVal(), getSValBuilder(), and clang::ento::SValBuilder::makeIntVal().
Returns true if the value of E
is negative.
Definition at line 129 of file CheckerContext.cpp.
References evalComparison(), getState(), getSVal(), getSValBuilder(), and clang::ento::SValBuilder::makeIntVal().
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 39 of file CheckerContext.h.
Referenced by clang::ento::retaincountchecker::RetainCountChecker::checkPostCall().