clang  10.0.0svn
Public Types | Public Member Functions | Protected Types | Protected Attributes | Friends | List of all members
clang::ento::BugReport Class Reference

This class provides an interface through which checkers can create individual bug reports. More...

#include "clang/StaticAnalyzer/Core/BugReporter/BugReporter.h"

Inheritance diagram for clang::ento::BugReport:
Inheritance graph
[legend]
Collaboration diagram for clang::ento::BugReport:
Collaboration graph
[legend]

Public Types

using ranges_iterator = const SourceRange *
 
using VisitorList = SmallVector< std::unique_ptr< BugReporterVisitor >, 8 >
 
using visitor_iterator = VisitorList::iterator
 
using visitor_range = llvm::iterator_range< visitor_iterator >
 
using NoteList = SmallVector< std::shared_ptr< PathDiagnosticNotePiece >, 4 >
 

Public Member Functions

 BugReport (const BugType &bt, StringRef desc, const ExplodedNode *errornode)
 
 BugReport (const BugType &bt, StringRef shortDesc, StringRef desc, const ExplodedNode *errornode)
 
 BugReport (const BugType &bt, StringRef desc, PathDiagnosticLocation l)
 
 BugReport (BugType &bt, StringRef desc, const ExplodedNode *errornode, PathDiagnosticLocation LocationToUnique, const Decl *DeclToUnique)
 Create a BugReport with a custom uniqueing location. More...
 
virtual ~BugReport ()=default
 
const BugTypegetBugType () const
 
bool isPathSensitive () const
 True when the report has an execution path associated with it. More...
 
const ExplodedNodegetErrorNode () const
 
StringRef getDescription () const
 
StringRef getShortDescription (bool UseFallback=true) const
 
bool shouldPrunePath () const
 Indicates whether or not any path pruning should take place when generating a PathDiagnostic from this BugReport. More...
 
void disablePathPruning ()
 Disable all path pruning when generating a PathDiagnostic. More...
 
void markInteresting (SymbolRef sym, bugreporter::TrackingKind TKind=bugreporter::TrackingKind::Thorough)
 Marks a symbol as interesting. More...
 
void markInteresting (const MemRegion *R, bugreporter::TrackingKind TKind=bugreporter::TrackingKind::Thorough)
 Marks a region as interesting. More...
 
void markInteresting (SVal V, bugreporter::TrackingKind TKind=bugreporter::TrackingKind::Thorough)
 Marks a symbolic value as interesting. More...
 
void markInteresting (const LocationContext *LC)
 
bool isInteresting (SymbolRef sym) const
 
bool isInteresting (const MemRegion *R) const
 
bool isInteresting (SVal V) const
 
bool isInteresting (const LocationContext *LC) const
 
Optional< bugreporter::TrackingKind > getInterestingnessKind (SymbolRef sym) const
 
Optional< bugreporter::TrackingKind > getInterestingnessKind (const MemRegion *R) const
 
Optional< bugreporter::TrackingKind > getInterestingnessKind (SVal V) const
 
bool isValid () const
 Returns whether or not this report should be considered valid. More...
 
void markInvalid (const void *Tag, const void *Data)
 Marks the current report as invalid, meaning that it is probably a false positive and should not be reported to the user. More...
 
const DeclgetDeclWithIssue () const
 Return the canonical declaration, be it a method or class, where this issue semantically occurred. More...
 
void setDeclWithIssue (const Decl *declWithIssue)
 Specifically set the Decl where an issue occurred. More...
 
void addNote (StringRef Msg, const PathDiagnosticLocation &Pos, ArrayRef< SourceRange > Ranges)
 Add new item to the list of additional notes that need to be attached to this path-insensitive report. More...
 
void addNote (StringRef Msg, const PathDiagnosticLocation &Pos)
 
virtual const NoteListgetNotes ()
 
virtual PathDiagnosticLocation getLocation (const SourceManager &SM) const
 Return the "definitive" location of the reported bug. More...
 
PathDiagnosticLocation getUniqueingLocation () const
 Get the location on which the report should be uniqued. More...
 
const DeclgetUniqueingDecl () const
 Get the declaration containing the uniqueing location. More...
 
