Index: clang/include/clang/Analysis/PathDiagnosticConsumers.h =================================================================== --- clang/include/clang/Analysis/PathDiagnosticConsumers.h +++ clang/include/clang/Analysis/PathDiagnosticConsumers.h @@ -27,14 +27,14 @@ namespace ento { class PathDiagnosticConsumer; -typedef std::vector PathDiagnosticConsumers; +typedef std::vector 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/StaticAnalyzer/Core/Analyses.def" +#include "clang/Analysis/PathDiagnosticConsumers.def" } // end 'ento' namespace } // end 'clang' namespace Index: clang/include/clang/Analysis/PathDiagnosticConsumers.def =================================================================== --- /dev/null +++ clang/include/clang/Analysis/PathDiagnosticConsumers.def @@ -0,0 +1,50 @@ +//===-- 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 different 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 Index: clang/include/clang/StaticAnalyzer/Core/Analyses.def =================================================================== --- clang/include/clang/StaticAnalyzer/Core/Analyses.def +++ clang/include/clang/StaticAnalyzer/Core/Analyses.def @@ -28,42 +28,6 @@ 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 @@ -91,7 +55,6 @@ #undef ANALYSIS_STORE #undef ANALYSIS_CONSTRAINTS -#undef ANALYSIS_DIAGNOSTICS #undef ANALYSIS_PURGE #undef ANALYSIS_INLINING_MODE #undef ANALYSIS_IPA Index: clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h =================================================================== --- clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h +++ clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h @@ -58,7 +58,7 @@ /// analysis results. enum AnalysisDiagClients { #define ANALYSIS_DIAGNOSTICS(NAME, CMDFLAG, DESC, CREATFN) PD_##NAME, -#include "clang/StaticAnalyzer/Core/Analyses.def" +#include "clang/Analysis/PathDiagnosticConsumers.def" PD_NONE, NUM_ANALYSIS_DIAG_CLIENTS }; Index: clang/include/clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h =================================================================== --- clang/include/clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h +++ 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 { Index: clang/lib/Analysis/CMakeLists.txt =================================================================== --- clang/lib/Analysis/CMakeLists.txt +++ clang/lib/Analysis/CMakeLists.txt @@ -17,14 +17,19 @@ 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 Index: clang/lib/Analysis/HTMLPathDiagnosticConsumer.cpp =================================================================== --- clang/lib/Analysis/HTMLPathDiagnosticConsumer.cpp +++ clang/lib/Analysis/HTMLPathDiagnosticConsumer.cpp @@ -1,4 +1,4 @@ -//===- HTMLDiagnostics.cpp - HTML Diagnostics for Paths -------------------===// +//===- HTMLPathDiagnosticConsumer.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,12 +6,13 @@ // //===----------------------------------------------------------------------===// // -// This file defines the HTMLDiagnostics object. +// This file defines the HTMLPathDiagnosticConsumer 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" @@ -24,7 +25,6 @@ #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 @@ namespace { -class HTMLDiagnostics : public PathDiagnosticConsumer { +class HTMLPathDiagnosticConsumer : public PathDiagnosticConsumer { PathDiagnosticConsumerOptions DiagOpts; std::string Directory; bool createdDir = false; @@ -65,20 +65,18 @@ const bool SupportsCrossFileDiagnostics; public: - HTMLDiagnostics(PathDiagnosticConsumerOptions DiagOpts, - const std::string &OutputDir, const Preprocessor &pp, - bool supportsMultipleFiles) - : DiagOpts(std::move(DiagOpts)), Directory(OutputDir), PP(pp), - SupportsCrossFileDiagnostics(supportsMultipleFiles) {} + HTMLPathDiagnosticConsumer(PathDiagnosticConsumerOptions DiagOpts, + const std::string &OutputDir, + const Preprocessor &PP, bool SupportsMultipleFiles) + : DiagOpts(std::move(DiagOpts)), Directory(OutputDir), PP(PP), + SupportsCrossFileDiagnostics(SupportsMultipleFiles) {} - ~HTMLDiagnostics() override { FlushDiagnostics(nullptr); } + ~HTMLPathDiagnosticConsumer() override { FlushDiagnostics(nullptr); } void FlushDiagnosticsImpl(std::vector &Diags, FilesMade *filesMade) override; - StringRef getName() const override { - return "HTMLDiagnostics"; - } + StringRef getName() const override { return "HTMLPathDiagnosticConsumer"; } bool supportsCrossFileDiagnostics() const override { return SupportsCrossFileDiagnostics; @@ -148,7 +146,8 @@ if (OutputDir.empty()) return; - C.push_back(new HTMLDiagnostics(std::move(DiagOpts), OutputDir, PP, true)); + C.push_back( + new HTMLPathDiagnosticConsumer(std::move(DiagOpts), OutputDir, PP, true)); } void ento::createHTMLSingleFileDiagnosticConsumer( @@ -161,34 +160,22 @@ if (OutputDir.empty()) return; - 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); + C.push_back(new HTMLPathDiagnosticConsumer(std::move(DiagOpts), OutputDir, PP, + false)); } //===----------------------------------------------------------------------===// // Report processing. //===----------------------------------------------------------------------===// -void HTMLDiagnostics::FlushDiagnosticsImpl( - std::vector &Diags, - FilesMade *filesMade) { +void HTMLPathDiagnosticConsumer::FlushDiagnosticsImpl( + std::vector &Diags, FilesMade *filesMade) { for (const auto Diag : Diags) ReportDiag(*Diag, filesMade); } -void HTMLDiagnostics::ReportDiag(const PathDiagnostic& D, - FilesMade *filesMade) { +void HTMLPathDiagnosticConsumer::ReportDiag(const PathDiagnostic &D, + FilesMade *filesMade) { // Create the HTML directory if it is missing. if (!createdDir) { createdDir = true; @@ -296,8 +283,11 @@ os << report; } -std::string HTMLDiagnostics::GenerateHTML(const PathDiagnostic& D, Rewriter &R, - const SourceManager& SMgr, const PathPieces& path, const char *declName) { +std::string HTMLPathDiagnosticConsumer::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 FileIDs; for (auto I : path) { @@ -369,9 +359,8 @@ return os.str(); } -void HTMLDiagnostics::dumpCoverageData( - const PathDiagnostic &D, - const PathPieces &path, +void HTMLPathDiagnosticConsumer::dumpCoverageData( + const PathDiagnostic &D, const PathPieces &path, llvm::raw_string_ostream &os) { const FilesToLineNumsMap &ExecutedLines = D.getExecutedLines(); @@ -395,8 +384,8 @@ os << "};"; } -std::string HTMLDiagnostics::showRelevantLinesJavascript( - const PathDiagnostic &D, const PathPieces &path) { +std::string HTMLPathDiagnosticConsumer::showRelevantLinesJavascript( + const PathDiagnostic &D, const PathPieces &path) { std::string s; llvm::raw_string_ostream os(s); os << "