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

#include <CheckerContext.h>

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

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. More...
 
const ProgramStateRefgetState () 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...
 
ASTContextgetASTContext ()
 
const LangOptionsgetLangOpts () const
 
const LocationContextgetLocationContext () const
 
const StackFrameContextgetStackFrame () const
 
bool inTopFrame () const
 Return true if the current LocationContext has no caller context. More...
 
BugReportergetBugReporter ()
 
SourceManagergetSourceManager ()
 
SValBuildergetSValBuilder ()
 
SymbolManagergetSymbolManager ()
 
bool isObjCGCEnabled () const
 
ProgramStateManagergetStateManager ()
 
AnalysisDeclContextgetCurrentAnalysisDeclContext () 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...
 
ExplodedNodeaddTransition (ProgramStateRef State=nullptr, const ProgramPointTag *Tag=nullptr)
 Generates a new transition in the program state graph (ExplodedGraph). More...
 
ExplodedNodeaddTransition (ProgramStateRef State, ExplodedNode *Pred, const ProgramPointTag *Tag=nullptr)
 Generates a new transition with the given predecessor. More...
 
ExplodedNodegenerateSink (ProgramStateRef State, ExplodedNode *Pred, const ProgramPointTag *Tag=nullptr)
 Generate a sink node. More...
 
ExplodedNodegenerateErrorNode (ProgramStateRef State=nullptr, const ProgramPointTag *Tag=nullptr)
 Generate a transition to a node that will be used to report an error. More...
 