const StmtgetStmt () const
 
void addRange (SourceRange R)
 Add a range to a bug report. More...
 
virtual llvm::iterator_range< ranges_iteratorgetRanges () const
 Get the SourceRanges associated with the report. More...
 
void addVisitor (std::unique_ptr< BugReporterVisitor > visitor)
 Add custom or predefined bug report visitors to this report. More...
 
void clearVisitors ()
 Remove all visitors attached to this bug report. More...
 
visitor_iterator visitor_begin ()
 Iterators through the custom diagnostic visitors. More...
 
visitor_iterator visitor_end ()
 
visitor_range visitors ()
 
bool addTrackedCondition (const ExplodedNode *Cond)
 Notes that the condition of the CFGBlock associated with Cond is being tracked. More...
 
virtual void Profile (llvm::FoldingSetNodeID &hash) const
 Profile to identify equivalent bug reports for error report coalescing. More...
 

Protected Types

using InvalidationRecord = std::pair< const void *, const void * >
 Used to track unique reasons why a bug report might be invalid. More...
 

Protected Attributes

const BugTypeBT
 
const DeclDeclWithIssue = nullptr
 
std::string ShortDescription
 
std::string Description
 
PathDiagnosticLocation Location
 
PathDiagnosticLocation UniqueingLocation
 
const DeclUniqueingDecl
 
const ExplodedNodeErrorNode = nullptr
 
SmallVector< SourceRange, 4 > Ranges
 
const SourceRange ErrorNodeRange
 
NoteList Notes
 
llvm::DenseMap< SymbolRef, bugreporter::TrackingKind > InterestingSymbols
 A (stack of) a set of symbols that are registered with this report as being "interesting", and thus used to help decide which diagnostics to include when constructing the final path diagnostic. More...
 
llvm::DenseMap< const MemRegion *, bugreporter::TrackingKind > InterestingRegions
 A (stack of) set of regions that are registered with this report as being "interesting", and thus used to help decide which diagnostics to include when constructing the final path diagnostic. More...
 
llvm::SmallSet< const LocationContext *, 2 > InterestingLocationContexts
 A set of location contexts that correspoind to call sites which should be considered "interesting". More...
 
VisitorList Callbacks
 A set of custom visitors which generate "event" diagnostics at interesting points in the path. More...
 
llvm::FoldingSet< BugReporterVisitorCallbacksSet
 Used for ensuring the visitors are only added once. More...
 
bool DoNotPrunePath = false
 When set, this flag disables all callstack pruning from a diagnostic path. More...
 
llvm::SmallSet< InvalidationRecord, 4 > Invalidations
 If non-empty, this bug report is likely a false positive and should not be shown to the user. More...
 
llvm::SmallSet< const ExplodedNode *, 4 > TrackedConditions
 Conditions we're already tracking. More...
 

Friends

class BugReportEquivClass
 
class BugReporter
 

Detailed Description

This class provides an interface through which checkers can create individual bug reports.

Definition at line 75 of file BugReporter.h.

Member Typedef Documentation

◆ InvalidationRecord

using clang::ento::BugReport::InvalidationRecord = std::pair<const void *, const void *>
protected

Used to track unique reasons why a bug report might be invalid.

See also
markInvalid
removeInvalidation

Definition at line 135 of file BugReporter.h.

◆ NoteList

Definition at line 81 of file BugReporter.h.

◆ ranges_iterator

Definition at line 77 of file BugReporter.h.

◆ visitor_iterator

using clang::ento::BugReport::visitor_iterator = VisitorList::iterator

Definition at line 79 of file BugReporter.h.

◆ visitor_range

Definition at line 80 of file BugReporter.h.

◆ VisitorList

Definition at line 78 of file BugReporter.h.

Constructor & Destructor Documentation

◆ BugReport() [1/4]

clang::ento::BugReport::BugReport ( const BugType bt,
StringRef  desc,
const ExplodedNode errornode 
)
inline

Definition at line 148 of file BugReporter.h.

◆ BugReport() [2/4]

clang::ento::BugReport::BugReport ( const BugType bt,
StringRef  shortDesc,
StringRef  desc,
const ExplodedNode errornode 
)
inline

