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

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

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

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  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 (BugType &bt, StringRef desc, const ExplodedNode *errorNode, PathDiagnosticLocation LocationToUnique, const Decl *DeclToUnique)
 Create a PathSensitiveBugReport with a custom uniqueing location. More...
 
const ExplodedNodegetErrorNode () 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 DeclgetUniqueingDecl () const override
 Get the declaration containing the uniqueing location. More...
 
const DeclgetDeclWithIssue () const override
 The smallest declaration that contains the bug location. More...
 
ArrayRef< SourceRangegetRanges () 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...
 
- Public Member Functions inherited from clang::ento::BugReport
virtual ~BugReport ()=default
 
Kind getKind () const
 
const BugTypegetBugType () 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< FixItHintgetFixits () 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 StmtgetStmt () 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 ExplodedNodeErrorNode = 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< 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...
 
PathDiagnosticLocation UniqueingLocation
 Reports with different uniqueing locations are considered to be different for the purposes of deduplication. More...
 
const DeclUniqueingDecl
 
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...
 
- Protected Attributes inherited from clang::ento::BugReport
Kind K
 
const BugTypeBT
 
std::string ShortDescription
 
std::string Description
 
SmallVector< SourceRange, 4 > Ranges
 
SmallVector< std::shared_ptr< PathDiagnosticNotePiece >, 4 > Notes
 
SmallVector< FixItHint, 4 > Fixits
 

Detailed Description

Definition at line 289 of file BugReporter.h.

Member Typedef Documentation

◆ InvalidationRecord

using clang::ento::PathSensitiveBugReport::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 341 of file BugReporter.h.

◆ visitor_iterator

Definition at line 292 of file BugReporter.h.

◆ visitor_range

Definition at line 293 of file BugReporter.h.

◆ VisitorList

Definition at line 291 of file BugReporter.h.

Constructor & Destructor Documentation

◆ PathSensitiveBugReport() [1/3]

clang::ento::PathSensitiveBugReport::PathSensitiveBugReport ( const BugType bt,
StringRef  desc,
const ExplodedNode errorNode 
)
inline

Definition at line 369 of file BugReporter.h.

◆ PathSensitiveBugReport() [2/3]

clang::ento::PathSensitiveBugReport::PathSensitiveBugReport ( const BugType bt,
StringRef  shortDesc,
StringRef  desc,
const ExplodedNode errorNode 
)
inline

Definition at line 375 of file BugReporter.h.

◆ PathSensitiveBugReport() [3/3]

clang::ento::PathSensitiveBugReport::PathSensitiveBugReport ( BugType bt,
StringRef  desc,
const ExplodedNode errorNode,
PathDiagnosticLocation  LocationToUnique,
const Decl DeclToUnique 
)
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.

Member Function Documentation

◆ addCallStackHint()

void clang::ento::PathSensitiveBugReport::addCallStackHint ( PathDiagnosticPieceRef  Piece,
std::unique_ptr< StackHintGenerator StackHint 
)
inline

Definition at line 511 of file BugReporter.h.

◆ addTrackedCondition()

bool clang::ento::PathSensitiveBugReport::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 507 of file BugReporter.h.

◆ 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.

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

Definition at line 2108 of file BugReporter.cpp.

◆ classof()

static bool clang::ento::PathSensitiveBugReport::classof ( const BugReport R)
inlinestatic

Definition at line 399 of file BugReporter.h.

References clang::ento::BugReport::getKind().

◆ clearVisitors()

void PathSensitiveBugReport::clearVisitors ( )

Remove all visitors attached to this bug report.

Definition at line 2124 of file BugReporter.cpp.

◆ disablePathPruning()

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

Disable all path pruning when generating a PathDiagnostic.

Definition at line 410 of file BugReporter.h.

◆ getCallStackMessage()

std::string clang::ento::PathSensitiveBugReport::getCallStackMessage ( PathDiagnosticPieceRef  Piece,
const ExplodedNode N 
) const
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.

◆ getDeclWithIssue()

const Decl * PathSensitiveBugReport::getDeclWithIssue ( ) const
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().

◆ getErrorNode()

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

Definition at line 403 of file BugReporter.h.

◆ getInterestingnessKind() [1/3]

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

Definition at line 2265 of file BugReporter.cpp.

◆ getInterestingnessKind() [2/3]

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

Definition at line 2277 of file BugReporter.cpp.

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

◆ getInterestingnessKind() [3/3]

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

◆ getLocation()

PathDiagnosticLocation PathSensitiveBugReport::getLocation ( ) const
overridevirtual

◆ getRanges()

ArrayRef< SourceRange > PathSensitiveBugReport::getRanges ( ) const
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().

