From 7258ca3ab7ef520a6934124284311c622b9d5bc8 Mon Sep 17 00:00:00 2001 From: Artem Dergachev Date: Fri, 7 Oct 2016 11:26:15 +0000 Subject: [PATCH] [analyzer] Re-apply r283092, attempt no.3, in small chunks this time. llvm-svn: 283540 --- .../StaticAnalyzer/Core/BugReporter/BugReporter.h | 37 ++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h b/clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h index 0ab8b29..ebfe0c6 100644 --- a/clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h +++ b/clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h @@ -66,6 +66,7 @@ public: typedef SmallVector, 8> VisitorList; typedef VisitorList::iterator visitor_iterator; typedef SmallVector ExtraTextList; + typedef SmallVector NoteList; protected: friend class BugReporter; @@ -82,7 +83,8 @@ protected: const ExplodedNode *ErrorNode; SmallVector Ranges; ExtraTextList ExtraText; - + NoteList Notes; + typedef llvm::DenseSet Symbols; typedef llvm::DenseSet Regions; @@ -177,6 +179,18 @@ public: const BugType& getBugType() const { return BT; } BugType& getBugType() { return BT; } + /// \brief True when the report has an execution path associated with it. + /// + /// A report is said to be path-sensitive if it was thrown against a + /// particular exploded node in the path-sensitive analysis graph. + /// Path-sensitive reports have their intermediate path diagnostics + /// auto-generated, perhaps with the help of checker-defined visitors, + /// and may contain extra notes. + /// Path-insensitive reports consist only of a single warning message + /// in a specific location, and perhaps extra notes. + /// Path-sensitive checkers are allowed to throw path-insensitive reports. + bool isPathSensitive() const { return ErrorNode != nullptr; } + const ExplodedNode *getErrorNode() const { return ErrorNode; } StringRef getDescription() const { return Description; } @@ -245,7 +259,26 @@ public: void setDeclWithIssue(const Decl *declWithIssue) { DeclWithIssue = declWithIssue; } - + + /// Add new item to the list of additional notes that need to be attached to + /// this path-insensitive report. If you want to add extra notes to a + /// path-sensitive report, you need to use a BugReporterVisitor because it + /// allows you to specify where exactly in the auto-generated path diagnostic + /// the extra note should appear. + void addNote(StringRef Msg, const PathDiagnosticLocation &Pos, + ArrayRef Ranges = {}) { + auto *P = new PathDiagnosticNotePiece(Pos, Msg); + + for (const auto &R : Ranges) + P->addRange(R); + + Notes.push_back(P); + } + + virtual const NoteList &getNotes() { + return Notes; + } + /// \brief This allows for addition of meta data to the diagnostic. /// /// Currently, only the HTMLDiagnosticClient knows how to display it. -- 2.7.4