Definition at line 153 of file BugReporter.h.

◆ BugReport() [3/4]

clang::ento::BugReport::BugReport ( const BugType bt,
StringRef  desc,
PathDiagnosticLocation  l 
)
inline

Definition at line 160 of file BugReporter.h.

◆ BugReport() [4/4]

clang::ento::BugReport::BugReport ( BugType bt,
StringRef  desc,
const ExplodedNode errornode,
PathDiagnosticLocation  LocationToUnique,
const Decl DeclToUnique 
)
inline

Create a BugReport with a custom uniqueing location.

The reports that have the same report location, description, bug type, and ranges are uniqued - only one of the equivalent reports will be presented to the user. This method allows to rest the location which should be used for uniquing reports. For example, memory leaks checker, could set this to the allocation site, rather then the location where the bug is reported.

Definition at line 172 of file BugReporter.h.

References ~BugReport().

◆ ~BugReport()

virtual clang::ento::BugReport::~BugReport ( )
virtualdefault

Referenced by BugReport().

Member Function Documentation

◆ addNote() [1/2]

void clang::ento::BugReport::addNote ( StringRef  Msg,
const PathDiagnosticLocation Pos,
ArrayRef< SourceRange Ranges 
)
inline

Add new item to the list of additional notes that need to be attached to this path-insensitive report.

If you want to add extra notes to a path-sensitive report, you need to use a BugReporterVisitor because it allows you to specify where exactly in the auto-generated path diagnostic the extra note should appear.

Definition at line 282 of file BugReporter.h.

References P.

Referenced by addNote().

◆ addNote() [2/2]

void clang::ento::BugReport::addNote ( StringRef  Msg,
const PathDiagnosticLocation Pos 
)
inline

Definition at line 294 of file BugReporter.h.

References addNote(), and Ranges.

◆ addRange()

void clang::ento::BugReport::addRange ( SourceRange  R)
inline

Add a range to a bug report.

Ranges are used to highlight regions of interest in the source code. They should be at the same source code line as the BugReport location. By default, the source range of the statement corresponding to the error node will be used; add a single invalid range to specify absence of ranges.

Definition at line 329 of file BugReporter.h.

References addVisitor(), clearVisitors(), getRanges(), and clang::SourceRange::isValid().

◆ addTrackedCondition()

bool clang::ento::BugReport::addTrackedCondition ( const ExplodedNode Cond)
inline

Notes that the condition of the CFGBlock associated with Cond is being tracked.

Returns
false if the condition is already being tracked.

Definition at line 358 of file BugReporter.h.

References Profile().

◆ addVisitor()

void BugReport::addVisitor ( std::unique_ptr< BugReporterVisitor visitor)

Add custom or predefined bug report visitors to this report.

The visitors should be used when the default trace is not sufficient. For example, they allow constructing a more elaborate trace.

See also
registerConditionVisitor(), registerTrackNullOrUndefValue(), registerFindLastStore(), registerNilReceiverVisitor(), and registerVarDeclsLastStore().

Definition at line 2053 of file BugReporter.cpp.

Referenced by addRange().

◆ clearVisitors()

void BugReport::clearVisitors ( )

Remove all visitors attached to this bug report.

Definition at line 2068 of file BugReporter.cpp.

Referenced by addRange().

◆ disablePathPruning()

void clang::ento::BugReport::disablePathPruning ( )
inline

Disable all path pruning when generating a PathDiagnostic.

Definition at line 211 of file BugReporter.h.

References getInterestingnessKind(), isInteresting(), markInteresting(), and V.

◆ getBugType()

const BugType& clang::ento::BugReport::getBugType ( ) const
inline

Definition at line 181 of file BugReporter.h.

References BT.

◆ getDeclWithIssue()

const Decl * BugReport::getDeclWithIssue ( ) const

Return the canonical declaration, be it a method or class, where this issue semantically occurred.

Definition at line 2072 of file BugReporter.cpp.

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

Referenced by markInvalid().

◆ getDescription()

StringRef clang::ento::BugReport::getDescription ( ) const
inline

Definition at line 198 of file BugReporter.h.