◆ getStmt()

const Stmt * PathSensitiveBugReport::getStmt ( ) const
protected

◆ getUniqueingDecl()

const Decl* clang::ento::PathSensitiveBugReport::getUniqueingDecl ( ) const
inlineoverridevirtual

Get the declaration containing the uniqueing location.

Implements clang::ento::BugReport.

Definition at line 418 of file BugReporter.h.

References V.

◆ getUniqueingLocation()

PathDiagnosticLocation clang::ento::PathSensitiveBugReport::getUniqueingLocation ( ) const
inlineoverridevirtual

Get the location on which the report should be uniqued.

Implements clang::ento::BugReport.

Definition at line 413 of file BugReporter.h.

◆ hasCallStackHint()

bool clang::ento::PathSensitiveBugReport::hasCallStackHint ( PathDiagnosticPieceRef  Piece) const
inline

Definition at line 516 of file BugReporter.h.

◆ isInteresting() [1/4]

bool PathSensitiveBugReport::isInteresting ( SymbolRef  sym) const

Definition at line 2295 of file BugReporter.cpp.

◆ isInteresting() [2/4]

bool PathSensitiveBugReport::isInteresting ( const MemRegion R) const

Definition at line 2299 of file BugReporter.cpp.

◆ isInteresting() [3/4]

bool PathSensitiveBugReport::isInteresting ( SVal  V) const

Definition at line 2291 of file BugReporter.cpp.

◆ isInteresting() [4/4]

bool PathSensitiveBugReport::isInteresting ( const LocationContext LC) const

Definition at line 2303 of file BugReporter.cpp.

◆ isValid()

bool clang::ento::PathSensitiveBugReport::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 465 of file BugReporter.h.

◆ markInteresting() [1/4]

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().

◆ markInteresting() [2/4]

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).

◆ markInteresting() [3/4]

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).

◆ markInteresting() [4/4]

void PathSensitiveBugReport::markInteresting ( const LocationContext LC)

Definition at line 2233 of file BugReporter.cpp.

◆ markInvalid()

void clang::ento::PathSensitiveBugReport::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 478 of file BugReporter.h.

◆ Profile()

void PathSensitiveBugReport::Profile ( llvm::FoldingSetNodeID &  hash) const
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().

◆ shouldPrunePath()

bool clang::ento::PathSensitiveBugReport::shouldPrunePath ( ) const
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.

◆ visitor_begin()

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

Iterators through the custom diagnostic visitors.

Definition at line 500 of file BugReporter.h.

◆ visitor_end()

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

Definition at line 501 of file BugReporter.h.

◆ visitors()

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

Definition at line 502 of file BugReporter.h.

Member Data Documentation

◆ Callbacks

VisitorList clang::ento::PathSensitiveBugReport::Callbacks
protected

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

Definition at line 327 of file BugReporter.h.

◆ CallbacksSet

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

Used for ensuring the visitors are only added once.

Definition at line 330 of file BugReporter.h.

◆ DoNotPrunePath

bool clang::ento::PathSensitiveBugReport::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 335 of file BugReporter.h.

◆ ErrorNode

const ExplodedNode* clang::ento::PathSensitiveBugReport::ErrorNode = nullptr
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.

◆ ErrorNodeRange

const SourceRange clang::ento::PathSensitiveBugReport::ErrorNodeRange
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.

◆ InterestingLocationContexts

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

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

Definition at line 323 of file BugReporter.h.

◆ InterestingRegions

llvm::DenseMap<const MemRegion *, bugreporter::TrackingKind> clang::ento::PathSensitiveBugReport::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 319 of file BugReporter.h.

◆ InterestingSymbols

llvm::DenseMap<SymbolRef, bugreporter::TrackingKind> clang::ento::PathSensitiveBugReport::InterestingSymbols
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.

◆ Invalidations

llvm::SmallSet<InvalidationRecord, 4> clang::ento::PathSensitiveBugReport::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 348 of file BugReporter.h.

◆ StackHints

std::map<PathDiagnosticPieceRef, std::unique_ptr<StackHintGenerator> > clang::ento::PathSensitiveBugReport::StackHints
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.

◆ TrackedConditions

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

Conditions we're already tracking.

Definition at line 351 of file BugReporter.h.

◆ UniqueingDecl

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

Definition at line 356 of file BugReporter.h.

◆ UniqueingLocation

PathDiagnosticLocation clang::ento::PathSensitiveBugReport::UniqueingLocation
protected

Reports with different uniqueing locations are considered to be different for the purposes of deduplication.

Definition at line 355 of file BugReporter.h.


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