clang API Documentation

Public Member Functions | Static Public Member Functions | Public Attributes
clang::ento::CheckerContext Class Reference

#include <CheckerContext.h>

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

List of all members.

Public Member Functions

 CheckerContext (NodeBuilder &builder, ExprEngine &eng, ExplodedNode *pred, const ProgramPoint &loc, bool wasInlined=false)
AnalysisManagergetAnalysisManager ()
ConstraintManagergetConstraintManager ()
StoreManagergetStoreManager ()
ExplodedNodegetPredecessor ()
 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.
const ProgramStateRefgetState () const
bool isDifferent ()
 Check if the checker changed the state of the execution; ex: added a new transition or a bug report.
unsigned blockCount () const
 Returns the number of times the current block has been visited along the analyzed path.
ASTContextgetASTContext ()
const LangOptionsgetLangOpts () const
const LocationContextgetLocationContext () const
const StackFrameContextgetStackFrame () const
bool inTopFrame () const
 Return true if the current LocationContext has no caller context.
BugReportergetBugReporter ()
SourceManagergetSourceManager ()
SValBuildergetSValBuilder ()
SymbolManagergetSymbolManager ()
bool isObjCGCEnabled () const
ProgramStateManagergetStateManager ()
AnalysisDeclContextgetCurrentAnalysisDeclContext () const
unsigned getBlockID () const
 Get the blockID.
SVal getSVal (const Stmt *S) const
 Get the value of arbitrary expressions at this point in the path.
ExplodedNodeaddTransition (ProgramStateRef State=nullptr, const ProgramPointTag *Tag=nullptr)
 Generates a new transition in the program state graph (ExplodedGraph). Uses the default CheckerContext predecessor node.
ExplodedNodeaddTransition (ProgramStateRef State, ExplodedNode *Pred, const ProgramPointTag *Tag=nullptr)
 Generates a new transition with the given predecessor. Allows checkers to generate a chain of nodes.
ExplodedNodegenerateSink (ProgramStateRef State=nullptr, ExplodedNode *Pred=nullptr, const ProgramPointTag *Tag=nullptr)
 Generate a sink node. Generating a sink stops exploration of the given path.
void emitReport (BugReport *R)
 Emit the diagnostics report.
const FunctionDeclgetCalleeDecl (const CallExpr *CE) const
 Get the declaration of the called function (path-sensitive).
StringRef getCalleeName (const FunctionDecl *FunDecl) const
 Get the name of the called function (path-sensitive).
const IdentifierInfogetCalleeIdentifier (const CallExpr *CE) const
 Get the identifier of the called function (path-sensitive).
StringRef getCalleeName (const CallExpr *CE) const
 Get the name of the called function (path-sensitive).
StringRef getMacroNameOrSpelling (SourceLocation &Loc)
 Depending on wither the location corresponds to a macro, return either the macro name or the token spelling.

Static Public Member Functions

static const MemRegiongetLocationRegionIfPostStore (const ExplodedNode *N)
 If the given node corresponds to a PostStore program point, retrieve the location region as it was uttered in the code.
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.

Public Attributes

const bool wasInlined

Detailed Description

Definition at line 70 of file CheckerContext.h.


Constructor & Destructor Documentation

clang::ento::CheckerContext::CheckerContext ( NodeBuilder builder,
ExprEngine eng,
ExplodedNode pred,
const ProgramPoint loc,
bool  wasInlined = false 
) [inline]

Definition at line 87 of file CheckerContext.h.

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


Member Function Documentation

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:
StateThe state of the generated node. If not specified, the state will not be changed, but the new node will have the checker's tag.
TagThe 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 208 of file CheckerContext.h.

References getState(), and State.

Referenced by addSelfFlag(), recordFixedType(), and setFlag().

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:
StateThe state of the generated node.
PredThe transition will be generated from the specified Pred node to the newly generated node.
TagThe tag to uniquely identify the creation site.

Definition at line 220 of file CheckerContext.h.

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

Emit the diagnostics report.

Definition at line 235 of file CheckerContext.h.

References clang::ento::BugReporter::emitReport(), and clang::ento::ExprEngine::getBugReporter().

Referenced by emitBug().

ExplodedNode* clang::ento::CheckerContext::generateSink ( ProgramStateRef  State = nullptr,
ExplodedNode Pred = nullptr,
const ProgramPointTag Tag = nullptr 
) [inline]

Generate a sink node. Generating a sink stops exploration of the given path.

Definition at line 228 of file CheckerContext.h.

References getState(), and State.

Referenced by emitBug().

Definition at line 102 of file CheckerContext.h.

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

Definition at line 130 of file CheckerContext.h.

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

Referenced by recordFixedType().

Definition at line 149 of file CheckerContext.h.

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

Referenced by getSourceManager().

const FunctionDecl * CheckerContext::getCalleeDecl ( const CallExpr CE) const

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

Definition at line 247 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 29 of file CheckerContext.cpp.

References clang::NamedDecl::getIdentifier(), and clang::IdentifierInfo::getName().

Referenced by getCalleeName(), and getPrintfFormatArgumentNum().

StringRef clang::ento::CheckerContext::getCalleeName ( const CallExpr CE) const [inline]

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

Definition at line 256 of file CheckerContext.h.

References getCalleeDecl(), and getCalleeName().

Definition at line 106 of file CheckerContext.h.

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

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

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 91 of file CheckerContext.cpp.

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

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

Definition at line 142 of file CheckerContext.h.

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

Definition at line 169 of file CheckerContext.h.

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

Definition at line 110 of file CheckerContext.h.

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

Referenced by getAsPointeeSymbol().

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 195 of file CheckerContext.h.

References getLocationContext(), and getState().

Referenced by checkCollectionNonNil().

Return true if the current LocationContext has no caller context.

Definition at line 147 of file CheckerContext.h.

References getLocationContext(), and clang::LocationContext::inTopFrame().

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 39 of file CheckerContext.cpp.

References clang::ASTContext::BuiltinInfo, clang::Decl::getASTContext(), clang::FunctionDecl::getBuiltinID(), clang::Decl::getDeclContext(), clang::NamedDecl::getIdentifier(), clang::Builtin::Context::GetName(), clang::IdentifierInfo::getName(), clang::DeclContext::getParent(), clang::NamedDecl::isExternallyVisible(), clang::FunctionDecl::isInlined(), clang::DeclContext::isTranslationUnit(), and clang::DeclContext::isTransparentContext().

Referenced by clang::ento::CallEvent::isGlobalCFunction().

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.

Definition at line 165 of file CheckerContext.h.

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


Member Data Documentation

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.


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