clang 8.0.0

Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
clang::ento::CheckerContext Class Reference

`#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"`

Collaboration diagram for clang::ento::CheckerContext:
[legend]

## 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...

## Detailed Description

Definition at line 24 of file CheckerContext.h.

## Constructor & Destructor Documentation

## ◆ CheckerContext()

clang::ento::CheckerContext::CheckerContext | ( | NodeBuilder & | builder,
|  | ExprEngine & | eng,
|  | ExplodedNode * | pred,
|  | const ProgramPoint & | loc,
|  | bool | wasInlined = `false`
| ) |  |
| inline

Definition at line 41 of file CheckerContext.h.

References clang::ento::ExplodedNode::getState().

## Member Function Documentation

## ◆ addTransition() [1/2]

ExplodedNode* clang::ento::CheckerContext::addTransition | ( | ProgramStateRef | State = `nullptr`,
|  | const ProgramPointTag * | Tag = `nullptr`
| ) |  |
| inline

Generates a new transition in the program state graph (ExplodedGraph).

Uses the default CheckerContext predecessor node.

Parameters

  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().

## ◆ addTransition() [2/2]

ExplodedNode* clang::ento::CheckerContext::addTransition | ( | ProgramStateRef | State,
|  | ExplodedNode * | Pred,
|  | const ProgramPointTag * | Tag = `nullptr`
| ) |  |
| inline

Generates a new transition with the given predecessor.

Allows checkers to generate a chain of nodes.

Parameters

  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.

## ◆ blockCount()

unsigned clang::ento::CheckerContext::blockCount | ( |  | ) | const
| 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().

## ◆ emitReport()

void clang::ento::CheckerContext::emitReport | ( | std::unique_ptr< BugReport > | R | ) |
| 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().

## ◆ generateErrorNode()

ExplodedNode* clang::ento::CheckerContext::generateErrorNode | ( | ProgramStateRef | State = `nullptr`,
|  | const ProgramPointTag * | Tag = `nullptr`
| ) |  |
| 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.

Parameters

  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().

## ◆ generateNonFatalErrorNode()

ExplodedNode* clang::ento::CheckerContext::generateNonFatalErrorNode | ( | ProgramStateRef | State = `nullptr`,
|  | const ProgramPointTag * | Tag = `nullptr`
| ) |  |
| 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.

Parameters

  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().

## ◆ generateSink()

ExplodedNode* clang::ento::CheckerContext::generateSink | ( | ProgramStateRef | State,
|  | ExplodedNode * | Pred,
|  | const ProgramPointTag * | Tag = `nullptr`
| ) |  |
| 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().

## ◆ getAnalysisManager()

AnalysisManager& clang::ento::CheckerContext::getAnalysisManager | ( |  | ) |
| inline

Definition at line 56 of file CheckerContext.h.

References clang::ento::ExprEngine::getAnalysisManager().

## ◆ getASTContext()

ASTContext& clang::ento::CheckerContext::getASTContext | ( |  | ) |
| 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().

## ◆ getBlockID()

unsigned clang::ento::CheckerContext::getBlockID | ( |  | ) | const
| 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().

## ◆ getBugReporter()

BugReporter& clang::ento::CheckerContext::getBugReporter | ( |  | ) |
| 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().

## ◆ getCalleeDecl()

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().

## ◆ getCalleeIdentifier()

const IdentifierInfo* clang::ento::CheckerContext::getCalleeIdentifier | ( | const CallExpr * | CE | ) | const
| inline

Get the identifier of the called function (path-sensitive).

Definition at line 234 of file CheckerContext.h.

References getCalleeDecl(), and clang::NamedDecl::getIdentifier().

## ◆ getCalleeName() [1/2]

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().

## ◆ getCalleeName() [2/2]

StringRef clang::ento::CheckerContext::getCalleeName | ( | const CallExpr * | CE | ) | const
| inline

Get the name of the called function (path-sensitive).

Definition at line 243 of file CheckerContext.h.

References getCalleeDecl(), getCalleeName(), and isCLibraryFunction().

## ◆ getConstraintManager()

ConstraintManager& clang::ento::CheckerContext::getConstraintManager | ( |  | ) |
| inline

Definition at line 60 of file CheckerContext.h.

References clang::ento::ExprEngine::getConstraintManager().

## ◆ getCurrentAnalysisDeclContext()

