[clang] 2407eb0 - [analyzer] Update static analyzer to be support sarif-html

Haowei Wu via cfe-commits cfe-commits at lists.llvm.org
Wed Feb 10 18:35:06 PST 2021


Author: Daniel Hwang
Date: 2021-02-10T18:34:53-08:00
New Revision: 2407eb08a5748bc2613e95fa449fc1cae6f4ff8f

URL: https://github.com/llvm/llvm-project/commit/2407eb08a5748bc2613e95fa449fc1cae6f4ff8f
DIFF: https://github.com/llvm/llvm-project/commit/2407eb08a5748bc2613e95fa449fc1cae6f4ff8f.diff

LOG: [analyzer] Update static analyzer to be support sarif-html

Updates static analyzer to be able to generate both sarif and html
output in a single run similar to plist-html.

Differential Revision: https://reviews.llvm.org/D96389

Added: 
    

Modified: 
    clang/include/clang/Driver/Options.td
    clang/include/clang/StaticAnalyzer/Core/Analyses.def
    clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index e767d4238f0f..e2a955ea0243 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3667,7 +3667,7 @@ def _CLASSPATH : Separate<["--"], "CLASSPATH">, Alias<fclasspath_EQ>;
 def _all_warnings : Flag<["--"], "all-warnings">, Alias<Wall>;
 def _analyzer_no_default_checks : Flag<["--"], "analyzer-no-default-checks">, Flags<[NoXarchOption]>;
 def _analyzer_output : JoinedOrSeparate<["--"], "analyzer-output">, Flags<[NoXarchOption]>,
-  HelpText<"Static analyzer report output format (html|plist|plist-multi-file|plist-html|sarif|text).">;
+  HelpText<"Static analyzer report output format (html|plist|plist-multi-file|plist-html|sarif|sarif-html|text).">;
 def _analyze : Flag<["--"], "analyze">, Flags<[NoXarchOption, CoreOption]>,
   HelpText<"Run the static analyzer">;
 def _assemble : Flag<["--"], "assemble">, Alias<S>;

diff  --git a/clang/include/clang/StaticAnalyzer/Core/Analyses.def b/clang/include/clang/StaticAnalyzer/Core/Analyses.def
index c4e5f5be6fd7..88c375ce0925 100644
--- a/clang/include/clang/StaticAnalyzer/Core/Analyses.def
+++ b/clang/include/clang/StaticAnalyzer/Core/Analyses.def
@@ -52,9 +52,14 @@ 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",
+ANALYSIS_DIAGNOSTICS(SARIF, "sarif", "Output analysis results using SARIF",
                      createSarifDiagnosticConsumer)
 
+ANALYSIS_DIAGNOSTICS(SARIF_HTML, "sarif-html",
+                     "Output analysis results using both SARIF and HTML "
+                     "output files",
+                     createSarifHTMLDiagnosticConsumer)
+
 ANALYSIS_DIAGNOSTICS(TEXT, "text", "Text output of analysis results to stderr",
                      createTextPathDiagnosticConsumer)
 

diff  --git a/clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp b/clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp
index 149459cf986a..46e533d9680e 100644
--- a/clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp
+++ b/clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp
@@ -176,6 +176,16 @@ void ento::createPlistHTMLDiagnosticConsumer(
                                           CTU);
 }
 
+void ento::createSarifHTMLDiagnosticConsumer(
+  PathDiagnosticConsumerOptions DiagOpts, PathDiagnosticConsumers &C,
+    const std::string &sarif_file, const Preprocessor &PP,
+    const cross_tu::CrossTranslationUnitContext &CTU) {
+  createHTMLDiagnosticConsumer(DiagOpts, C, std::string(llvm::sys::path::parent_path(sarif_file)), PP, CTU);
+  createSarifDiagnosticConsumer(DiagOpts, C, sarif_file, PP, CTU);
+  createTextMinimalPathDiagnosticConsumer(std::move(DiagOpts), C, sarif_file, PP,
+                                          CTU);
+}
+
 //===----------------------------------------------------------------------===//
 // Report processing.
 //===----------------------------------------------------------------------===//


        


More information about the cfe-commits mailing list