diff --git a/clang/include/clang/StaticAnalyzer/Core/PathDiagnosticConsumers.h b/clang/include/clang/Analysis/PathDiagnosticConsumers.h rename from clang/include/clang/StaticAnalyzer/Core/PathDiagnosticConsumers.h rename to clang/include/clang/Analysis/PathDiagnosticConsumers.h --- a/clang/include/clang/StaticAnalyzer/Core/PathDiagnosticConsumers.h +++ b/clang/include/clang/Analysis/PathDiagnosticConsumers.h @@ -16,6 +16,8 @@ #include #include +#include "clang/Analysis/PathDiagnostic.h" + namespace clang { class AnalyzerOptions; @@ -27,14 +29,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 diff --git a/clang/include/clang/StaticAnalyzer/Core/Analyses.def b/clang/include/clang/Analysis/PathDiagnosticConsumers.def copy from clang/include/clang/StaticAnalyzer/Core/Analyses.def copy to clang/include/clang/Analysis/PathDiagnosticConsumers.def --- a/clang/include/clang/StaticAnalyzer/Core/Analyses.def +++ b/clang/include/clang/Analysis/PathDiagnosticConsumers.def @@ -1,4 +1,4 @@ -//===-- Analyses.def - Metadata about Static Analyses -----------*- C++ -*-===// +//===-- 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. @@ -6,28 +6,11 @@ // //===----------------------------------------------------------------------===// // -// This file defines the set of static analyses used by AnalysisConsumer. +// This file defines the set of path diagnostic consumers - objects that +// implement different representations of static analysis results. // //===----------------------------------------------------------------------===// -#ifndef ANALYSIS_STORE -#define ANALYSIS_STORE(NAME, CMDFLAG, DESC, CREATFN) -#endif - -ANALYSIS_STORE(RegionStore, "region", "Use region-based analyzer store", - CreateRegionStoreManager) - -#ifndef ANALYSIS_CONSTRAINTS -#define ANALYSIS_CONSTRAINTS(NAME, CMDFLAG, DESC, CREATFN) -#endif - -ANALYSIS_CONSTRAINTS(RangeConstraints, "range", - "Use constraint tracking of concrete value ranges", - CreateRangeConstraintManager) - -ANALYSIS_CONSTRAINTS(Z3Constraints, "z3", "Use Z3 contraint solver", - CreateZ3ConstraintManager) - #ifndef ANALYSIS_DIAGNOSTICS #define ANALYSIS_DIAGNOSTICS(NAME, CMDFLAG, DESC, CREATEFN) #endif @@ -64,34 +47,4 @@ "used in addition to other analysis types", createTextMinimalPathDiagnosticConsumer) -#ifndef ANALYSIS_PURGE -#define ANALYSIS_PURGE(NAME, CMDFLAG, DESC) -#endif - -ANALYSIS_PURGE( - PurgeStmt, "statement", - "Purge symbols, bindings, and constraints before every statement") - -ANALYSIS_PURGE( - PurgeBlock, "block", - "Purge symbols, bindings, and constraints before every basic block") - -ANALYSIS_PURGE(PurgeNone, "none", - "Do not purge symbols, bindings, or constraints") - -#ifndef ANALYSIS_INLINING_MODE -#define ANALYSIS_INLINING_MODE(NAME, CMDFLAG, DESC) -#endif - -ANALYSIS_INLINING_MODE(All, "all", "Analyze all functions as top level") - -ANALYSIS_INLINING_MODE( - NoRedundancy, "noredundancy", - "Do not analyze a function which has been previously inlined") - -#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/Analyses.def b/clang/include/clang/StaticAnalyzer/Core/Analyses.def --- a/clang/include/clang/StaticAnalyzer/Core/Analyses.def +++ b/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 diff --git a/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h b/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h --- a/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h +++ b/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 }; diff --git a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h --- 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 --- a/clang/include/clang/module.modulemap +++ b/clang/include/clang/module.modulemap @@ -3,6 +3,7 @@ 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 --- a/clang/lib/Analysis/CMakeLists.txt +++ b/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 diff --git a/clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp b/clang/lib/Analysis/HTMLPathDiagnosticConsumer.cpp rename from clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp rename to clang/lib/Analysis/HTMLPathDiagnosticConsumer.cpp --- a/clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp +++ b/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 << "