References Description.

◆ getErrorNode()

const ExplodedNode* clang::ento::BugReport::getErrorNode ( ) const
inline

Definition at line 196 of file BugReporter.h.

References ErrorNode.

◆ getInterestingnessKind() [1/3]

Optional< bugreporter::TrackingKind > BugReport::getInterestingnessKind ( SymbolRef  sym) const

Definition at line 2194 of file BugReporter.cpp.

Referenced by disablePathPruning().

◆ getInterestingnessKind() [2/3]

Optional< bugreporter::TrackingKind > BugReport::getInterestingnessKind ( const MemRegion R) const

Definition at line 2206 of file BugReporter.cpp.

References clang::ento::MemRegion::getBaseRegion().

◆ getInterestingnessKind() [3/3]

Optional< bugreporter::TrackingKind > BugReport::getInterestingnessKind ( SVal  V) const

◆ getLocation()

PathDiagnosticLocation BugReport::getLocation ( const SourceManager SM) const
virtual

Return the "definitive" location of the reported bug.

While a bug can span an entire path, usually there is a specific location that can be used to identify where the key issue occurred. This location is used by clients rendering diagnostics.

Reimplemented in clang::ento::retaincountchecker::RefLeakReport.

Definition at line 2272 of file BugReporter.cpp.

References clang::ento::PathDiagnosticLocation::createEndOfPath().

Referenced by getNotes().

◆ getNotes()

virtual const NoteList& clang::ento::BugReport::getNotes ( )
inlinevirtual

Definition at line 299 of file BugReporter.h.

References getLocation(), Notes, and SM.

◆ getRanges()

llvm::iterator_range< BugReport::ranges_iterator > BugReport::getRanges ( ) const
virtual

Get the SourceRanges associated with the report.

Reimplemented in clang::ento::retaincountchecker::RefCountReport.

Definition at line 2256 of file BugReporter.cpp.

Referenced by addRange(), and clang::ento::retaincountchecker::RefCountReport::getRanges().

◆ getShortDescription()

StringRef clang::ento::BugReport::getShortDescription ( bool  UseFallback = true) const
inline

Definition at line 200 of file BugReporter.h.

References ShortDescription.

◆ getStmt()

const Stmt * BugReport::getStmt ( ) const

◆ getUniqueingDecl()

const Decl* clang::ento::BugReport::getUniqueingDecl ( ) const
inline

Get the declaration containing the uniqueing location.

Definition at line 316 of file BugReporter.h.

References getStmt(), and UniqueingDecl.

◆ getUniqueingLocation()

PathDiagnosticLocation clang::ento::BugReport::getUniqueingLocation ( ) const
inline

Get the location on which the report should be uniqued.

Definition at line 311 of file BugReporter.h.

References UniqueingLocation.

◆ isInteresting() [1/4]

bool BugReport::isInteresting ( SymbolRef  sym) const

Definition at line 2224 of file BugReporter.cpp.

Referenced by disablePathPruning().

◆ isInteresting() [2/4]

bool BugReport::isInteresting ( const MemRegion R) const

Definition at line 2228 of file BugReporter.cpp.

◆ isInteresting() [3/4]

bool BugReport::isInteresting ( SVal  V) const

Definition at line 2220 of file BugReporter.cpp.

◆ isInteresting() [4/4]

bool BugReport::isInteresting ( const LocationContext LC) const

Definition at line 2232 of file BugReporter.cpp.

◆ isPathSensitive()

bool clang::ento::BugReport::isPathSensitive ( ) const
inline

True when the report has an execution path associated with it.

A report is said to be path-sensitive if it was thrown against a particular exploded node in the path-sensitive analysis graph. Path-sensitive reports have their intermediate path diagnostics auto-generated, perhaps with the help of checker-defined visitors, and may contain extra notes. Path-insensitive reports consist only of a single warning message in a specific location, and perhaps extra notes. Path-sensitive checkers are allowed to throw path-insensitive reports.

Definition at line 194 of file BugReporter.h.

◆ isValid()

bool clang::ento::BugReport::isValid ( ) const
inline

Returns whether or not this report should be considered valid.