ExplodedNodegenerateNonFatalErrorNode (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 FunctionDeclgetCalleeDecl (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 IdentifierInfogetCalleeIdentifier (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 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. 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 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(), alreadyExecutedAtLeastOneLoopIteration(), checkInvariantViolation(), computeExtentBegin(), describeUninitializedArgumentInCall(), didPreviousFreeFail(), emitBug(), clang::ento::ProgramStateTrait< SymbolSet >::GDMIndex(), generateNonFatalErrorNode(), GetAllocationSite(), getArgumentValueString(), getAsPointeeSymbol(), GetCFNumberSize(), getFreeWhenDoneArg(), getMethodReceiverIfKnownImmutable(), getReceiverNullability(), GetReturnType(), getReturnTypeForMethod(), isARCNilInitializedLocal(), isCPPStdLibraryFunction(), isDebuggingContext(), isInvalidSelf(), IsZeroByteAllocation(), lookThroughImplicitCasts(), llvm::FoldingSetTrait< AllocKind >::Profile(), recordFixedType(), REGISTER_MAP_WITH_PROGRAMSTATE(), setFlag(), storeWhenMoreInformative(), supportsNilWithFloatRet(), suppressReport(), treatUnusedNewEscaped(), updateOutParameter(), and wasLoadedFromIvar().

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.

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

References clang::ento::NodeBuilderContext::blockCount(), and clang::ento::NodeBuilder::getContext().

Referenced by getFreeWhenDoneArg(), and updateOutParameter().

void clang::ento::CheckerContext::emitReport ( std::unique_ptr< BugReport R)
inline
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
StateThe state of the generated node.
TagThe tag to uniquely identify the creation site. If null, the default tag for the checker will be used.

Definition at line 241 of file CheckerContext.h.

References generateSink(), clang::ProgramPoint::getTag(), and State.

Referenced by computeExtentBegin(), describeUninitializedArgumentInCall(), didPreviousFreeFail(), emitBug(), evenFlexibleArraySize(), FindBlockDeclRefExpr(), findKnownClass(), clang::ento::ProgramStateTrait< SymbolSet >::GDMIndex(), GetCFNumberSize(), isARCNilInitializedLocal(), isInvalidSelf(), isLeaked(), IsZeroByteAllocation(), lookThroughImplicitCasts(), supportsNilWithFloatRet(), suppressReport(), and updateOutParameter().

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
StateThe state of the generated node.
TagThe tag to uniquely identify the creation site. If null, the default tag for the checker will be used.

Definition at line 255 of file CheckerContext.h.

References addTransition(), clang::ProgramPoint::getTag(), and State.

Referenced by didPreviousFreeFail(), clang::ento::ProgramStateTrait< SymbolSet >::GDMIndex(), getArgumentValueString(), getAsPointeeSymbol(), GetCFNumberSize(), getPrintfFormatArgumentNum(), isLeaked(), and llvm::FoldingSetTrait< AllocKind >::Profile().

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

References getState().

Referenced by alreadyExecutedAtLeastOneLoopIteration(), generateErrorNode(), suppressReport(), and updateOutParameter().

AnalysisManager& clang::ento::CheckerContext::getAnalysisManager ( )
inline
ASTContext& clang::ento::CheckerContext::getASTContext ( )
inline
unsigned clang::ento::CheckerContext::getBlockID ( ) const
inline
BugReporter& clang::ento::CheckerContext::getBugReporter ( )
inline
const FunctionDecl * CheckerContext::getCalleeDecl ( const CallExpr CE) const
const IdentifierInfo* clang::ento::CheckerContext::getCalleeIdentifier ( const CallExpr CE) const
inline

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

Definition at line 277 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 emitReport(), getAsPointeeSymbol(), getCalleeName(), getPrintfFormatArgumentNum(), and IsZeroByteAllocation().

StringRef clang::ento::CheckerContext::getCalleeName ( const CallExpr CE) const
inline
ConstraintManager& clang::ento::CheckerContext::getConstraintManager ( )
inline

Definition at line 106 of file CheckerContext.h.

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

Referenced by isBooleanType().

AnalysisDeclContext* clang::ento::CheckerContext::getCurrentAnalysisDeclContext ( ) const
inline
StringRef CheckerContext::getDeclDescription ( const Decl D)

Returns the word that should be used to refer to the declaration in the report.

Definition at line 38 of file CheckerContext.cpp.

Referenced by emitReport(), and lookThroughImplicitCasts().

const LangOptions& clang::ento::CheckerContext::getLangOpts ( ) const
inline
const LocationContext* clang::ento::CheckerContext::getLocationContext ( ) const
inline
static const MemRegion* clang::ento::CheckerContext::getLocationRegionIfPostStore ( const ExplodedNode N)
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().

Referenced by didPreviousFreeFail().

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

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

Referenced by getCalleeName().

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

Referenced by alreadyExecutedAtLeastOneLoopIteration(), checkInvariantViolation(), didPreviousFreeFail(), GetAllocationSite(), getArgumentValueString(), getFreeWhenDoneArg(), getReturnTypeForMethod(), isARCNilInitializedLocal(), isDebuggingContext(), lookThroughImplicitCasts(), recordFixedType(), suppressReport(), and updateOutParameter().

SourceManager& clang::ento::CheckerContext::getSourceManager ( )
inline
const StackFrameContext* clang::ento::CheckerContext::getStackFrame ( ) const
inline

Definition at line 142 of file CheckerContext.h.

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

Referenced by recordFixedType(), and wasLoadedFromIvar().

const ProgramStateRef& clang::ento::CheckerContext::getState ( ) const
inline
ProgramStateManager& clang::ento::CheckerContext::getStateManager ( )
inline

Definition at line 169 of file CheckerContext.h.

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

Referenced by GetAllocationSite().

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

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
SValBuilder& clang::ento::CheckerContext::getSValBuilder ( )
inline
SymbolManager& clang::ento::CheckerContext::getSymbolManager ( )
inline
bool clang::ento::CheckerContext::inTopFrame ( ) const
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().

Referenced by getMethodReceiverIfKnownImmutable(), and updateOutParameter().

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 46 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::getRedeclContext(), clang::NamedDecl::isExternallyVisible(), clang::FunctionDecl::isInlined(), and clang::DeclContext::isTranslationUnit().

Referenced by getCalleeName(), getPrintfFormatArgumentNum(), isCPPStdLibraryFunction(), and clang::ento::CallEvent::isGlobalCFunction().

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

Referenced by isCPPStdLibraryFunction().

bool clang::ento::CheckerContext::isObjCGCEnabled ( ) const
inline

Member Data Documentation

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.

Referenced by getFreeWhenDoneArg(), getReceiverNullability(), and wasLoadedFromIvar().


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