15 #ifndef LLVM_CLANG_STATICANALYZER_CORE_BUGREPORTER_BUGREPORTER_H
16 #define LLVM_CLANG_STATICANALYZER_CORE_BUGREPORTER_BUGREPORTER_H
24 #include "llvm/ADT/DenseSet.h"
25 #include "llvm/ADT/FoldingSet.h"
26 #include "llvm/ADT/ImmutableSet.h"
27 #include "llvm/ADT/SmallSet.h"
28 #include "llvm/ADT/ilist.h"
29 #include "llvm/ADT/ilist_node.h"
34 class DiagnosticsEngine;
45 class BugReporterContext;
55 class BugReport :
public llvm::ilist_node<BugReport> {
58 virtual void anchor();
138 Symbols &getInterestingSymbols();
139 Regions &getInterestingRegions();
141 void lazyInitializeInterestingSets();
142 void pushInterestingSymbolsAndRegions();
143 void popInterestingSymbolsAndRegions();
287 assert((R.
isValid() ||
Ranges.empty()) &&
"Invalid range can only be used "
288 "to specify that the report does not have a range.");
293 virtual llvm::iterator_range<ranges_iterator>
getRanges();
302 void addVisitor(std::unique_ptr<BugReporterVisitor> visitor);
311 virtual void Profile(llvm::FoldingSetNodeID& hash)
const;
318 template<>
struct ilist_traits<clang::ento::BugReport>
326 return createSentinel();
329 return createSentinel();
332 mutable ilist_half_node<clang::ento::BugReport> Sentinel;
345 llvm::ilist<BugReport> Reports;
348 void AddReport(std::unique_ptr<BugReport> R) {
349 Reports.push_back(R.release());
357 assert(!Reports.empty());
358 Reports.front().Profile(ID);
394 BugTypesTy::Factory F;
405 void FlushReport(
BugReport *exampleReport,
410 llvm::FoldingSet<BugReportEquivClass> EQClasses;
412 std::vector<BugReportEquivClass *> EQClassesVector;
467 void emitReport(std::unique_ptr<BugReport> R);
470 StringRef BugName, StringRef BugCategory,
475 StringRef BugName, StringRef BugCategory,
480 llvm::StringMap<BugType *> StrBugTypes;
527 virtual void anchor();
VisitorList::iterator visitor_iterator
BugReporter(BugReporterData &d)
unsigned getConfigurationChangeToken() const
const Decl * getDeclWithIssue() const
Return the canonical declaration, be it a method or class, where this issue semantically occurred...
const SourceRange * ranges_iterator
MemRegion - The root abstract class for all memory regions.
ASTContext & getASTContext()
bool isInteresting(SymbolRef sym)
llvm::DenseSet< SymbolRef > Symbols
const ExplodedNode * getErrorNode() const
virtual PathDiagnosticLocation getLocation(const SourceManager &SM) const
Return the "definitive" location of the reported bug.
BugReport(BugType &bt, StringRef shortDesc, StringRef desc, const ExplodedNode *errornode)
ArrayRef< PathDiagnosticConsumer * > getPathDiagnosticConsumers()
void disablePathPruning()
Disable all path pruning when generating a PathDiagnostic.
SmallVector< SourceRange, 4 > Ranges
virtual AnalyzerOptions & getAnalyzerOptions()=0
bool shouldPrunePath() const
Indicates whether or not any path pruning should take place when generating a PathDiagnostic from thi...
PathDiagnostic - PathDiagnostic objects represent a single path-sensitive diagnostic.
const Decl * getUniqueingDecl() const
Get the declaration containing the uniqueing location.
clang::ento::BugReport * createSentinel() const
void addRange(SourceRange R)
Add a range to a bug report.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
BugReport(BugType &bt, StringRef desc, const ExplodedNode *errornode, PathDiagnosticLocation LocationToUnique, const Decl *DeclToUnique)
Create a BugReport with a custom uniqueing location.
const BugType & getBugType() const
std::string ShortDescription
virtual DiagnosticsEngine & getDiagnostic()=0
llvm::SmallSet< InvalidationRecord, 4 > Invalidations
If non-empty, this bug report is likely a false positive and should not be shown to the user...
SValBuilder & getSValBuilder()
const Stmt * getStmt() const
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.
virtual llvm::iterator_range< ranges_iterator > getRanges()
Get the SourceRanges associated with the report.
llvm::FoldingSet< BugReporterVisitor > CallbacksSet
Used for ensuring the visitors are only added once.
llvm::SmallSet< const LocationContext *, 2 > InterestingLocationContexts
A set of location contexts that correspoind to call sites which should be considered "interesting"...
BugReporter(BugReporterData &d, Kind k)
ASTContext & getContext()
const_iterator end() const
Concrete class used by the front-end to report problems and issues.
ExplodedGraph & getGraph()
llvm::FoldingSet< BugReportEquivClass >::iterator EQClasses_iterator
Iterator over the set of BugReports tracked by the BugReporter.
GRBugReporter(BugReporterData &d, ExprEngine &eng)
StringRef getDescription() const
StringRef getShortDescription(bool UseFallback=true) const
BugReporterContext(GRBugReporter &br)
virtual BugReport::NodeResolver & getNodeResolver()=0
void addVisitor(std::unique_ptr< BugReporterVisitor > visitor)
Add custom or predefined bug report visitors to this report.
const_iterator begin() const
const Decl * UniqueingDecl
BugReportEquivClass(std::unique_ptr< BugReport > R)
bool DoNotPrunePath
When set, this flag disables all callstack pruning from a diagnostic path.
virtual const ExtraTextList & getExtraText()
visitor_iterator visitor_end()
void Profile(llvm::FoldingSetNodeID &ID) const
~GRBugReporter() override
visitor_iterator visitor_begin()
Iterators through the custom diagnostic visitors.
BugReport(BugType &bt, StringRef desc, PathDiagnosticLocation l)
virtual SourceManager & getSourceManager()=0
void Register(BugType *BT)
unsigned ConfigurationChangeToken
Used for clients to tell if the report's configuration has changed since the last time they checked...
void FlushReports()
Generate and flush diagnostics for all bug reports.
SValBuilder & getSValBuilder()
virtual bool generatePathDiagnostic(PathDiagnostic &pathDiagnostic, PathDiagnosticConsumer &PC, ArrayRef< BugReport * > &bugReports)
void markInteresting(SymbolRef sym)
AnalyzerOptions & getAnalyzerOptions()
clang::ento::BugReport * provideInitialHead() const
virtual ArrayRef< PathDiagnosticConsumer * > getPathDiagnosticConsumers()=0
llvm::ilist< BugReport >::iterator iterator
BugReporter is a utility class for generating PathDiagnostics for analysis.
PathDiagnosticLocation UniqueingLocation
static bool classof(const BugReporter *R)
classof - Used by isa<>, cast<>, and dyn_cast<>.
llvm::DenseSet< const MemRegion * > Regions
EQClasses_iterator EQClasses_begin()
void EmitBasicReport(const Decl *DeclWithIssue, const CheckerBase *Checker, StringRef BugName, StringRef BugCategory, StringRef BugStr, PathDiagnosticLocation Loc, ArrayRef< SourceRange > Ranges=None)
const TemplateArgument * iterator
const ExplodedNode * ErrorNode
ExplodedGraph & getGraph()
getGraph - Get the exploded graph created by the analysis engine for the analyzed method or function...
void emitReport(std::unique_ptr< BugReport > R)
Add the given report to the set of reports tracked by BugReporter.
BugTypesTy::iterator iterator
Iterator over the set of BugTypes tracked by the BugReporter.
SVal - This represents a symbolic expression, which can be either an L-value or an R-value...
bool generatePathDiagnostic(PathDiagnostic &PD, PathDiagnosticConsumer &PC, ArrayRef< BugReport * > &bugReports) override
Generates a path corresponding to one of the given bug reports.
PathDiagnosticLocation Location
const Decl * DeclWithIssue
VisitorList Callbacks
A set of custom visitors which generate "event" diagnostics at interesting points in the path...
std::pair< const void *, const void * > InvalidationRecord
Used to track unique reasons why a bug report might be invalid.
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.
virtual void Profile(llvm::FoldingSetNodeID &hash) const
Profile to identify equivalent bug reports for error report coalescing.
virtual ~BugReporterData()
GRBugReporter & getBugReporter()
PathDiagnosticLocation getUniqueingLocation() const
Get the location on which the report should be uniqued.
llvm::ilist< BugReport >::const_iterator const_iterator
virtual ~BugReporterContext()
DiagnosticsEngine & getDiagnostic()
ProgramStateManager & getStateManager()
EQClasses_iterator EQClasses_end()
bool RemoveUnneededCalls(PathPieces &pieces, BugReport *R)
SourceManager & getSourceManager()
ProgramStateManager & getStateManager()
getStateManager - Return the state manager used by the analysis engine.
BugReport(BugType &bt, StringRef desc, const ExplodedNode *errornode)
Defines the clang::SourceLocation class and associated facilities.
void addExtraText(StringRef S)
This allows for addition of meta data to the diagnostic.
void removeInvalidation(const void *Tag, const void *Data)
Reverses the effects of a previous invalidation.
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 r...
clang::ento::BugReport * ensureHead(clang::ento::BugReport *) const
virtual const ExplodedNode * getOriginalNode(const ExplodedNode *N)=0
void destroySentinel(clang::ento::BugReport *) const
SmallVector< StringRef, 2 > ExtraTextList
A trivial tuple used to represent a source range.
This class provides an interface through which checkers can create individual bug reports...
SmallVector< std::unique_ptr< BugReporterVisitor >, 8 > VisitorList
bool isValid() const
Returns whether or not this report should be considered valid.
This class handles loading and caching of source files into memory.
virtual ASTContext & getASTContext()=0
SourceManager & getSourceManager()
void setDeclWithIssue(const Decl *declWithIssue)
Specifically set the Decl where an issue occurred.
ExprEngine & getEngine()
getEngine - Return the analysis engine used to analyze a given function or method.