Invalid reports are those that have been classified as likely false positives after the fact.

Definition at line 250 of file BugReporter.h.

◆ markInteresting() [1/4]

void clang::ento::BugReport::markInteresting ( SymbolRef  sym,
bugreporter::TrackingKind  TKind = bugreporter::TrackingKind::Thorough 
)

Marks a symbol as interesting.

Different kinds of interestingness will be processed differently by visitors (e.g. if the tracking kind is condition, will append "will be used as a condition" to the message).

Referenced by disablePathPruning(), and insertToInterestingnessMap().

◆ markInteresting() [2/4]

void clang::ento::BugReport::markInteresting ( const MemRegion R,
bugreporter::TrackingKind  TKind = bugreporter::TrackingKind::Thorough 
)

Marks a region as interesting.

Different kinds of interestingness will be processed differently by visitors (e.g. if the tracking kind is condition, will append "will be used as a condition" to the message).

◆ markInteresting() [3/4]

void clang::ento::BugReport::markInteresting ( SVal  V,
bugreporter::TrackingKind  TKind = bugreporter::TrackingKind::Thorough 
)

Marks a symbolic value as interesting.

Different kinds of interestingness will be processed differently by visitors (e.g. if the tracking kind is condition, will append "will be used as a condition" to the message).

◆ markInteresting() [4/4]

void BugReport::markInteresting ( const LocationContext LC)

Definition at line 2162 of file BugReporter.cpp.

◆ markInvalid()

void clang::ento::BugReport::markInvalid ( const void *  Tag,
const void *  Data 
)
inline

Marks the current report as invalid, meaning that it is probably a false positive and should not be reported to the user.

The Tag and Data arguments are intended to be opaque identifiers for this particular invalidation, where Tag represents the visitor responsible for invalidation, and Data represents the reason this visitor decided to invalidate the bug report.

See also
removeInvalidation

Definition at line 263 of file BugReporter.h.

References getDeclWithIssue().

◆ Profile()

void BugReport::Profile ( llvm::FoldingSetNodeID &  hash) const
virtual

Profile to identify equivalent bug reports for error report coalescing.

Reports are uniqued to ensure that we do not emit multiple diagnostics for each bug.

Definition at line 2084 of file BugReporter.cpp.

References GetCurrentOrPreviousStmt(), clang::ento::PathDiagnosticLocation::isValid(), clang::ento::PathDiagnosticLocation::Profile(), and clang::tooling::range().

Referenced by addTrackedCondition().

◆ setDeclWithIssue()

void clang::ento::BugReport::setDeclWithIssue ( const Decl declWithIssue)
inline

Specifically set the Decl where an issue occurred.

This isn't necessary for BugReports that cover a path as it will be automatically inferred.

Definition at line 273 of file BugReporter.h.

◆ shouldPrunePath()

bool clang::ento::BugReport::shouldPrunePath ( ) const
inline

Indicates whether or not any path pruning should take place when generating a PathDiagnostic from this BugReport.

Definition at line 208 of file BugReporter.h.

References DoNotPrunePath.

◆ visitor_begin()

visitor_iterator clang::ento::BugReport::visitor_begin ( )
inline

Iterators through the custom diagnostic visitors.

Definition at line 351 of file BugReporter.h.

Referenced by visitors().

◆ visitor_end()

visitor_iterator clang::ento::BugReport::visitor_end ( )
inline

Definition at line 352 of file BugReporter.h.

Referenced by visitors().

◆ visitors()

visitor_range clang::ento::BugReport::visitors ( )
inline

Definition at line 353 of file BugReporter.h.

References visitor_begin(), and visitor_end().

Friends And Related Function Documentation

◆ BugReportEquivClass

friend class BugReportEquivClass
friend

Definition at line 84 of file BugReporter.h.

◆ BugReporter

friend class BugReporter
friend

Definition at line 85 of file BugReporter.h.

Member Data Documentation

◆ BT

const BugType& clang::ento::BugReport::BT
protected

Definition at line 87 of file BugReporter.h.

Referenced by getBugType().

◆ Callbacks

VisitorList clang::ento::BugReport::Callbacks
protected

