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();
140 Symbols &getInterestingSymbols();
141 Regions &getInterestingRegions();
143 void lazyInitializeInterestingSets();
144 void pushInterestingSymbolsAndRegions();
145 void popInterestingSymbolsAndRegions();
149 : BT(bt), DeclWithIssue(nullptr), Description(desc), ErrorNode(errornode),
150 ConfigurationChangeToken(0), DoNotPrunePath(
false) {}
154 : BT(bt), DeclWithIssue(nullptr), ShortDescription(shortDesc),
155 Description(desc), ErrorNode(errornode), ConfigurationChangeToken(0),
156 DoNotPrunePath(
false) {}
159 : BT(bt), DeclWithIssue(nullptr), Description(desc), Location(l),
160 ErrorNode(nullptr), ConfigurationChangeToken(0), DoNotPrunePath(
false) {}
171 : BT(bt), DeclWithIssue(nullptr), Description(desc),
172 UniqueingLocation(LocationToUnique),
173 UniqueingDecl(DeclToUnique),
174 ErrorNode(errornode), ConfigurationChangeToken(0),
175 DoNotPrunePath(
false) {}
199 if (ShortDescription.empty() && UseFallback)
230 return Invalidations.empty();
243 Invalidations.insert(std::make_pair(Tag, Data));
250 Invalidations.erase(std::make_pair(Tag, Data));
260 DeclWithIssue = declWithIssue;
270 auto P = std::make_shared<PathDiagnosticNotePiece>(Pos, Msg);
272 for (
const auto &R : Ranges)
275 Notes.push_back(std::move(
P));
281 std::vector<SourceRange>
Ranges;
293 ExtraText.push_back(S);
327 assert((R.
isValid() || Ranges.empty()) &&
"Invalid range can only be used " 328 "to specify that the report does not have a range.");
333 virtual llvm::iterator_range<ranges_iterator>
getRanges();
342 void addVisitor(std::unique_ptr<BugReporterVisitor> visitor);
351 virtual void Profile(llvm::FoldingSetNodeID& hash)
const;
360 llvm::ilist<BugReport> Reports;
363 void AddReport(std::unique_ptr<BugReport> R) {
364 Reports.push_back(R.release());
372 assert(!Reports.empty());
373 Reports.front().Profile(ID);
379 iterator
begin() {
return Reports.begin(); }
380 iterator
end() {
return Reports.end(); }
382 const_iterator
begin()
const {
return Reports.begin(); }
383 const_iterator
end()
const {
return Reports.end(); }
405 enum Kind { BaseBRKind, GRBugReporterKind };
409 BugTypesTy::Factory F;
420 void FlushReport(
BugReport *exampleReport,
425 llvm::FoldingSet<BugReportEquivClass> EQClasses;
427 std::vector<BugReportEquivClass *> EQClassesVector;
453 iterator
begin() {
return BugTypes.begin(); }
454 iterator
end() {
return BugTypes.end(); }
482 void emitReport(std::unique_ptr<BugReport> R);
485 StringRef BugName, StringRef BugCategory,
490 StringRef BugName, StringRef BugCategory,
495 llvm::StringMap<BugType *> StrBugTypes;
499 BugType *getBugTypeForName(CheckName CheckName, StringRef name,
537 return R->
getKind() == GRBugReporterKind;
542 virtual void anchor();
558 return getStateManager().getSValBuilder();
VisitorList::iterator visitor_iterator
BugReporter(BugReporterData &d)
bool shouldPrunePath() const
Indicates whether or not any path pruning should take place when generating a PathDiagnostic from thi...
const SourceRange * ranges_iterator
MemRegion - The root abstract class for all memory regions.
PathDiagnosticLocation getUniqueingLocation() const
Get the location on which the report should be uniqued.
ASTContext & getASTContext()
bool isInteresting(SymbolRef sym)
llvm::DenseSet< SymbolRef > Symbols
Stmt - This represents one statement.
Decl - This represents one declaration (or definition), e.g.
StringRef getDescription() const
BugReport(BugType &bt, StringRef shortDesc, StringRef desc, const ExplodedNode *errornode)
ArrayRef< PathDiagnosticConsumer * > getPathDiagnosticConsumers()
virtual PathDiagnosticLocation getLocation(const SourceManager &SM) const
Return the "definitive" location of the reported bug.
void addNote(StringRef Msg, const PathDiagnosticLocation &Pos)
void disablePathPruning()
Disable all path pruning when generating a PathDiagnostic.
SmallVector< SourceRange, 4 > Ranges
virtual bool generatePathDiagnostic(PathDiagnostic &pathDiagnostic, PathDiagnosticConsumer &PC, ArrayRef< BugReport *> &bugReports)
virtual AnalyzerOptions & getAnalyzerOptions()=0
PathDiagnostic - PathDiagnostic objects represent a single path-sensitive diagnostic.
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.
bool isValid() const
Returns whether or not this report should be considered valid.
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...
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.
const Stmt * getStmt() const
llvm::SmallSet< const LocationContext *, 2 > InterestingLocationContexts
A set of location contexts that correspoind to call sites which should be considered "interesting"...
const BugType & getBugType() const
BugReporter(BugReporterData &d, Kind k)
ASTContext & getContext()
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.
void Profile(llvm::FoldingSetNodeID &ID) const
GRBugReporter(BugReporterData &d, ExprEngine &eng)
const Decl * getDeclWithIssue() const
Return the canonical declaration, be it a method or class, where this issue semantically occurred...
BugReporterContext(GRBugReporter &br)
void addVisitor(std::unique_ptr< BugReporterVisitor > visitor)
Add custom or predefined bug report visitors to this report.
virtual const NoteList & getNotes()
const_iterator begin() const
const Decl * UniqueingDecl
unsigned getConfigurationChangeToken() const
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()
visitor_iterator visitor_begin()
Iterators through the custom diagnostic visitors.
BugReport(BugType &bt, StringRef desc, PathDiagnosticLocation l)
virtual SourceManager & getSourceManager()=0
const Decl * getUniqueingDecl() const
Get the declaration containing the uniqueing location.
unsigned ConfigurationChangeToken
Used for clients to tell if the report's configuration has changed since the last time they checked...
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...
SValBuilder & getSValBuilder()
SmallVector< std::shared_ptr< PathDiagnosticNotePiece >, 4 > NoteList
void markInteresting(SymbolRef sym)
AnalyzerOptions & getAnalyzerOptions()
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()
const ExplodedNode * ErrorNode
ExplodedGraph & getGraph()
getGraph - Get the exploded graph created by the analysis engine for the analyzed method or function...
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...
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.
Dataflow Directional Tag Classes.
GRBugReporter & getBugReporter()
llvm::ilist< BugReport >::const_iterator const_iterator
virtual ~BugReporterContext()
DiagnosticsEngine & getDiagnostic()
const_iterator end() const
ProgramStateManager & getStateManager()
const ExplodedNode * getErrorNode() const
virtual void Profile(llvm::FoldingSetNodeID &hash) const
Profile to identify equivalent bug reports for error report coalescing.
EQClasses_iterator EQClasses_end()
StringRef getShortDescription(bool UseFallback=true) const
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...
unsigned kind
All of the diagnostics that can be emitted by the frontend.
virtual const ExplodedNode * getOriginalNode(const ExplodedNode *N)=0
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
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.
bool isPathSensitive() const
True when the report has an execution path associated with it.
ExprEngine & getEngine()
getEngine - Return the analysis engine used to analyze a given function or method.