clang
8.0.0
|
This class provides an interface through which checkers can create individual bug reports. More...
#include "clang/StaticAnalyzer/Core/BugReporter/BugReporter.h"
Classes | |
class | NodeResolver |
Public Types | |
using | ranges_iterator = const SourceRange * |
using | VisitorList = SmallVector< std::unique_ptr< BugReporterVisitor >, 8 > |
using | visitor_iterator = VisitorList::iterator |
using | ExtraTextList = SmallVector< StringRef, 2 > |
using | NoteList = SmallVector< std::shared_ptr< PathDiagnosticNotePiece >, 4 > |
Public Member Functions | |
BugReport (BugType &bt, StringRef desc, const ExplodedNode *errornode) | |
BugReport (BugType &bt, StringRef shortDesc, StringRef desc, const ExplodedNode *errornode) | |
BugReport (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 () |
const BugType & | getBugType () const |
BugType & | getBugType () |
bool | isPathSensitive () const |
True when the report has an execution path associated with it. More... | |
const ExplodedNode * | getErrorNode () 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) |
void | markInteresting (const MemRegion *R) |
void | markInteresting (SVal V) |
void | markInteresting (const LocationContext *LC) |
bool | isInteresting (SymbolRef sym) |
bool | isInteresting (const MemRegion *R) |
bool | isInteresting (SVal V) |
bool | isInteresting (const LocationContext *LC) |
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 Decl * | getDeclWithIssue () 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 NoteList & | getNotes () |
void | addExtraText (StringRef S) |
This allows for addition of meta data to the diagnostic. More... | |
virtual const ExtraTextList & | getExtraText () |
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 Decl * | getUniqueingDecl () const |
Get the declaration containing the uniqueing location. More... | |
const Stmt * | getStmt () const |
void | addRange (SourceRange R) |
Add a range to a bug report. More... | |
virtual llvm::iterator_range< ranges_iterator > | getRanges () |
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 () |
virtual void | Profile (llvm::FoldingSetNodeID &hash) const |
Profile to identify equivalent bug reports for error report coalescing. More... | |
Protected Types | |
using | Symbols = llvm::DenseSet< SymbolRef > |
using | Regions = llvm::DenseSet< const MemRegion * > |
using | InvalidationRecord = std::pair< const void *, const void * > |
Used to track unique reasons why a bug report might be invalid. More... | |
Protected Attributes | |
BugType & | BT |
const Decl * | DeclWithIssue = nullptr |
std::string | ShortDescription |
std::string | Description |
PathDiagnosticLocation | Location |
PathDiagnosticLocation | UniqueingLocation |
const Decl * | UniqueingDecl |
const ExplodedNode * | ErrorNode = nullptr |
SmallVector< SourceRange, 4 > | Ranges |
ExtraTextList | ExtraText |
NoteList | Notes |
SmallVector< Symbols *, 2 > | 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... | |
SmallVector< Regions *, 2 > | 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< BugReporterVisitor > | CallbacksSet |
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... | |
Friends | |
class | BugReportEquivClass |
class | BugReporter |
This class provides an interface through which checkers can create individual bug reports.
Definition at line 76 of file BugReporter.h.
using clang::ento::BugReport::ExtraTextList = SmallVector<StringRef, 2> |
Definition at line 91 of file BugReporter.h.
|
protected |
Used to track unique reasons why a bug report might be invalid.
Definition at line 148 of file BugReporter.h.
using clang::ento::BugReport::NoteList = SmallVector<std::shared_ptr<PathDiagnosticNotePiece>, 4> |
Definition at line 92 of file BugReporter.h.
using clang::ento::BugReport::ranges_iterator = const SourceRange * |
Definition at line 88 of file BugReporter.h.
|
protected |
Definition at line 112 of file BugReporter.h.
|
protected |
Definition at line 111 of file BugReporter.h.
using clang::ento::BugReport::visitor_iterator = VisitorList::iterator |
Definition at line 90 of file BugReporter.h.
using clang::ento::BugReport::VisitorList = SmallVector<std::unique_ptr<BugReporterVisitor>, 8> |
Definition at line 89 of file BugReporter.h.
|
inline |
Definition at line 167 of file BugReporter.h.
|
inline |
Definition at line 170 of file BugReporter.h.
|
inline |
Definition at line 175 of file BugReporter.h.
|
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 185 of file BugReporter.h.
References ~BugReport().
|
virtual |
Definition at line 2050 of file BugReporter.cpp.
Referenced by BugReport().
|
inline |
This allows for addition of meta data to the diagnostic.
Currently, only the HTMLDiagnosticClient knows how to display it.
Definition at line 294 of file BugReporter.h.
|
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 270 of file BugReporter.h.
References P.
Referenced by addNote().
|
inline |
Definition at line 282 of file BugReporter.h.
|
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 328 of file BugReporter.h.
References addVisitor(), clearVisitors(), getRanges(), and clang::SourceRange::isValid().
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.
Definition at line 2031 of file BugReporter.cpp.
Referenced by addRange().
void BugReport::clearVisitors | ( | ) |
Remove all visitors attached to this bug report.
Definition at line 2046 of file BugReporter.cpp.
Referenced by addRange().
|
inline |
Disable all path pruning when generating a PathDiagnostic.
Definition at line 222 of file BugReporter.h.
References isInteresting(), and markInteresting().
|
inline |
Definition at line 192 of file BugReporter.h.
References BT.
|
inline |
Definition at line 193 of file BugReporter.h.
References BT.
const Decl * BugReport::getDeclWithIssue | ( | ) | const |
Return the canonical declaration, be it a method or class, where this issue semantically occurred.
Definition at line 2056 of file BugReporter.cpp.
References clang::LocationContext::getDecl(), clang::ento::ExplodedNode::getLocationContext(), and clang::LocationContext::getStackFrame().
Referenced by markInvalid().
|
inline |
Definition at line 209 of file BugReporter.h.
References Description.
|
inline |
Definition at line 207 of file BugReporter.h.
References ErrorNode.
|
inlinevirtual |
Definition at line 298 of file BugReporter.h.
References ExtraText, getLocation(), and SM.
|
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 2213 of file BugReporter.cpp.
References clang::ento::PathDiagnosticLocation::createEndOfPath(), clang::ento::BugReportEquivClass::~BugReportEquivClass(), clang::ento::BugReporterData::~BugReporterData(), and clang::ento::GRBugReporter::~GRBugReporter().
Referenced by getExtraText().
|
inlinevirtual |
Definition at line 287 of file BugReporter.h.
References Notes.
|
virtual |
Get the SourceRanges associated with the report.
Reimplemented in clang::ento::retaincountchecker::RefCountReport.
Definition at line 2196 of file BugReporter.cpp.
Referenced by addRange(), and clang::ento::retaincountchecker::RefCountReport::getRanges().
Definition at line 211 of file BugReporter.h.
References ShortDescription.
const Stmt * BugReport::getStmt | ( | ) | const |
Definition at line 2178 of file BugReporter.cpp.
References clang::ProgramPoint::getAs(), clang::LocationContext::getCFG(), clang::CFG::getExit(), clang::ProgramPoint::getLocationContext(), GetPreviousStmt(), and clang::ento::PathDiagnosticLocation::getStmt().
Referenced by getUniqueingDecl().
|
inline |
Get the declaration containing the uniqueing location.
Definition at line 315 of file BugReporter.h.
References getStmt(), and UniqueingDecl.
|
inline |
Get the location on which the report should be uniqued.
Definition at line 310 of file BugReporter.h.
References UniqueingLocation.
Definition at line 2125 of file BugReporter.cpp.
Referenced by disablePathPruning().
Definition at line 2133 of file BugReporter.cpp.
References clang::ento::MemRegion::getBaseRegion().
Definition at line 2121 of file BugReporter.cpp.
References clang::ento::SVal::getAsRegion(), and clang::ento::SVal::getAsSymbol().
bool BugReport::isInteresting | ( | const LocationContext * | LC | ) |
Definition at line 2145 of file BugReporter.cpp.
|
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 205 of file BugReporter.h.
|
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 238 of file BugReporter.h.
void BugReport::markInteresting | ( | SymbolRef | sym | ) |
Definition at line 2089 of file BugReporter.cpp.
Referenced by disablePathPruning().
void BugReport::markInteresting | ( | const MemRegion * | R | ) |
Definition at line 2099 of file BugReporter.cpp.
References clang::ento::MemRegion::getBaseRegion().
void BugReport::markInteresting | ( | SVal | V | ) |
Definition at line 2110 of file BugReporter.cpp.
References clang::ento::SVal::getAsRegion(), and clang::ento::SVal::getAsSymbol().
void BugReport::markInteresting | ( | const LocationContext * | LC | ) |
Definition at line 2115 of file BugReporter.cpp.
|
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.
Definition at line 251 of file BugReporter.h.
References getDeclWithIssue().
|
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 2068 of file BugReporter.cpp.
References GetCurrentOrPreviousStmt(), clang::ento::PathDiagnosticLocation::isValid(), and clang::ento::PathDiagnosticLocation::Profile().
Referenced by visitor_end().
|
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 261 of file BugReporter.h.
|
inline |
Indicates whether or not any path pruning should take place when generating a PathDiagnostic from this BugReport.
Definition at line 219 of file BugReporter.h.
References DoNotPrunePath.
|
inline |
Iterators through the custom diagnostic visitors.
Definition at line 350 of file BugReporter.h.
|
inline |
Definition at line 351 of file BugReporter.h.
References Profile().
|
friend |
Definition at line 95 of file BugReporter.h.
|
friend |
Definition at line 96 of file BugReporter.h.
|
protected |
Definition at line 98 of file BugReporter.h.
Referenced by clang::ento::BugReporter::generatePathDiagnostics(), and getBugType().
|
protected |
A set of custom visitors which generate "event" diagnostics at interesting points in the path.
Definition at line 134 of file BugReporter.h.
|
protected |
Used for ensuring the visitors are only added once.
Definition at line 137 of file BugReporter.h.
|
protected |
Definition at line 99 of file BugReporter.h.
Referenced by clang::ento::BugReporter::generatePathDiagnostics().
|
protected |
Definition at line 101 of file BugReporter.h.
Referenced by getDescription().
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 142 of file BugReporter.h.
Referenced by shouldPrunePath().
|
protected |
Definition at line 106 of file BugReporter.h.
Referenced by getErrorNode().
|
protected |
Definition at line 108 of file BugReporter.h.
Referenced by getExtraText().
|
protected |
A set of location contexts that correspoind to call sites which should be considered "interesting".
Definition at line 130 of file BugReporter.h.
|
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 126 of file BugReporter.h.
|
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 119 of file BugReporter.h.
|
protected |
If non-empty, this bug report is likely a false positive and should not be shown to the user.
Definition at line 155 of file BugReporter.h.
|
protected |
Definition at line 102 of file BugReporter.h.
|
protected |
Definition at line 109 of file BugReporter.h.
Referenced by getNotes().
|
protected |
Definition at line 107 of file BugReporter.h.
Referenced by addNote(), and clang::ento::BugReporter::generatePathDiagnostics().
|
protected |
Definition at line 100 of file BugReporter.h.
Referenced by getShortDescription().
|
protected |
Definition at line 104 of file BugReporter.h.
Referenced by getUniqueingDecl().
|
protected |
Definition at line 103 of file BugReporter.h.
Referenced by getUniqueingLocation().