A set of custom visitors which generate "event" diagnostics at interesting points in the path.

Definition at line 121 of file BugReporter.h.

◆ CallbacksSet

llvm::FoldingSet<BugReporterVisitor> clang::ento::BugReport::CallbacksSet
protected

Used for ensuring the visitors are only added once.

Definition at line 124 of file BugReporter.h.

◆ DeclWithIssue

const Decl* clang::ento::BugReport::DeclWithIssue = nullptr
protected

Definition at line 88 of file BugReporter.h.

Referenced by clang::ento::BugReporter::generatePathDiagnostics().

◆ Description

std::string clang::ento::BugReport::Description
protected

Definition at line 90 of file BugReporter.h.

Referenced by getDescription().

◆ DoNotPrunePath

bool clang::ento::BugReport::DoNotPrunePath = false
protected

When set, this flag disables all callstack pruning from a diagnostic path.

This is useful for some reports that want maximum fidelty when reporting an issue.

Definition at line 129 of file BugReporter.h.

Referenced by shouldPrunePath().

◆ ErrorNode

const ExplodedNode* clang::ento::BugReport::ErrorNode = nullptr
protected

Definition at line 95 of file BugReporter.h.

Referenced by getErrorNode().

◆ ErrorNodeRange

const SourceRange clang::ento::BugReport::ErrorNodeRange
protected

Definition at line 97 of file BugReporter.h.

◆ InterestingLocationContexts

llvm::SmallSet<const LocationContext *, 2> clang::ento::BugReport::InterestingLocationContexts
protected

A set of location contexts that correspoind to call sites which should be considered "interesting".

Definition at line 117 of file BugReporter.h.

◆ InterestingRegions

llvm::DenseMap<const MemRegion *, bugreporter::TrackingKind> clang::ento::BugReport::InterestingRegions
protected

A (stack of) set of regions that are registered with this report as being "interesting", and thus used to help decide which diagnostics to include when constructing the final path diagnostic.

The stack is largely used by BugReporter when generating PathDiagnostics for multiple PathDiagnosticConsumers.

Definition at line 113 of file BugReporter.h.

◆ InterestingSymbols

llvm::DenseMap<SymbolRef, bugreporter::TrackingKind> clang::ento::BugReport::InterestingSymbols
protected

A (stack of) a set of symbols that are registered with this report as being "interesting", and thus used to help decide which diagnostics to include when constructing the final path diagnostic.

The stack is largely used by BugReporter when generating PathDiagnostics for multiple PathDiagnosticConsumers.

Definition at line 105 of file BugReporter.h.

◆ Invalidations

llvm::SmallSet<InvalidationRecord, 4> clang::ento::BugReport::Invalidations
protected

If non-empty, this bug report is likely a false positive and should not be shown to the user.

See also
markInvalid
removeInvalidation

Definition at line 142 of file BugReporter.h.

◆ Location

PathDiagnosticLocation clang::ento::BugReport::Location
protected

Definition at line 91 of file BugReporter.h.

◆ Notes

NoteList clang::ento::BugReport::Notes
protected

Definition at line 98 of file BugReporter.h.

Referenced by getNotes().

◆ Ranges

SmallVector<SourceRange, 4> clang::ento::BugReport::Ranges
protected

Definition at line 96 of file BugReporter.h.

Referenced by addNote(), and clang::ento::BugReporter::generatePathDiagnostics().

◆ ShortDescription

std::string clang::ento::BugReport::ShortDescription
protected

Definition at line 89 of file BugReporter.h.

Referenced by getShortDescription().

◆ TrackedConditions

llvm::SmallSet<const ExplodedNode *, 4> clang::ento::BugReport::TrackedConditions
protected

Conditions we're already tracking.

Definition at line 145 of file BugReporter.h.

◆ UniqueingDecl

const Decl* clang::ento::BugReport::UniqueingDecl
protected

Definition at line 93 of file BugReporter.h.

Referenced by getUniqueingDecl().

◆ UniqueingLocation

PathDiagnosticLocation clang::ento::BugReport::UniqueingLocation
protected

Definition at line 92 of file BugReporter.h.

Referenced by getUniqueingLocation().


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