15 #ifndef LLVM_CLANG_STATICANALYZER_CORE_BUGREPORTER_BUGREPORTER_H 16 #define LLVM_CLANG_STATICANALYZER_CORE_BUGREPORTER_BUGREPORTER_H 27 #include "llvm/ADT/ArrayRef.h" 28 #include "llvm/ADT/DenseSet.h" 29 #include "llvm/ADT/FoldingSet.h" 30 #include "llvm/ADT/ImmutableSet.h" 31 #include "llvm/ADT/None.h" 32 #include "llvm/ADT/SmallSet.h" 33 #include "llvm/ADT/SmallVector.h" 34 #include "llvm/ADT/StringMap.h" 35 #include "llvm/ADT/StringRef.h" 36 #include "llvm/ADT/ilist.h" 37 #include "llvm/ADT/ilist_node.h" 38 #include "llvm/ADT/iterator_range.h" 47 class AnalyzerOptions;
50 class DiagnosticsEngine;
51 class LocationContext;
72 llvm::DenseMap<PathDiagnosticConsumer *, std::unique_ptr<PathDiagnostic>>;
76 class BugReport :
public llvm::ilist_node<BugReport> {
79 virtual void anchor();
159 Symbols &getInterestingSymbols();
160 Regions &getInterestingRegions();
162 void lazyInitializeInterestingSets();
163 void pushInterestingSymbolsAndRegions();
164 void popInterestingSymbolsAndRegions();
168 : BT(bt), Description(desc), ErrorNode(errornode) {}
172 : BT(bt), ShortDescription(shortDesc), Description(desc),
173 ErrorNode(errornode) {}
176 : BT(bt), Description(desc), Location(l) {}
187 : BT(bt), Description(desc), UniqueingLocation(LocationToUnique),
188 UniqueingDecl(DeclToUnique), ErrorNode(errornode) {}
212 if (ShortDescription.empty() && UseFallback)
239 return Invalidations.empty();
252 Invalidations.insert(std::make_pair(Tag, Data));
262 DeclWithIssue = declWithIssue;
272 auto P = std::make_shared<PathDiagnosticNotePiece>(Pos, Msg);
274 for (
const auto &R : Ranges)
277 Notes.push_back(std::move(
P));
283 std::vector<SourceRange>
Ranges;
295 ExtraText.push_back(S);
329 assert((R.
isValid() || Ranges.empty()) &&
"Invalid range can only be used " 330 "to specify that the report does not have a range.");
335 virtual llvm::iterator_range<ranges_iterator>
getRanges();
344 void addVisitor(std::unique_ptr<BugReporterVisitor> visitor);
356 virtual void Profile(llvm::FoldingSetNodeID& hash)
const;
367 llvm::ilist<BugReport> Reports;
369 void AddReport(std::unique_ptr<BugReport> R) {
370 Reports.push_back(R.release());
378 assert(!Reports.empty());
379 Reports.front().Profile(ID);
414 enum Kind { BaseBRKind, GRBugReporterKind };
417 using BugTypesTy = llvm::ImmutableSet<BugType *>;
419 BugTypesTy::Factory F;
429 std::unique_ptr<DiagnosticForConsumerMapTy>
430 generateDiagnosticForConsumerMap(
BugReport *exampleReport,
435 llvm::FoldingSet<BugReportEquivClass> EQClasses;
438 std::vector<BugReportEquivClass *> EQClassesVector;
442 : BugTypes(F.getEmptySet()), kind(k), D(d) {}
446 : BugTypes(F.getEmptySet()), kind(BaseBRKind), D(d) {}
478 virtual std::unique_ptr<DiagnosticForConsumerMapTy>
491 void emitReport(std::unique_ptr<BugReport> R);
494 StringRef BugName, StringRef BugCategory,
499 StringRef BugName, StringRef BugCategory,
504 llvm::StringMap<BugType *> StrBugTypes;
508 BugType *getBugTypeForName(CheckName CheckName, StringRef name,
535 std::unique_ptr<DiagnosticForConsumerMapTy>
541 return R->
getKind() == GRBugReporterKind;
561 virtual void anchor();
565 : BR(br), NMC(Backmap) {}
578 return getStateManager().getSValBuilder();
600 #endif // LLVM_CLANG_STATICANALYZER_CORE_BUGREPORTER_BUGREPORTER_H const ExplodedNode * getOriginalNode(const ExplodedNode *N) override
BugReporter(BugReporterData &d)
bool shouldPrunePath() const
Indicates whether or not any path pruning should take place when generating a PathDiagnostic from thi...
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)
AnalyzerOptions & getAnalyzerOptions()
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()
The l-value was an access to a declared entity or something equivalently strong, like the address of ...
virtual PathDiagnosticLocation getLocation(const SourceManager &SM) const
Return the "definitive" location of the reported bug.
virtual std::unique_ptr< DiagnosticForConsumerMapTy > generatePathDiagnostics(ArrayRef< PathDiagnosticConsumer *> consumers, ArrayRef< BugReport *> &bugReports)
NodeMapClosure(InterExplodedGraphMap &m)
void addNote(StringRef Msg, const PathDiagnosticLocation &Pos)
void disablePathPruning()
Disable all path pruning when generating a PathDiagnostic.
SmallVector< SourceRange, 4 > Ranges
virtual AnalyzerOptions & getAnalyzerOptions()=0
llvm::DenseMap< PathDiagnosticConsumer *, std::unique_ptr< PathDiagnostic > > DiagnosticForConsumerMapTy
A mapping from diagnostic consumers to the diagnostics they should consume.
void clearVisitors()
Remove all visitors attached to this bug report.
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)
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified...
ASTContext & getContext()
Concrete class used by the front-end to report problems and issues.
ExplodedGraph & getGraph()
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...
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
NodeMapClosure & getNodeResolver()
const Decl * UniqueingDecl
VisitorList::iterator visitor_iterator
BugReportEquivClass(std::unique_ptr< BugReport > R)
bool DoNotPrunePath
When set, this flag disables all callstack pruning from a diagnostic path.
virtual const ExtraTextList & getExtraText()
BugTypesTy::iterator iterator
Iterator over the set of BugTypes tracked by the BugReporter.
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.
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()
BugReporterContext(GRBugReporter &br, InterExplodedGraphMap &Backmap)
void markInteresting(SymbolRef sym)
std::pair< const void *, const void * > InvalidationRecord
Used to track unique reasons why a bug report might be invalid.
AnalyzerOptions & getAnalyzerOptions()
virtual ArrayRef< PathDiagnosticConsumer * > getPathDiagnosticConsumers()=0
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<>.
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...
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...
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::DenseMap< const ExplodedNode *, const ExplodedNode * > InterExplodedGraphMap
DiagnosticsEngine & getDiagnostic()
const_iterator end() const
ProgramStateManager & getStateManager()
virtual ~NodeResolver()=default
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
llvm::FoldingSet< BugReportEquivClass >::iterator EQClasses_iterator
Iterator over the set of BugReports tracked by the BugReporter.
Stores options for the analyzer from the command line.
llvm::ilist< BugReport >::iterator iterator
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.
GRBugReporter is used for generating path-sensitive reports.
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
A trivial tuple used to represent a source range.
This class provides an interface through which checkers can create individual bug reports...
llvm::ilist< BugReport >::const_iterator const_iterator
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.