[clang] 77bb3eb - Revert "[analyzer] NFC: Move path diagnostic consumer implementations to libAnalysis."

Artem Dergachev via cfe-commits cfe-commits at lists.llvm.org
Tue Oct 13 12:03:24 PDT 2020


Author: Artem Dergachev
Date: 2020-10-13T12:03:04-07:00
New Revision: 77bb3ebebbca13f0648beb433fbd1b06ba95a19c

URL: https://github.com/llvm/llvm-project/commit/77bb3ebebbca13f0648beb433fbd1b06ba95a19c
DIFF: https://github.com/llvm/llvm-project/commit/77bb3ebebbca13f0648beb433fbd1b06ba95a19c.diff

LOG: Revert "[analyzer] NFC: Move path diagnostic consumer implementations to libAnalysis."

This reverts commit 44b7cf2983b6a8373c99a9b254f8c3f944e03f35.

Added: 
    clang/include/clang/StaticAnalyzer/Core/PathDiagnosticConsumers.h
    clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp
    clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
    clang/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp
    clang/lib/StaticAnalyzer/Core/TextDiagnostics.cpp

Modified: 
    clang/include/clang/StaticAnalyzer/Core/Analyses.def
    clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
    clang/include/clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h
    clang/include/clang/module.modulemap
    clang/lib/Analysis/CMakeLists.txt
    clang/lib/Frontend/CompilerInvocation.cpp
    clang/lib/StaticAnalyzer/Core/CMakeLists.txt
    clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp

Removed: 
    clang/include/clang/Analysis/PathDiagnosticConsumers.def
    clang/include/clang/Analysis/PathDiagnosticConsumers.h
    clang/lib/Analysis/HTMLPathDiagnosticConsumer.cpp
    clang/lib/Analysis/PlistHTMLPathDiagnosticConsumer.cpp
    clang/lib/Analysis/PlistPathDiagnosticConsumer.cpp
    clang/lib/Analysis/SarifPathDiagnosticConsumer.cpp
    clang/lib/Analysis/TextPathDiagnosticConsumer.cpp


################################################################################
diff  --git a/clang/include/clang/Analysis/PathDiagnosticConsumers.def b/clang/include/clang/Analysis/PathDiagnosticConsumers.def
deleted file mode 100644
index 33d2072fcf31..000000000000
--- a/clang/include/clang/Analysis/PathDiagnosticConsumers.def
+++ /dev/null
@@ -1,50 +0,0 @@
-//===-- PathDiagnosticConsumers.def - Visualizing warnings ------*- C++ -*-===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-//
-// This file defines the set of path diagnostic consumers - objects that
-// implement 
diff erent representations of static analysis results.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef ANALYSIS_DIAGNOSTICS
-#define ANALYSIS_DIAGNOSTICS(NAME, CMDFLAG, DESC, CREATEFN)
-#endif
-
-ANALYSIS_DIAGNOSTICS(HTML, "html", "Output analysis results using HTML",
-                     createHTMLDiagnosticConsumer)
-
-ANALYSIS_DIAGNOSTICS(
-    HTML_SINGLE_FILE, "html-single-file",
-    "Output analysis results using HTML (not allowing for multi-file bugs)",
-    createHTMLSingleFileDiagnosticConsumer)
-
-ANALYSIS_DIAGNOSTICS(PLIST, "plist", "Output analysis results using Plists",
-                     createPlistDiagnosticConsumer)
-
-ANALYSIS_DIAGNOSTICS(
-    PLIST_MULTI_FILE, "plist-multi-file",
-    "Output analysis results using Plists (allowing for multi-file bugs)",
-    createPlistMultiFileDiagnosticConsumer)
-
-ANALYSIS_DIAGNOSTICS(PLIST_HTML, "plist-html",
-                     "Output analysis results using HTML wrapped with Plists",
-                     createPlistHTMLDiagnosticConsumer)
-
-ANALYSIS_DIAGNOSTICS(SARIF, "sarif", "Output analysis results in a SARIF file",
-                     createSarifDiagnosticConsumer)
-
-ANALYSIS_DIAGNOSTICS(TEXT, "text", "Text output of analysis results to stderr",
-                     createTextPathDiagnosticConsumer)
-
-ANALYSIS_DIAGNOSTICS(TEXT_MINIMAL, "text-minimal",
-                     "Emits minimal diagnostics to stderr, stating only the "
-                     "warning message and the associated notes. Usually "
-                     "used in addition to other analysis types",
-                     createTextMinimalPathDiagnosticConsumer)
-
-#undef ANALYSIS_DIAGNOSTICS

