clang 20.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 > |
Public Types inherited from clang::ento::BugReport | |
enum class | Kind { Basic , 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. | |
PathSensitiveBugReport (const BugType &bt, StringRef shortDesc, StringRef desc, const ExplodedNode *errorNode, PathDiagnosticLocation LocationToUnique, const Decl *DeclToUnique) | |
const ExplodedNode * | getErrorNode () const |
bool | shouldPrunePath () const |
Indicates whether or not any path pruning should take place when generating a PathDiagnostic from this BugReport. | |
void | disablePathPruning () |
Disable all path pruning when generating a PathDiagnostic. | |
PathDiagnosticLocation | getUniqueingLocation () const override |
Get the location on which the report should be uniqued. | |
const Decl * | getUniqueingDecl () const override |
Get the declaration containing the uniqueing location. | |
const Decl * | getDeclWithIssue () const override |
The smallest declaration that contains the bug location. | |
ArrayRef< SourceRange > | getRanges () const override |
Get the SourceRanges associated with the report. | |
PathDiagnosticLocation | getLocation () const override |
The primary location of the bug report that points at the undesirable behavior in the code. | |
void | markInteresting (SymbolRef sym, bugreporter::TrackingKind TKind=bugreporter::TrackingKind::Thorough) |
Marks a symbol as interesting. | |
void | markNotInteresting (SymbolRef sym) |
void | markInteresting (const MemRegion *R, bugreporter::TrackingKind TKind=bugreporter::TrackingKind::Thorough) |
Marks a region as interesting. | |
void | markNotInteresting (const MemRegion *R) |
void | markInteresting (SVal V, bugreporter::TrackingKind TKind=bugreporter::TrackingKind::Thorough) |
Marks a symbolic value as interesting. | |
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 |
std::optional< bugreporter::TrackingKind > | getInterestingnessKind (SymbolRef sym) const |
std::optional< bugreporter::TrackingKind > | getInterestingnessKind (const MemRegion *R) const |
std::optional< bugreporter::TrackingKind > | getInterestingnessKind (SVal V) const |
bool | isValid () const |
Returns whether or not this report should be considered valid. | |
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. | |
void | Profile (llvm::FoldingSetNodeID &hash) const override |
Profile to identify equivalent bug reports for error report coalescing. | |
void | clearVisitors () |
Remove all visitors attached to this bug report. | |
visitor_iterator | visitor_begin () |
Iterators through the custom diagnostic visitors. | |
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. | |
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. | |
void | addVisitor (std::unique_ptr< BugReporterVisitor > visitor) |
Add custom or predefined bug report visitors to this report. | |
template<class VisitorType , class... Args> | |
void | addVisitor (Args &&... ConstructorArgs) |
Public Member Functions inherited from clang::ento::BugReport | |
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. | |
StringRef | getShortDescription (bool UseFallback=true) const |
A short general warning message that is appropriate for displaying in the list of all reported bugs. | |
virtual PathDiagnosticLocation | getLocation () const =0 |
The primary location of the bug report that points at the undesirable behavior in the code. | |
virtual const Decl * | getDeclWithIssue () const =0 |
The smallest declaration that contains the bug location. | |
virtual PathDiagnosticLocation | getUniqueingLocation () const =0 |
Get the location on which the report should be uniqued. | |
virtual const Decl * | getUniqueingDecl () const =0 |
Get the declaration that corresponds to (usually contains) the uniqueing location. | |
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. | |
ArrayRef< std::shared_ptr< PathDiagnosticNotePiece > > | getNotes () |
void | addRange (SourceRange R) |
Add a range to a bug report. | |
virtual ArrayRef< SourceRange > | getRanges () const |
Get the SourceRanges associated with the report. | |
void | addFixItHint (const FixItHint &F) |
Add a fix-it hint to the bug report. | |
llvm::ArrayRef< FixItHint > | getFixits () const |
virtual void | Profile (llvm::FoldingSetNodeID &hash) const =0 |
Reports are uniqued to ensure that we do not emit multiple diagnostics for each bug. | |
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. | |
Protected Member Functions | |
const Stmt * | getStmt () const |
Protected Member Functions inherited from clang::ento::BugReport | |
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. | |
const SourceRange | ErrorNodeRange |
The range that corresponds to ErrorNode's program point. | |
llvm::DenseMap< SymbolRef, bugreporter::TrackingKind > | InterestingSymbols |
Profile to identify equivalent bug reports for error report coalescing. | |
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. | |
llvm::SmallSet< const LocationContext *, 2 > | InterestingLocationContexts |
A set of location contexts that correspoind to call sites which should be considered "interesting". | |
VisitorList | Callbacks |
A set of custom visitors which generate "event" diagnostics at interesting points in the path. | |
llvm::FoldingSet< BugReporterVisitor > | CallbacksSet |
Used for ensuring the visitors are only added once. | |
bool | DoNotPrunePath = false |
When set, this flag disables all callstack pruning from a diagnostic path. | |
llvm::SmallSet< InvalidationRecord, 4 > | Invalidations |
If non-empty, this bug report is likely a false positive and should not be shown to the user. | |
llvm::SmallSet< const ExplodedNode *, 4 > | TrackedConditions |
Conditions we're already tracking. | |
PathDiagnosticLocation | UniqueingLocation |
Reports with different uniqueing locations are considered to be different for the purposes of deduplication. | |
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. | |
Protected Attributes inherited from clang::ento::BugReport | |
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 373 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 386 of file BugReporter.h.
PathSensitiveBugReport::PathSensitiveBugReport | ( | const BugType & | bt, |
StringRef | shortDesc, | ||
StringRef | desc, | ||
const ExplodedNode * | errorNode, | ||
PathDiagnosticLocation | LocationToUnique, | ||
const Decl * | DeclToUnique | ||
) |
Definition at line 2143 of file BugReporter.cpp.
References ErrorNode, clang::ento::BugType::getCheckerName(), clang::ento::ExplodedNode::getState(), isDependency(), and isHidden().
|
inline |
Definition at line 519 of file BugReporter.h.
References StackHints.
|
inline |
Notes that the condition of the CFGBlock associated with Cond
is being tracked.
Definition at line 515 of file BugReporter.h.
References TrackedConditions.
|
inline |
Definition at line 498 of file BugReporter.h.
References addVisitor().
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 2169 of file BugReporter.cpp.
References Callbacks, and CallbacksSet.
Referenced by addVisitor(), and clang::ento::bugreporter::Tracker::track().
Definition at line 398 of file BugReporter.h.
References clang::ento::BugReport::getKind(), and clang::ento::BugReport::PathSensitive.
void PathSensitiveBugReport::clearVisitors | ( | ) |
Remove all visitors attached to this bug report.
Definition at line 2185 of file BugReporter.cpp.
References Callbacks.
Referenced by generateVisitorsDiagnostics().
|
inline |
Disable all path pruning when generating a PathDiagnostic.
Definition at line 409 of file BugReporter.h.
References DoNotPrunePath.
|
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 531 of file BugReporter.h.
References I, and StackHints.
|
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 2189 of file BugReporter.cpp.
References clang::LocationContext::getDecl(), getErrorNode(), clang::ento::ExplodedNode::getLocationContext(), and clang::LocationContext::getStackFrame().
Referenced by generateEmptyDiagnosticForReport().
|
inline |
Definition at line 402 of file BugReporter.h.
References ErrorNode.
Referenced by generateEmptyDiagnosticForReport(), getDeclWithIssue(), clang::ento::errno_modeling::getErrnoNoteTag(), isVarAnInterestingCondition(), and clang::ento::SuppressInlineDefensiveChecksVisitor::VisitNode().
std::optional< bugreporter::TrackingKind > PathSensitiveBugReport::getInterestingnessKind | ( | const MemRegion * | R | ) | const |
Definition at line 2363 of file BugReporter.cpp.
References clang::ento::MemRegion::getBaseRegion(), getInterestingnessKind(), and InterestingRegions.
std::optional< bugreporter::TrackingKind > PathSensitiveBugReport::getInterestingnessKind | ( | SVal | V | ) | const |
Definition at line 2326 of file BugReporter.cpp.
References clang::ento::bugreporter::Condition, getInterestingnessKind(), clang::ento::bugreporter::Thorough, and V.
std::optional< bugreporter::TrackingKind > PathSensitiveBugReport::getInterestingnessKind | ( | SymbolRef | sym | ) | const |
Definition at line 2351 of file BugReporter.cpp.
References InterestingSymbols.
Referenced by getInterestingnessKind(), isInteresting(), isInterestingExpr(), and isVarAnInterestingCondition().
|
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 2424 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(), ErrorNode, clang::ento::ExplodedNode::getLocation(), clang::ento::ExplodedNode::getLocationContext(), clang::ento::ExplodedNode::getNextStmtForDiagnostics(), clang::ento::ExplodedNode::getState(), clang::ento::ExplodedNode::getStmtForDiagnostics(), clang::ento::PathDiagnosticLocation::getValidSourceLocation(), P, and SM.
Referenced by clang::ento::LikelyFalsePositiveSuppressionBRVisitor::finalizeVisitor(), clang::ento::BugReporterVisitor::getDefaultEndPath(), and 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 2414 of file BugReporter.cpp.
References ErrorNodeRange, getStmt(), and clang::ento::BugReport::Ranges.
Referenced by clang::ento::BugReporterVisitor::getDefaultEndPath(), and clang::ento::retaincountchecker::RefCountReport::getRanges().
|
protected |
Definition at line 2395 of file BugReporter.cpp.
References ErrorNode, clang::ProgramPoint::getAs(), clang::LocationContext::getCFG(), clang::CFG::getExit(), clang::ento::ExplodedNode::getLocation(), clang::ProgramPoint::getLocationContext(), clang::ento::ExplodedNode::getPreviousStmtForDiagnostics(), and clang::ento::ExplodedNode::getStmtForDiagnostics().
Referenced by getRanges().
|
inlineoverridevirtual |
Get the declaration containing the uniqueing location.
Implements clang::ento::BugReport.
Definition at line 417 of file BugReporter.h.
References UniqueingDecl.
Referenced by generateEmptyDiagnosticForReport().
|
inlineoverridevirtual |
Get the location on which the report should be uniqued.
Implements clang::ento::BugReport.
Definition at line 412 of file BugReporter.h.
References UniqueingLocation.
Referenced by generateEmptyDiagnosticForReport(), and Profile().
|
inline |
Definition at line 524 of file BugReporter.h.
References StackHints.
bool PathSensitiveBugReport::isInteresting | ( | const LocationContext * | LC | ) | const |
Definition at line 2389 of file BugReporter.cpp.
References InterestingLocationContexts.
Definition at line 2385 of file BugReporter.cpp.
References getInterestingnessKind().
Definition at line 2377 of file BugReporter.cpp.
References getInterestingnessKind(), and V.
Definition at line 2381 of file BugReporter.cpp.
References getInterestingnessKind().
Referenced by clang::ento::errno_modeling::getErrnoNoteTag(), clang::ento::ConditionBRVisitor::patternMatch(), and removeUnneededCalls().
|
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 468 of file BugReporter.h.
References Invalidations.
Referenced by generateVisitorsDiagnostics().
void PathSensitiveBugReport::markInteresting | ( | const LocationContext * | LC | ) |
Definition at line 2319 of file BugReporter.cpp.
References InterestingLocationContexts.
void 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).
Definition at line 2290 of file BugReporter.cpp.
References clang::ento::MemRegion::getBaseRegion(), insertToInterestingnessMap(), InterestingRegions, and markInteresting().
void 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).
Definition at line 2313 of file BugReporter.cpp.
References markInteresting(), and V.
void 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).
Definition at line 2265 of file BugReporter.cpp.
References insertToInterestingnessMap(), InterestingSymbols, and markInteresting().
Referenced by clang::ento::retaincountchecker::RefCountReportVisitor::getEndPath(), clang::ento::retaincountchecker::RefLeakReportVisitor::getEndPath(), markInteresting(), and clang::ento::UndefOrNullArgVisitor::VisitNode().
|
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 481 of file BugReporter.h.
References clang::Data, and Invalidations.
Referenced by clang::ento::LikelyFalsePositiveSuppressionBRVisitor::finalizeVisitor(), clang::ento::NoStateChangeFuncVisitor::VisitNode(), and clang::ento::SuppressInlineDefensiveChecksVisitor::VisitNode().
void PathSensitiveBugReport::markNotInteresting | ( | const MemRegion * | R | ) |
Definition at line 2302 of file BugReporter.cpp.
References clang::ento::MemRegion::getBaseRegion(), InterestingRegions, and markNotInteresting().
void PathSensitiveBugReport::markNotInteresting | ( | SymbolRef | sym | ) |
Definition at line 2278 of file BugReporter.cpp.
References InterestingSymbols, and markNotInteresting().
Referenced by markNotInteresting().
|
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 2213 of file BugReporter.cpp.
References clang::ento::BugReport::BT, ErrorNode, clang::ento::ExplodedNode::getCurrentOrPreviousStmtForDiagnostics(), clang::ento::BugReport::getKind(), clang::ento::BugReport::getShortDescription(), getUniqueingLocation(), clang::ento::PathDiagnosticLocation::isValid(), clang::ento::PathDiagnosticLocation::Profile(), and clang::ento::BugReport::Ranges.
|
inline |
Indicates whether or not any path pruning should take place when generating a PathDiagnostic from this BugReport.
Definition at line 406 of file BugReporter.h.
References DoNotPrunePath.
|
inline |
Iterators through the custom diagnostic visitors.
Definition at line 508 of file BugReporter.h.
References Callbacks.
Referenced by visitors().
|
inline |
|
inline |
Definition at line 510 of file BugReporter.h.
References visitor_begin(), and visitor_end().
Referenced by generateVisitorsDiagnostics().
|
protected |
A set of custom visitors which generate "event" diagnostics at interesting points in the path.
Definition at line 327 of file BugReporter.h.
Referenced by addVisitor(), clearVisitors(), visitor_begin(), and visitor_end().
|
protected |
Used for ensuring the visitors are only added once.
Definition at line 330 of file BugReporter.h.
Referenced by addVisitor().
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.
Referenced by disablePathPruning(), and shouldPrunePath().
|
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.
Referenced by getErrorNode(), getLocation(), getStmt(), PathSensitiveBugReport(), and Profile().
|
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.
Referenced by getRanges().
|
protected |
A set of location contexts that correspoind to call sites which should be considered "interesting".
Definition at line 323 of file BugReporter.h.
Referenced by isInteresting(), and markInteresting().
|
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.
Referenced by getInterestingnessKind(), markInteresting(), and markNotInteresting().
|
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.
Referenced by getInterestingnessKind(), markInteresting(), and markNotInteresting().
|
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.
Referenced by isValid(), and markInvalid().
|
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.
Referenced by addCallStackHint(), getCallStackMessage(), and hasCallStackHint().
|
protected |
Conditions we're already tracking.
Definition at line 351 of file BugReporter.h.
Referenced by addTrackedCondition().
|
protected |
Definition at line 356 of file BugReporter.h.
Referenced by getUniqueingDecl().
|
protected |
Reports with different uniqueing locations are considered to be different for the purposes of deduplication.
Definition at line 355 of file BugReporter.h.
Referenced by getUniqueingLocation().