AnalysisDeclContext* clang::ento::CheckerContext::getCurrentAnalysisDeclContext | ( |  | ) | const
| inline

Definition at line 123 of file CheckerContext.h.

References clang::LocationContext::getAnalysisDeclContext(), and clang::ento::ExplodedNode::getLocationContext().

## ◆ getDeclDescription()

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().

## ◆ getLangOpts()

const LangOptions& clang::ento::CheckerContext::getLangOpts | ( |  | ) | const
| inline

Definition at line 88 of file CheckerContext.h.

References clang::ento::ExprEngine::getContext(), and clang::ASTContext::getLangOpts().

Referenced by getMacroNameOrSpelling().

## ◆ getLocationContext()

const LocationContext* clang::ento::CheckerContext::getLocationContext | ( |  | ) | const
| 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().

## ◆ getLocationRegionIfPostStore()

static const MemRegion* clang::ento::CheckerContext::getLocationRegionIfPostStore | ( | const ExplodedNode * | N | ) |
| inline static

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().

## ◆ getMacroNameOrSpelling()

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.

See also
  clang::Lexer::getSpelling(), clang::Lexer::getImmediateMacroName().

Definition at line 93 of file CheckerContext.cpp.

References clang::Lexer::getImmediateMacroName(), getLangOpts(), getSourceManager(), clang::Lexer::getSpelling(), and clang::SourceLocation::isMacroID().

## ◆ getPredecessor()

ExplodedNode* clang::ento::CheckerContext::getPredecessor | ( |  | ) |
| 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().

## ◆ getSourceManager()

SourceManager& clang::ento::CheckerContext::getSourceManager | ( |  | ) |
| inline

Definition at line 107 of file CheckerContext.h.

References getBugReporter(), and clang::ento::BugReporter::getSourceManager().

Referenced by getMacroNameOrSpelling().

## ◆ getStackFrame()

const StackFrameContext* clang::ento::CheckerContext::getStackFrame | ( |  | ) | const
| inline

Definition at line 96 of file CheckerContext.h.

References clang::ento::ExplodedNode::getStackFrame().

Referenced by clang::ento::retaincountchecker::RetainCountChecker::checkPostStmt(), and getConstructedRegion().

## ◆ getState()

const ProgramStateRef& clang::ento::CheckerContext::getState | ( |  | ) | const
| 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().

## ◆ getStateManager()

ProgramStateManager& clang::ento::CheckerContext::getStateManager | ( |  | ) |
| inline

Definition at line 119 of file CheckerContext.h.

References clang::ento::ExprEngine::getStateManager().

## ◆ getStoreManager()

StoreManager& clang::ento::CheckerContext::getStoreManager | ( |  | ) |
| inline

Definition at line 64 of file CheckerContext.h.

References clang::ento::ExprEngine::getStoreManager().

Referenced by clang::ento::mpi::MPIChecker::checkMissingWaits().

## ◆ getSVal()

SVal clang::ento::CheckerContext::getSVal | ( | const Stmt * | S | ) | const
| inline

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().

## ◆ getSValBuilder()

SValBuilder& clang::ento::CheckerContext::getSValBuilder | ( |  | ) |
| 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().

## ◆ getSymbolManager()

SymbolManager& clang::ento::CheckerContext::getSymbolManager | ( |  | ) |
| inline

Definition at line 115 of file CheckerContext.h.

References getSValBuilder(), and clang::ento::SValBuilder::getSymbolManager().

## ◆ inTopFrame()

bool clang::ento::CheckerContext::inTopFrame | ( |  | ) | const
| 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().

## ◆ isCLibraryFunction()

bool CheckerContext::isCLibraryFunction | ( | const FunctionDecl * | FD,
|  | StringRef | Name = `StringRef()`
| ) |  |
| 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().

## ◆ isDifferent()

bool clang::ento::CheckerContext::isDifferent | ( |  | ) |
| 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.

## ◆ isGreaterOrEqual()

bool CheckerContext::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.

Definition at line 124 of file CheckerContext.cpp.

References evalComparison(), getASTContext(), getState(), getSVal(), getSValBuilder(), and clang::ento::SValBuilder::makeIntVal().

## ◆ isNegative()

bool CheckerContext::isNegative | ( | const Expr * | E | ) |

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().

## Member Data Documentation

## ◆ wasInlined

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().

The documentation for this class was generated from the following files:

- include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h
- lib/StaticAnalyzer/Core/CheckerContext.cpp