diff  --git a/clang/include/clang/StaticAnalyzer/Core/Analyses.def b/clang/include/clang/StaticAnalyzer/Core/Analyses.def
index 2e98cbba4c9e..c4e5f5be6fd7 100644
--- a/clang/include/clang/StaticAnalyzer/Core/Analyses.def
+++ b/clang/include/clang/StaticAnalyzer/Core/Analyses.def
@@ -28,6 +28,42 @@ ANALYSIS_CONSTRAINTS(RangeConstraints, "range",
 ANALYSIS_CONSTRAINTS(Z3Constraints, "z3", "Use Z3 contraint solver",
                      CreateZ3ConstraintManager)
 
+#ifndef ANALYSIS_DIAGNOSTICS
+#define ANALYSIS_DIAGNOSTICS(NAME, CMDFLAG, DESC, CREATEFN)
+#endif
+
+ANALYSIS_DIAGNOSTICS(HTML, "html", "Output analysis results using HTML",
+                     createHTMLDiagnosticConsumer)
+
+ANALYSIS_DIAGNOSTICS(
+    HTML_SINGLE_FILE, "html-single-file",
+    "Output analysis results using HTML (not allowing for multi-file bugs)",
+    createHTMLSingleFileDiagnosticConsumer)
+
+ANALYSIS_DIAGNOSTICS(PLIST, "plist", "Output analysis results using Plists",
+                     createPlistDiagnosticConsumer)
+
+ANALYSIS_DIAGNOSTICS(
+    PLIST_MULTI_FILE, "plist-multi-file",
+    "Output analysis results using Plists (allowing for multi-file bugs)",
+    createPlistMultiFileDiagnosticConsumer)
+
+ANALYSIS_DIAGNOSTICS(PLIST_HTML, "plist-html",
+                     "Output analysis results using HTML wrapped with Plists",
+                     createPlistHTMLDiagnosticConsumer)
+
+ANALYSIS_DIAGNOSTICS(SARIF, "sarif", "Output analysis results in a SARIF file",
+                     createSarifDiagnosticConsumer)
+
+ANALYSIS_DIAGNOSTICS(TEXT, "text", "Text output of analysis results to stderr",
+                     createTextPathDiagnosticConsumer)
+
+ANALYSIS_DIAGNOSTICS(TEXT_MINIMAL, "text-minimal",
+                     "Emits minimal diagnostics to stderr, stating only the "
+                     "warning message and the associated notes. Usually "
+                     "used in addition to other analysis types",
+                     createTextMinimalPathDiagnosticConsumer)
+
 #ifndef ANALYSIS_PURGE
 #define ANALYSIS_PURGE(NAME, CMDFLAG, DESC)
 #endif
@@ -55,6 +91,7 @@ ANALYSIS_INLINING_MODE(
 
 #undef ANALYSIS_STORE
 #undef ANALYSIS_CONSTRAINTS
+#undef ANALYSIS_DIAGNOSTICS
 #undef ANALYSIS_PURGE
 #undef ANALYSIS_INLINING_MODE
 #undef ANALYSIS_IPA

diff  --git a/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h b/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
index aa334fed41fb..e1093772e02c 100644
--- a/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
+++ b/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
@@ -58,7 +58,7 @@ NumConstraints
 ///  analysis results.
 enum AnalysisDiagClients {
 #define ANALYSIS_DIAGNOSTICS(NAME, CMDFLAG, DESC, CREATFN) PD_##NAME,
-#include "clang/Analysis/PathDiagnosticConsumers.def"
+#include "clang/StaticAnalyzer/Core/Analyses.def"
 PD_NONE,
 NUM_ANALYSIS_DIAG_CLIENTS
 };

diff  --git a/clang/include/clang/Analysis/PathDiagnosticConsumers.h b/clang/include/clang/StaticAnalyzer/Core/PathDiagnosticConsumers.h
similarity index 88%
rename from clang/include/clang/Analysis/PathDiagnosticConsumers.h
rename to clang/include/clang/StaticAnalyzer/Core/PathDiagnosticConsumers.h
index 9b309e6d3607..4b63812b2f83 100644
--- a/clang/include/clang/Analysis/PathDiagnosticConsumers.h
+++ b/clang/include/clang/StaticAnalyzer/Core/PathDiagnosticConsumers.h
@@ -16,8 +16,6 @@
 #include <string>
 #include <vector>
 
-#include "clang/Analysis/PathDiagnostic.h"
-
 namespace clang {
 
 class AnalyzerOptions;
@@ -29,14 +27,14 @@ class CrossTranslationUnitContext;
 namespace ento {
 
 class PathDiagnosticConsumer;
-typedef std::vector<PathDiagnosticConsumer *> PathDiagnosticConsumers;
+typedef std::vector<PathDiagnosticConsumer*> PathDiagnosticConsumers;
 
 #define ANALYSIS_DIAGNOSTICS(NAME, CMDFLAG, DESC, CREATEFN)                    \
   void CREATEFN(PathDiagnosticConsumerOptions Diagopts,                        \
                 PathDiagnosticConsumers &C, const std::string &Prefix,         \
                 const Preprocessor &PP,                                        \
                 const cross_tu::CrossTranslationUnitContext &CTU);
-#include "clang/Analysis/PathDiagnosticConsumers.def"
+#include "clang/StaticAnalyzer/Core/Analyses.def"
 
 } // end 'ento' namespace
 } // end 'clang' namespace

diff  --git a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h
index 7e8b9de3a942..c76e9c0326af 100644
--- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h
+++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h
@@ -16,10 +16,10 @@
 
 #include "clang/Analysis/AnalysisDeclContext.h"
 #include "clang/Analysis/PathDiagnostic.h"
-#include "clang/Analysis/PathDiagnosticConsumers.h"
 #include "clang/Lex/Preprocessor.h"
 #include "clang/StaticAnalyzer/Core/AnalyzerOptions.h"
 #include "clang/StaticAnalyzer/Core/BugReporter/BugReporter.h"
+#include "clang/StaticAnalyzer/Core/PathDiagnosticConsumers.h"
 
 namespace clang {
 

diff  --git a/clang/include/clang/module.modulemap b/clang/include/clang/module.modulemap
index 17104ead5e3c..13d4dbf9dc2e 100644
--- a/clang/include/clang/module.modulemap
+++ b/clang/include/clang/module.modulemap
@@ -3,7 +3,6 @@ module Clang_Analysis {
   umbrella "Analysis"
 
   textual header "Analysis/Analyses/ThreadSafetyOps.def"
-  textual header "Analysis/PathDiagnosticConsumers.def"
 
   module * { export * }
 

diff  --git a/clang/lib/Analysis/CMakeLists.txt b/clang/lib/Analysis/CMakeLists.txt
index 52689dc6ac1e..6cad671a8a4d 100644
--- a/clang/lib/Analysis/CMakeLists.txt
+++ b/clang/lib/Analysis/CMakeLists.txt
@@ -17,19 +17,14 @@ add_clang_library(clangAnalysis
   CodeInjector.cpp
   Dominators.cpp
   ExprMutationAnalyzer.cpp
-  HTMLPathDiagnosticConsumer.cpp
   IssueHash.cpp
   LiveVariables.cpp
   ObjCNoReturn.cpp
   PathDiagnostic.cpp
-  PlistPathDiagnosticConsumer.cpp
-  PlistHTMLPathDiagnosticConsumer.cpp
   PostOrderCFGView.cpp
   ProgramPoint.cpp
   ReachableCode.cpp
   RetainSummaryManager.cpp
-  SarifPathDiagnosticConsumer.cpp
-  TextPathDiagnosticConsumer.cpp
   ThreadSafety.cpp
   ThreadSafetyCommon.cpp
   ThreadSafetyLogical.cpp

diff  --git a/clang/lib/Analysis/PlistHTMLPathDiagnosticConsumer.cpp b/clang/lib/Analysis/PlistHTMLPathDiagnosticConsumer.cpp
deleted file mode 100644
index 60be1077f9de..000000000000
--- a/clang/lib/Analysis/PlistHTMLPathDiagnosticConsumer.cpp
+++ /dev/null
@@ -1,31 +0,0 @@
-//===--- PlistHTMLDiagnostics.cpp - The Plist-HTML Diagnostic Consumer. ---===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-//
-// This diagnostic consumer produces both the HTML output and the Plist output.
-//
-//===----------------------------------------------------------------------===//
-
-#include "clang/Analysis/PathDiagnostic.h"
-#include "clang/Analysis/PathDiagnosticConsumers.h"
-#include "clang/Basic/SourceManager.h"
-#include "clang/CrossTU/CrossTranslationUnit.h"
-#include "clang/Lex/Preprocessor.h"
-
-using namespace clang;
-using namespace ento;
-
-void ento::createPlistHTMLDiagnosticConsumer(
-    PathDiagnosticConsumerOptions DiagOpts, PathDiagnosticConsumers &C,
-    const std::string &Prefix, const Preprocessor &PP,
-    const cross_tu::CrossTranslationUnitContext &CTU) {
-  createHTMLDiagnosticConsumer(
-      DiagOpts, C, std::string(llvm::sys::path::parent_path(Prefix)), PP, CTU);
-  createPlistMultiFileDiagnosticConsumer(DiagOpts, C, Prefix, PP, CTU);
-  createTextMinimalPathDiagnosticConsumer(std::move(DiagOpts), C, Prefix, PP,
-                                          CTU);
-}

diff  --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp
index 747b8a9e92bf..a4c56cc4e51e 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -301,7 +301,7 @@ static bool ParseAnalyzerArgs(AnalyzerOptions &Opts, ArgList &Args,
     AnalysisDiagClients Value = llvm::StringSwitch<AnalysisDiagClients>(Name)
 #define ANALYSIS_DIAGNOSTICS(NAME, CMDFLAG, DESC, CREATFN) \
       .Case(CMDFLAG, PD_##NAME)
-#include "clang/Analysis/PathDiagnosticConsumers.def"
+#include "clang/StaticAnalyzer/Core/Analyses.def"
       .Default(NUM_ANALYSIS_DIAG_CLIENTS);
     if (Value == NUM_ANALYSIS_DIAG_CLIENTS) {
       Diags.Report(diag::err_drv_invalid_value)

diff  --git a/clang/lib/StaticAnalyzer/Core/CMakeLists.txt b/clang/lib/StaticAnalyzer/Core/CMakeLists.txt
index b1f527ed75d5..d947d415ad6e 100644
--- a/clang/lib/StaticAnalyzer/Core/CMakeLists.txt
+++ b/clang/lib/StaticAnalyzer/Core/CMakeLists.txt
@@ -30,13 +30,16 @@ add_clang_library(clangStaticAnalyzerCore
   ExprEngineCallAndReturn.cpp
   ExprEngineObjC.cpp
   FunctionSummary.cpp
+  HTMLDiagnostics.cpp
   LoopUnrolling.cpp
   LoopWidening.cpp
   MemRegion.cpp
+  PlistDiagnostics.cpp
   ProgramState.cpp
   RangeConstraintManager.cpp
   RangedConstraintManager.cpp
   RegionStore.cpp
+  SarifDiagnostics.cpp
   SimpleConstraintManager.cpp
   SimpleSValBuilder.cpp
   SMTConstraintManager.cpp
@@ -44,6 +47,7 @@ add_clang_library(clangStaticAnalyzerCore
   SValBuilder.cpp
   SVals.cpp
   SymbolManager.cpp
+  TextDiagnostics.cpp
   WorkList.cpp
 
   LINK_LIBS

diff  --git a/clang/lib/Analysis/HTMLPathDiagnosticConsumer.cpp b/clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp
similarity index 91%
rename from clang/lib/Analysis/HTMLPathDiagnosticConsumer.cpp
rename to clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp
index 5b078fa007af..35c590fe396b 100644
--- a/clang/lib/Analysis/HTMLPathDiagnosticConsumer.cpp
+++ b/clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp
@@ -1,4 +1,4 @@
-//===- HTMLPathDiagnosticConsumer.cpp - HTML Diagnostics for Paths --------===//
+//===- HTMLDiagnostics.cpp - HTML Diagnostics for Paths -------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -6,13 +6,12 @@
 //
 //===----------------------------------------------------------------------===//
 //
-//  This file defines the HTMLPathDiagnosticConsumer object.
+//  This file defines the HTMLDiagnostics object.
 //
 //===----------------------------------------------------------------------===//
 
 #include "clang/Analysis/IssueHash.h"
 #include "clang/Analysis/PathDiagnostic.h"
-#include "clang/Analysis/PathDiagnosticConsumers.h"
 #include "clang/AST/Decl.h"
 #include "clang/AST/DeclBase.h"
 #include "clang/AST/Stmt.h"
@@ -25,6 +24,7 @@
 #include "clang/Lex/Token.h"
 #include "clang/Rewrite/Core/HTMLRewrite.h"
 #include "clang/Rewrite/Core/Rewriter.h"
+#include "clang/StaticAnalyzer/Core/PathDiagnosticConsumers.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/StringRef.h"
@@ -56,7 +56,7 @@ using namespace ento;
 
 namespace {
 
-class HTMLPathDiagnosticConsumer : public PathDiagnosticConsumer {
+class HTMLDiagnostics : public PathDiagnosticConsumer {
   PathDiagnosticConsumerOptions DiagOpts;
   std::string Directory;
   bool createdDir = false;
@@ -65,18 +65,20 @@ class HTMLPathDiagnosticConsumer : public PathDiagnosticConsumer {
   const bool SupportsCrossFileDiagnostics;
 
 public:
-  HTMLPathDiagnosticConsumer(PathDiagnosticConsumerOptions DiagOpts,
-                             const std::string &OutputDir,
-                             const Preprocessor &PP, bool SupportsMultipleFiles)
-      : DiagOpts(std::move(DiagOpts)), Directory(OutputDir), PP(PP),
-        SupportsCrossFileDiagnostics(SupportsMultipleFiles) {}
+  HTMLDiagnostics(PathDiagnosticConsumerOptions DiagOpts,
+                  const std::string &OutputDir, const Preprocessor &pp,
+                  bool supportsMultipleFiles)
+      : DiagOpts(std::move(DiagOpts)), Directory(OutputDir), PP(pp),
+        SupportsCrossFileDiagnostics(supportsMultipleFiles) {}
 
-  ~HTMLPathDiagnosticConsumer() override { FlushDiagnostics(nullptr); }
+  ~HTMLDiagnostics() override { FlushDiagnostics(nullptr); }
 
   void FlushDiagnosticsImpl(std::vector<const PathDiagnostic *> &Diags,
                             FilesMade *filesMade) override;
 
-  StringRef getName() const override { return "HTMLPathDiagnosticConsumer"; }
+  StringRef getName() const override {
+    return "HTMLDiagnostics";
+  }
 
   bool supportsCrossFileDiagnostics() const override {
     return SupportsCrossFileDiagnostics;
@@ -146,8 +148,7 @@ void ento::createHTMLDiagnosticConsumer(
   if (OutputDir.empty())
     return;
 
-  C.push_back(
-      new HTMLPathDiagnosticConsumer(std::move(DiagOpts), OutputDir, PP, true));
+  C.push_back(new HTMLDiagnostics(std::move(DiagOpts), OutputDir, PP, true));
 }
 
 void ento::createHTMLSingleFileDiagnosticConsumer(
@@ -160,22 +161,34 @@ void ento::createHTMLSingleFileDiagnosticConsumer(
   if (OutputDir.empty())
     return;
 
-  C.push_back(new HTMLPathDiagnosticConsumer(std::move(DiagOpts), OutputDir, PP,
-                                             false));
+  C.push_back(new HTMLDiagnostics(std::move(DiagOpts), OutputDir, PP, false));
+}
+
+void ento::createPlistHTMLDiagnosticConsumer(
+    PathDiagnosticConsumerOptions DiagOpts, PathDiagnosticConsumers &C,
+    const std::string &prefix, const Preprocessor &PP,
+    const cross_tu::CrossTranslationUnitContext &CTU) {
+  createHTMLDiagnosticConsumer(
+      DiagOpts, C, std::string(llvm::sys::path::parent_path(prefix)), PP,
+      CTU);
+  createPlistMultiFileDiagnosticConsumer(DiagOpts, C, prefix, PP, CTU);
+  createTextMinimalPathDiagnosticConsumer(std::move(DiagOpts), C, prefix, PP,
+                                          CTU);
 }
 
 //===----------------------------------------------------------------------===//
 // Report processing.
 //===----------------------------------------------------------------------===//
 
-void HTMLPathDiagnosticConsumer::FlushDiagnosticsImpl(
-    std::vector<const PathDiagnostic *> &Diags, FilesMade *filesMade) {
+void HTMLDiagnostics::FlushDiagnosticsImpl(
+  std::vector<const PathDiagnostic *> &Diags,
+  FilesMade *filesMade) {
   for (const auto Diag : Diags)
     ReportDiag(*Diag, filesMade);
 }
 
-void HTMLPathDiagnosticConsumer::ReportDiag(const PathDiagnostic &D,
-                                            FilesMade *filesMade) {
+void HTMLDiagnostics::ReportDiag(const PathDiagnostic& D,
+                                 FilesMade *filesMade) {
   // Create the HTML directory if it is missing.
   if (!createdDir) {
     createdDir = true;
@@ -283,11 +296,8 @@ void HTMLPathDiagnosticConsumer::ReportDiag(const PathDiagnostic &D,
   os << report;
 }
 
-std::string HTMLPathDiagnosticConsumer::GenerateHTML(const PathDiagnostic &D,
-                                                     Rewriter &R,
-                                                     const SourceManager &SMgr,
-                                                     const PathPieces &path,
-                                                     const char *declName) {
+std::string HTMLDiagnostics::GenerateHTML(const PathDiagnostic& D, Rewriter &R,
+    const SourceManager& SMgr, const PathPieces& path, const char *declName) {
   // Rewrite source files as HTML for every new file the path crosses
   std::vector<FileID> FileIDs;
   for (auto I : path) {
@@ -359,8 +369,9 @@ std::string HTMLPathDiagnosticConsumer::GenerateHTML(const PathDiagnostic &D,
   return os.str();
 }
 
-void HTMLPathDiagnosticConsumer::dumpCoverageData(
-    const PathDiagnostic &D, const PathPieces &path,
+void HTMLDiagnostics::dumpCoverageData(
+    const PathDiagnostic &D,
+    const PathPieces &path,
     llvm::raw_string_ostream &os) {
 
   const FilesToLineNumsMap &ExecutedLines = D.getExecutedLines();
@@ -384,8 +395,8 @@ void HTMLPathDiagnosticConsumer::dumpCoverageData(
   os << "};";
 }
 
-std::string HTMLPathDiagnosticConsumer::showRelevantLinesJavascript(
-    const PathDiagnostic &D, const PathPieces &path) {
+std::string HTMLDiagnostics::showRelevantLinesJavascript(
+      const PathDiagnostic &D, const PathPieces &path) {
   std::string s;
   llvm::raw_string_ostream os(s);
   os << "<script type='text/javascript'>\n";
@@ -449,10 +460,9 @@ document.addEventListener("DOMContentLoaded", function() {
   return os.str();
 }
 
-void HTMLPathDiagnosticConsumer::FinalizeHTML(
-    const PathDiagnostic &D, Rewriter &R, const SourceManager &SMgr,
-    const PathPieces &path, FileID FID, const FileEntry *Entry,
-    const char *declName) {
+void HTMLDiagnostics::FinalizeHTML(const PathDiagnostic& D, Rewriter &R,
+    const SourceManager& SMgr, const PathPieces& path, FileID FID,
+    const FileEntry *Entry, const char *declName) {
   // This is a cludge; basically we want to append either the full
   // working directory if we have no directory information.  This is
   // a work in progress.
@@ -597,7 +607,7 @@ void HTMLPathDiagnosticConsumer::FinalizeHTML(
   html::AddHeaderFooterInternalBuiltinCSS(R, FID, Entry->getName());
 }
 
-StringRef HTMLPathDiagnosticConsumer::showHelpJavascript() {
+StringRef HTMLDiagnostics::showHelpJavascript() {
   return R"<<<(
 <script type='text/javascript'>
 
@@ -680,9 +690,8 @@ static void HandlePopUpPieceEndTag(Rewriter &R,
   }
 }
 
-void HTMLPathDiagnosticConsumer::RewriteFile(Rewriter &R,
-                                             const PathPieces &path,
-                                             FileID FID) {
+void HTMLDiagnostics::RewriteFile(Rewriter &R,
+                                  const PathPieces& path, FileID FID) {
   // Process the path.
   // Maintain the counts of extra note pieces separately.
   unsigned TotalPieces = path.size();
@@ -760,9 +769,10 @@ void HTMLPathDiagnosticConsumer::RewriteFile(Rewriter &R,
   html::HighlightMacros(R, FID, PP);
 }
 
-void HTMLPathDiagnosticConsumer::HandlePiece(
-    Rewriter &R, FileID BugFileID, const PathDiagnosticPiece &P,
-    const std::vector<SourceRange> &PopUpRanges, unsigned num, unsigned max) {
+void HTMLDiagnostics::HandlePiece(Rewriter &R, FileID BugFileID,
+                                  const PathDiagnosticPiece &P,
+                                  const std::vector<SourceRange> &PopUpRanges,
+                                  unsigned num, unsigned max) {
   // For now, just draw a box above the line in question, and emit the
   // warning.
   FullSourceLoc Pos = P.getLocation().asLocation();
@@ -994,8 +1004,9 @@ static void EmitAlphaCounter(raw_ostream &os, unsigned n) {
   os << char('a' + x);
 }
 
-unsigned HTMLPathDiagnosticConsumer::ProcessMacroPiece(
-    raw_ostream &os, const PathDiagnosticMacroPiece &P, unsigned num) {
+unsigned HTMLDiagnostics::ProcessMacroPiece(raw_ostream &os,
+                                            const PathDiagnosticMacroPiece& P,
+                                            unsigned num) {
   for (const auto &subPiece : P.subPieces) {
     if (const auto *MP = dyn_cast<PathDiagnosticMacroPiece>(subPiece.get())) {
       num = ProcessMacroPiece(os, *MP, num);
@@ -1017,10 +1028,10 @@ unsigned HTMLPathDiagnosticConsumer::ProcessMacroPiece(
   return num;
 }
 
-void HTMLPathDiagnosticConsumer::HighlightRange(Rewriter &R, FileID BugFileID,
-                                                SourceRange Range,
-                                                const char *HighlightStart,
-                                                const char *HighlightEnd) {
+void HTMLDiagnostics::HighlightRange(Rewriter& R, FileID BugFileID,
+                                     SourceRange Range,
+                                     const char *HighlightStart,
+                                     const char *HighlightEnd) {
   SourceManager &SM = R.getSourceMgr();
   const LangOptions &LangOpts = R.getLangOpts();
 
@@ -1055,7 +1066,7 @@ void HTMLPathDiagnosticConsumer::HighlightRange(Rewriter &R, FileID BugFileID,
   html::HighlightRange(R, InstantiationStart, E, HighlightStart, HighlightEnd);
 }
 
-StringRef HTMLPathDiagnosticConsumer::generateKeyboardNavigationJavascript() {
+StringRef HTMLDiagnostics::generateKeyboardNavigationJavascript() {
   return R"<<<(
 <script type='text/javascript'>
 var digitMatcher = new RegExp("[0-9]+");

diff  --git a/clang/lib/Analysis/PlistPathDiagnosticConsumer.cpp b/clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
similarity index 97%
rename from clang/lib/Analysis/PlistPathDiagnosticConsumer.cpp
rename to clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
index 7e5851058e49..18d83465eca6 100644
--- a/clang/lib/Analysis/PlistPathDiagnosticConsumer.cpp
+++ b/clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
@@ -1,4 +1,4 @@
-//===--- PlistPathDiagnosticConsumer.cpp - Plist Diagnostics ----*- C++ -*-===//
+//===--- PlistDiagnostics.cpp - Plist Diagnostics for Paths -----*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -6,13 +6,12 @@
 //
 //===----------------------------------------------------------------------===//
 //
-//  This file defines the PlistPathDiagnosticConsumer object.
+//  This file defines the PlistDiagnostics object.
 //
 //===----------------------------------------------------------------------===//
 
 #include "clang/Analysis/IssueHash.h"
 #include "clang/Analysis/PathDiagnostic.h"
-#include "clang/Analysis/PathDiagnosticConsumers.h"
 #include "clang/Basic/FileManager.h"
 #include "clang/Basic/PlistSupport.h"
 #include "clang/Basic/SourceManager.h"
@@ -22,6 +21,7 @@
 #include "clang/Lex/Preprocessor.h"
 #include "clang/Lex/TokenConcatenation.h"
 #include "clang/Rewrite/Core/HTMLRewrite.h"
+#include "clang/StaticAnalyzer/Core/PathDiagnosticConsumers.h"
 #include "llvm/ADT/SmallPtrSet.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/Statistic.h"
@@ -38,7 +38,7 @@ using namespace markup;
 //===----------------------------------------------------------------------===//
 
 namespace {
-  class PlistPathDiagnosticConsumer : public PathDiagnosticConsumer {
+  class PlistDiagnostics : public PathDiagnosticConsumer {
     PathDiagnosticConsumerOptions DiagOpts;
     const std::string OutputFile;
     const Preprocessor &PP;
@@ -49,18 +49,18 @@ namespace {
                       const PathPieces &Path);
 
   public:
-    PlistPathDiagnosticConsumer(PathDiagnosticConsumerOptions DiagOpts,
+    PlistDiagnostics(PathDiagnosticConsumerOptions DiagOpts,
                      const std::string &OutputFile, const Preprocessor &PP,
                      const cross_tu::CrossTranslationUnitContext &CTU,
                      bool supportsMultipleFiles);
 
-    ~PlistPathDiagnosticConsumer() override {}
+    ~PlistDiagnostics() override {}
 
     void FlushDiagnosticsImpl(std::vector<const PathDiagnostic *> &Diags,
                               FilesMade *filesMade) override;
 
     StringRef getName() const override {
-      return "PlistPathDiagnosticConsumer";
+      return "PlistDiagnostics";
     }
 
     PathGenerationScheme getGenerationScheme() const override {
@@ -516,10 +516,10 @@ static void printCoverage(const PathDiagnostic *D,
 }
 
 //===----------------------------------------------------------------------===//
-// Methods of PlistPathDiagnosticConsumer.
+// Methods of PlistDiagnostics.
 //===----------------------------------------------------------------------===//
 
-PlistPathDiagnosticConsumer::PlistPathDiagnosticConsumer(
+PlistDiagnostics::PlistDiagnostics(
     PathDiagnosticConsumerOptions DiagOpts, const std::string &output,
     const Preprocessor &PP, const cross_tu::CrossTranslationUnitContext &CTU,
     bool supportsMultipleFiles)
@@ -538,8 +538,8 @@ void ento::createPlistDiagnosticConsumer(
   if (OutputFile.empty())
     return;
 
-  C.push_back(new PlistPathDiagnosticConsumer(DiagOpts, OutputFile, PP, CTU,
-                                              /*supportsMultipleFiles=*/false));
+  C.push_back(new PlistDiagnostics(DiagOpts, OutputFile, PP, CTU,
+                                   /*supportsMultipleFiles=*/false));
   createTextMinimalPathDiagnosticConsumer(std::move(DiagOpts), C, OutputFile,
                                           PP, CTU);
 }
@@ -553,15 +553,14 @@ void ento::createPlistMultiFileDiagnosticConsumer(
   if (OutputFile.empty())
     return;
 
-  C.push_back(new PlistPathDiagnosticConsumer(DiagOpts, OutputFile, PP, CTU,
-                                              /*supportsMultipleFiles=*/true));
+  C.push_back(new PlistDiagnostics(DiagOpts, OutputFile, PP, CTU,
+                                   /*supportsMultipleFiles=*/true));
   createTextMinimalPathDiagnosticConsumer(std::move(DiagOpts), C, OutputFile,
                                           PP, CTU);
 }
 
-void PlistPathDiagnosticConsumer::printBugPath(llvm::raw_ostream &o,
-                                               const FIDMap &FM,
-                                               const PathPieces &Path) {
+void PlistDiagnostics::printBugPath(llvm::raw_ostream &o, const FIDMap &FM,
+                                    const PathPieces &Path) {
   PlistPrinter Printer(FM, PP, CTU);
   assert(std::is_partitioned(Path.begin(), Path.end(),
                              [](const PathDiagnosticPieceRef &E) {
@@ -604,8 +603,9 @@ void PlistPathDiagnosticConsumer::printBugPath(llvm::raw_ostream &o,
   o << "   </array>\n";
 }
 
-void PlistPathDiagnosticConsumer::FlushDiagnosticsImpl(
-    std::vector<const PathDiagnostic *> &Diags, FilesMade *filesMade) {
+void PlistDiagnostics::FlushDiagnosticsImpl(
+                                    std::vector<const PathDiagnostic *> &Diags,
+                                    FilesMade *filesMade) {
   // Build up a set of FIDs that we use by scanning the locations and
   // ranges of the diagnostics.
   FIDMap FM;

diff  --git a/clang/lib/Analysis/SarifPathDiagnosticConsumer.cpp b/clang/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp
similarity index 93%
rename from clang/lib/Analysis/SarifPathDiagnosticConsumer.cpp
rename to clang/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp
index 656b6b275748..9abc5dedeb7a 100644
--- a/clang/lib/Analysis/SarifPathDiagnosticConsumer.cpp
+++ b/clang/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp
@@ -1,4 +1,4 @@
-//===--- SarifPathDiagnosticConsumer.cpp - Sarif Diagnostics  ---*- C++ -*-===//
+//===--- SarifDiagnostics.cpp - Sarif Diagnostics for Paths -----*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -6,15 +6,15 @@
 //
 //===----------------------------------------------------------------------===//
 //
-//  This file defines the SarifPathDiagnosticConsumer object.
+//  This file defines the SarifDiagnostics object.
 //
 //===----------------------------------------------------------------------===//
 
 #include "clang/Analysis/PathDiagnostic.h"
-#include "clang/Analysis/PathDiagnosticConsumers.h"
 #include "clang/Basic/FileManager.h"
 #include "clang/Basic/Version.h"
 #include "clang/Lex/Preprocessor.h"
+#include "clang/StaticAnalyzer/Core/PathDiagnosticConsumers.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/StringMap.h"
 #include "llvm/Support/ConvertUTF.h"
@@ -26,19 +26,19 @@ using namespace clang;
 using namespace ento;
 
 namespace {
-class SarifPathDiagnosticConsumer : public PathDiagnosticConsumer {
+class SarifDiagnostics : public PathDiagnosticConsumer {
   std::string OutputFile;
   const LangOptions &LO;
 
 public:
-  SarifPathDiagnosticConsumer(const std::string &Output, const LangOptions &LO)
+  SarifDiagnostics(const std::string &Output, const LangOptions &LO)
       : OutputFile(Output), LO(LO) {}
-  ~SarifPathDiagnosticConsumer() override = default;
+  ~SarifDiagnostics() override = default;
 
   void FlushDiagnosticsImpl(std::vector<const PathDiagnostic *> &Diags,
                             FilesMade *FM) override;
 
-  StringRef getName() const override { return "SarifPathDiagnosticConsumer"; }
+  StringRef getName() const override { return "SarifDiagnostics"; }
   PathGenerationScheme getGenerationScheme() const override { return Minimal; }
   bool supportsLogicalOpControlFlow() const override { return true; }
   bool supportsCrossFileDiagnostics() const override { return true; }
@@ -54,7 +54,7 @@ void ento::createSarifDiagnosticConsumer(
   if (Output.empty())
     return;
 
-  C.push_back(new SarifPathDiagnosticConsumer(Output, PP.getLangOpts()));
+  C.push_back(new SarifDiagnostics(Output, PP.getLangOpts()));
   createTextMinimalPathDiagnosticConsumer(std::move(DiagOpts), C, Output, PP,
                                           CTU);
 }
@@ -300,9 +300,6 @@ static json::Object createResult(const LangOptions &LO,
 }
 
 static StringRef getRuleDescription(StringRef CheckName) {
-  // FIXME: This is a layering violation; it only works for the particular
-  // use-case of clang static analyzer. This info should be provided
-  // as part of PathDiagnostic itself.
   return llvm::StringSwitch<StringRef>(CheckName)
 #define GET_CHECKERS
 #define CHECKER(FULLNAME, CLASS, HELPTEXT, DOC_URI, IS_HIDDEN)                 \
@@ -314,9 +311,6 @@ static StringRef getRuleDescription(StringRef CheckName) {
 }
 
 static StringRef getRuleHelpURIStr(StringRef CheckName) {
-  // FIXME: This is a layering violation; it only works for the particular
-  // use-case of clang static analyzer. This info should be provided
-  // as part of PathDiagnostic itself.
   return llvm::StringSwitch<StringRef>(CheckName)
 #define GET_CHECKERS
 #define CHECKER(FULLNAME, CLASS, HELPTEXT, DOC_URI, IS_HIDDEN)                 \
@@ -384,7 +378,7 @@ static json::Object createRun(const LangOptions &LO,
                       {"columnKind", "unicodeCodePoints"}};
 }
 
-void SarifPathDiagnosticConsumer::FlushDiagnosticsImpl(
+void SarifDiagnostics::FlushDiagnosticsImpl(
     std::vector<const PathDiagnostic *> &Diags, FilesMade *) {
   // We currently overwrite the file if it already exists. However, it may be
   // useful to add a feature someday that allows the user to append a run to an

diff  --git a/clang/lib/Analysis/TextPathDiagnosticConsumer.cpp b/clang/lib/StaticAnalyzer/Core/TextDiagnostics.cpp
similarity index 83%
rename from clang/lib/Analysis/TextPathDiagnosticConsumer.cpp
rename to clang/lib/StaticAnalyzer/Core/TextDiagnostics.cpp
index 21e89548636e..ae2bad7ee77c 100644
--- a/clang/lib/Analysis/TextPathDiagnosticConsumer.cpp
+++ b/clang/lib/StaticAnalyzer/Core/TextDiagnostics.cpp
@@ -1,4 +1,4 @@
-//===--- TextPathDiagnosticConsumer.cpp - Text Diagnostics ------*- C++ -*-===//
+//===--- TextDiagnostics.cpp - Text Diagnostics for Paths -------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -6,18 +6,19 @@
 //
 //===----------------------------------------------------------------------===//
 //
-//  This file defines the TextPathDiagnosticConsumer object.
+//  This file defines the TextDiagnostics object.
 //
 //===----------------------------------------------------------------------===//
 
 #include "clang/Analysis/PathDiagnostic.h"
-#include "clang/Analysis/PathDiagnosticConsumers.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Basic/Version.h"
 #include "clang/CrossTU/CrossTranslationUnit.h"
 #include "clang/Frontend/ASTUnit.h"
 #include "clang/Lex/Preprocessor.h"
 #include "clang/Rewrite/Core/Rewriter.h"
+#include "clang/StaticAnalyzer/Core/AnalyzerOptions.h"
+#include "clang/StaticAnalyzer/Core/PathDiagnosticConsumers.h"
 #include "clang/Tooling/Core/Replacement.h"
 #include "clang/Tooling/Tooling.h"
 #include "llvm/ADT/SmallPtrSet.h"
@@ -32,21 +33,21 @@ namespace {
 /// Emitsd minimal diagnostics (report message + notes) for the 'none' output
 /// type to the standard error, or to to compliment many others. Emits detailed
 /// diagnostics in textual format for the 'text' output type.
-class TextPathDiagnosticConsumer : public PathDiagnosticConsumer {
+class TextDiagnostics : public PathDiagnosticConsumer {
   PathDiagnosticConsumerOptions DiagOpts;
   DiagnosticsEngine &DiagEng;
   const LangOptions &LO;
   bool ShouldDisplayPathNotes;
 
 public:
-  TextPathDiagnosticConsumer(PathDiagnosticConsumerOptions DiagOpts,
-                             DiagnosticsEngine &DiagEng, const LangOptions &LO,
-                             bool ShouldDisplayPathNotes)
+  TextDiagnostics(PathDiagnosticConsumerOptions DiagOpts,
+                  DiagnosticsEngine &DiagEng, const LangOptions &LO,
+                  bool ShouldDisplayPathNotes)
       : DiagOpts(std::move(DiagOpts)), DiagEng(DiagEng), LO(LO),
         ShouldDisplayPathNotes(ShouldDisplayPathNotes) {}
-  ~TextPathDiagnosticConsumer() override {}
+  ~TextDiagnostics() override {}
 
-  StringRef getName() const override { return "TextPathDiagnosticConsumer"; }
+  StringRef getName() const override { return "TextDiagnostics"; }
 
   bool supportsLogicalOpControlFlow() const override { return true; }
   bool supportsCrossFileDiagnostics() const override { return true; }
@@ -139,16 +140,16 @@ void ento::createTextPathDiagnosticConsumer(
     PathDiagnosticConsumerOptions DiagOpts, PathDiagnosticConsumers &C,
     const std::string &Prefix, const clang::Preprocessor &PP,
     const cross_tu::CrossTranslationUnitContext &CTU) {
-  C.emplace_back(new TextPathDiagnosticConsumer(
-      std::move(DiagOpts), PP.getDiagnostics(), PP.getLangOpts(),
-      /*ShouldDisplayPathNotes=*/true));
+  C.emplace_back(new TextDiagnostics(std::move(DiagOpts), PP.getDiagnostics(),
+                                     PP.getLangOpts(),
+                                     /*ShouldDisplayPathNotes=*/true));
 }
 
 void ento::createTextMinimalPathDiagnosticConsumer(
     PathDiagnosticConsumerOptions DiagOpts, PathDiagnosticConsumers &C,
     const std::string &Prefix, const clang::Preprocessor &PP,
     const cross_tu::CrossTranslationUnitContext &CTU) {
-  C.emplace_back(new TextPathDiagnosticConsumer(
-      std::move(DiagOpts), PP.getDiagnostics(), PP.getLangOpts(),
-      /*ShouldDisplayPathNotes=*/false));
+  C.emplace_back(new TextDiagnostics(std::move(DiagOpts), PP.getDiagnostics(),
+                                     PP.getLangOpts(),
+                                     /*ShouldDisplayPathNotes=*/false));
 }

diff  --git a/clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp b/clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
index 74f0db484f8f..f41f8343086f 100644
--- a/clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
+++ b/clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
@@ -21,7 +21,6 @@
 #include "clang/Analysis/CallGraph.h"
 #include "clang/Analysis/CodeInjector.h"
 #include "clang/Analysis/PathDiagnostic.h"
-#include "clang/Analysis/PathDiagnosticConsumers.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/CrossTU/CrossTranslationUnit.h"
 #include "clang/Frontend/CompilerInstance.h"
@@ -31,6 +30,7 @@
 #include "clang/StaticAnalyzer/Core/AnalyzerOptions.h"
 #include "clang/StaticAnalyzer/Core/BugReporter/BugReporter.h"
 #include "clang/StaticAnalyzer/Core/CheckerManager.h"
+#include "clang/StaticAnalyzer/Core/PathDiagnosticConsumers.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h"
 #include "llvm/ADT/PostOrderIterator.h"
@@ -152,7 +152,7 @@ class AnalysisConsumer : public AnalysisASTConsumer,
   case PD_##NAME:                                                              \
     CREATEFN(Opts->getDiagOpts(), PathConsumers, OutDir, PP, CTU);             \
     break;
-#include "clang/Analysis/PathDiagnosticConsumers.def"
+#include "clang/StaticAnalyzer/Core/Analyses.def"
     default:
       llvm_unreachable("Unknown analyzer output type!");
     }


        


More information about the cfe-commits mailing list