clang
10.0.0git
|
#include "clang/StaticAnalyzer/Core/BugReporter/BugReporter.h"
Public Types | |
using | VisitorList = SmallVector< std::unique_ptr< BugReporterVisitor >, 8 > |
using | visitor_iterator = VisitorList::iterator |
using | visitor_range = llvm::iterator_range< visitor_iterator > |
![]() | |
enum | Kind { Kind::Basic, Kind::PathSensitive } |
Public Member Functions | |
PathSensitiveBugReport (const BugType &bt, StringRef desc, const ExplodedNode *errorNode) | |
PathSensitiveBugReport (const BugType &bt, StringRef shortDesc, StringRef desc, const ExplodedNode *errorNode) | |
PathSensitiveBugReport (const BugType &bt, StringRef desc, const ExplodedNode *errorNode, PathDiagnosticLocation LocationToUnique, const Decl *DeclToUnique) | |
Create a PathSensitiveBugReport with a custom uniqueing location. More... | |
const ExplodedNode * | getErrorNode () 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... | |
PathDiagnosticLocation | getUniqueingLocation () const override |
Get the location on which the report should be uniqued. More... | |
const Decl * | getUniqueingDecl () const override |
Get the declaration containing the uniqueing location. More... | |
const Decl * | getDeclWithIssue () const override |
The smallest declaration that contains the bug location. More... | |
ArrayRef< SourceRange > | getRanges () const override |
Get the SourceRanges associated with the report. More... | |
PathDiagnosticLocation | getLocation () const override |
The primary location of the bug report that points at the undesirable behavior in the code. 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... | |
void | Profile (llvm::FoldingSetNodeID &hash) const override |
Profile to identify equivalent bug reports for error report coalescing. 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... | |
void | addCallStackHint (PathDiagnosticPieceRef Piece, std::unique_ptr< StackHintGenerator > StackHint) |
bool | hasCallStackHint (PathDiagnosticPieceRef Piece) const |
std::string | getCallStackMessage (PathDiagnosticPieceRef Piece, const ExplodedNode *N) const |
Produce the hint for the given node. More... | |
![]() | |
virtual | ~BugReport ()=default |
Kind | getKind () const |
const BugType & | getBugType () const |
StringRef | getDescription () const |
A verbose warning message that is appropriate for displaying next to the source code that introduces the problem. More... | |
StringRef | getShortDescription (bool UseFallback=true) const |
A short general warning message that is appropriate for displaying in the list of all reported bugs. 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 report. More... | |
ArrayRef< std::shared_ptr< PathDiagnosticNotePiece > > | getNotes () |
void | addRange (SourceRange R) |
Add a range to a bug report. More... | |
void | addFixItHint (const FixItHint &F) |
Add a fix-it hint to the bug report. More... | |
llvm::ArrayRef< FixItHint > | getFixits () const |
Static Public Member Functions | |
static bool | classof (const BugReport *R) |
Protected Types | |
using | InvalidationRecord = std::pair< const void *, const void * > |
Used to track unique reasons why a bug report might be invalid. More... | |
Protected Member Functions | |
const Stmt * | getStmt () const |
![]() | |
BugReport (Kind kind, const BugType &bt, StringRef desc) | |
BugReport (Kind K, const BugType &BT, StringRef ShortDescription, StringRef Description) | |
Protected Attributes | |
const ExplodedNode * | ErrorNode = nullptr |
The ExplodedGraph node against which the report was thrown. More... | |
const SourceRange | ErrorNodeRange |
The range that corresponds to ErrorNode's program point. More... | |
llvm::DenseMap< SymbolRef, bugreporter::TrackingKind > | InterestingSymbols |
Profile to identify equivalent bug reports for error report coalescing. 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< 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... | |
llvm::SmallSet< const ExplodedNode *, 4 > | TrackedConditions |
Conditions we're already tracking. More... | |
PathDiagnosticLocation | UniqueingLocation |
Reports with different uniqueing locations are considered to be different for the purposes of deduplication. More... | |
const Decl * | UniqueingDecl |
std::map< PathDiagnosticPieceRef, std::unique_ptr< StackHintGenerator > > | StackHints |
If an event occurs in a different frame than the final diagnostic, supply a message that will be used to construct an extra hint on the returns from all the calls on the stack from this event to the final diagnostic. More... | |
![]() | |
Kind | K |
const BugType & | BT |
std::string | ShortDescription |
std::string | Description |
SmallVector< SourceRange, 4 > | Ranges |
SmallVector< std::shared_ptr< PathDiagnosticNotePiece >, 4 > | Notes |
SmallVector< FixItHint, 4 > | Fixits |
Definition at line 289 of file BugReporter.h.
|
protected |
Used to track unique reasons why a bug report might be invalid.
Definition at line 341 of file BugReporter.h.
using clang::ento::PathSensitiveBugReport::visitor_iterator = VisitorList::iterator |
Definition at line 292 of file BugReporter.h.
using clang::ento::PathSensitiveBugReport::visitor_range = llvm::iterator_range<visitor_iterator> |
Definition at line 293 of file BugReporter.h.
using clang::ento::PathSensitiveBugReport::VisitorList = SmallVector<std::unique_ptr<BugReporterVisitor>, 8> |
Definition at line 291 of file BugReporter.h.
|
inline |
Definition at line 369 of file BugReporter.h.
|
inline |
Definition at line 375 of file BugReporter.h.
|
inline |
Create a PathSensitiveBugReport 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 389 of file BugReporter.h.
|
inline |
Definition at line 511 of file BugReporter.h.
|
inline |
Notes that the condition of the CFGBlock associated with Cond
is being tracked.
Definition at line 507 of file BugReporter.h.
void PathSensitiveBugReport::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 2108 of file BugReporter.cpp.
Definition at line 399 of file BugReporter.h.
References clang::ento::BugReport::getKind().
void PathSensitiveBugReport::clearVisitors | ( | ) |
Remove all visitors attached to this bug report.
Definition at line 2124 of file BugReporter.cpp.
|
inline |
Disable all path pruning when generating a PathDiagnostic.
Definition at line 410 of file BugReporter.h.
|
inline |
Produce the hint for the given node.
The node contains information about the call for which the diagnostic can be generated.
Definition at line 523 of file BugReporter.h.
|
overridevirtual |
The smallest declaration that contains the bug location.
This is purely cosmetic; the declaration can be displayed to the user but it does not affect whether the report is emitted.
Implements clang::ento::BugReport.
Definition at line 2128 of file BugReporter.cpp.
References clang::LocationContext::getDecl(), clang::ento::ExplodedNode::getLocationContext(), and clang::LocationContext::getStackFrame().
|
inline |
Definition at line 403 of file BugReporter.h.
Optional< bugreporter::TrackingKind > PathSensitiveBugReport::getInterestingnessKind | ( | SymbolRef | sym | ) | const |
Definition at line 2265 of file BugReporter.cpp.
Optional< bugreporter::TrackingKind > PathSensitiveBugReport::getInterestingnessKind | ( | const MemRegion * | R | ) | const |
Definition at line 2277 of file BugReporter.cpp.
References clang::ento::MemRegion::getBaseRegion().
Optional< bugreporter::TrackingKind > PathSensitiveBugReport::getInterestingnessKind | ( | SVal | V | ) | const |
Definition at line 2240 of file BugReporter.cpp.
References clang::ento::SVal::getAsRegion(), and clang::ento::SVal::getAsSymbol().
|
overridevirtual |
The primary location of the bug report that points at the undesirable behavior in the code.
UIs should attach the warning description to this location. The warning description should describe the bad behavior at this location.
Implements clang::ento::BugReport.
Reimplemented in clang::ento::retaincountchecker::RefLeakReport.
Definition at line 2338 of file BugReporter.cpp.
References clang::ento::PathDiagnosticLocation::createBegin(), clang::ento::PathDiagnosticLocation::createDeclEnd(), clang::ento::PathDiagnosticLocation::createEnd(), clang::ento::PathDiagnosticLocation::createMemberLoc(), clang::ento::PathDiagnosticLocation::createOperatorLoc(), clang::ProgramPoint::getAs(), clang::Stmt::getBeginLoc(), clang::ProgramPoint::getLocationContext(), clang::ento::PathDiagnosticLocation::getValidSourceLocation(), clang::SourceLocation::isValid(), and SM.
Referenced by clang::ento::retaincountchecker::RefLeakReport::getEndOfPath().
|
overridevirtual |
Get the SourceRanges associated with the report.
Reimplemented from clang::ento::BugReport.
Reimplemented in clang::ento::retaincountchecker::RefCountReport.
Definition at line 2328 of file BugReporter.cpp.
Referenced by clang::ento::retaincountchecker::RefCountReport::getRanges().
|
protected |
Definition at line 2309 of file BugReporter.cpp.
References clang::ProgramPoint::getAs(), clang::LocationContext::getCFG(), clang::CFG::getExit(), and clang::ProgramPoint::getLocationContext().
|
inlineoverridevirtual |
Get the declaration containing the uniqueing location.
Implements clang::ento::BugReport.
Definition at line 418 of file BugReporter.h.
References V.
|
inlineoverridevirtual |
Get the location on which the report should be uniqued.
Implements clang::ento::BugReport.
Definition at line 413 of file BugReporter.h.
|
inline |
Definition at line 516 of file BugReporter.h.
Definition at line 2295 of file BugReporter.cpp.
Definition at line 2299 of file BugReporter.cpp.
Definition at line 2291 of file BugReporter.cpp.
bool PathSensitiveBugReport::isInteresting | ( | const LocationContext * | LC | ) | const |
Definition at line 2303 of file BugReporter.cpp.
|
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 465 of file BugReporter.h.
void clang::ento::PathSensitiveBugReport::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 insertToInterestingnessMap().
void clang::ento::PathSensitiveBugReport::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).
void clang::ento::PathSensitiveBugReport::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).
void PathSensitiveBugReport::markInteresting | ( | const LocationContext * | LC | ) |
Definition at line 2233 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 478 of file BugReporter.h.
|
overridevirtual |
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.
Implements clang::ento::BugReport.
Definition at line 2152 of file BugReporter.cpp.
References getKind(), clang::ento::PathDiagnosticLocation::isValid(), clang::ento::PathDiagnosticLocation::Profile(), and clang::transformer::range().
|
inline |
Indicates whether or not any path pruning should take place when generating a PathDiagnostic from this BugReport.
Definition at line 407 of file BugReporter.h.
|
inline |
Iterators through the custom diagnostic visitors.
Definition at line 500 of file BugReporter.h.
|
inline |
Definition at line 501 of file BugReporter.h.
|
inline |
Definition at line 502 of file BugReporter.h.
|
protected |
A set of custom visitors which generate "event" diagnostics at interesting points in the path.
Definition at line 327 of file BugReporter.h.
|
protected |
Used for ensuring the visitors are only added once.
Definition at line 330 of file BugReporter.h.
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 335 of file BugReporter.h.
|
protected |
The ExplodedGraph node against which the report was thrown.
It corresponds to the end of the execution path that demonstrates the bug.
Definition at line 298 of file BugReporter.h.
|
protected |
The range that corresponds to ErrorNode's program point.
It is usually highlighted in the report.
Definition at line 302 of file BugReporter.h.
|
protected |
A set of location contexts that correspoind to call sites which should be considered "interesting".
Definition at line 323 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 319 of file BugReporter.h.
|
protected |
Profile to identify equivalent bug reports for error report coalescing.
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 311 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 348 of file BugReporter.h.
|
protected |
If an event occurs in a different frame than the final diagnostic, supply a message that will be used to construct an extra hint on the returns from all the calls on the stack from this event to the final diagnostic.
Definition at line 366 of file BugReporter.h.
|
protected |
Conditions we're already tracking.
Definition at line 351 of file BugReporter.h.
|
protected |
Definition at line 356 of file BugReporter.h.
|
protected |
Reports with different uniqueing locations are considered to be different for the purposes of deduplication.
Definition at line 355 of file BugReporter.h.