[llvm-branch-commits] [clang] 6b0ee02 - Revert "Revert "Revert "Revert "[analyzer] NFC: Move path diagnostic consumer implementations to libAnalysis.""""
Artem Dergachev via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Thu Jan 7 20:27:13 PST 2021
Author: Artem Dergachev
Date: 2021-01-07T20:22:22-08:00
New Revision: 6b0ee02747ed22d41e175d15f27025183341e6f8
URL: https://github.com/llvm/llvm-project/commit/6b0ee02747ed22d41e175d15f27025183341e6f8
DIFF: https://github.com/llvm/llvm-project/commit/6b0ee02747ed22d41e175d15f27025183341e6f8.diff
LOG: Revert "Revert "Revert "Revert "[analyzer] NFC: Move path diagnostic consumer implementations to libAnalysis.""""
This reverts commit b12f26733a4259c90e5f387aceb9f23c35e003b8.
Fix dead include that looked like another missed circular dependency.
Added:
clang/include/clang/Analysis/CrossTUAnalysisHelper.h
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
Modified:
clang/include/clang/CrossTU/CrossTranslationUnit.h
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/CrossTU/CrossTranslationUnit.cpp
clang/lib/Frontend/CompilerInvocation.cpp
clang/lib/StaticAnalyzer/Core/CMakeLists.txt
clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
Removed:
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
################################################################################
diff --git a/clang/include/clang/Analysis/CrossTUAnalysisHelper.h b/clang/include/clang/Analysis/CrossTUAnalysisHelper.h
new file mode 100644
index 000000000000..500e78ddedcf
--- /dev/null
+++ b/clang/include/clang/Analysis/CrossTUAnalysisHelper.h
@@ -0,0 +1,41 @@
+//===- CrossTUAnalysisHelper.h - Abstraction layer for CTU ------*- 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
+//
+//===----------------------------------------------------------------------===//
+#ifndef LLVM_CLANG_ANALYSIS_CROSS_TU_HELPER_H
+#define LLVM_CLANG_ANALYSIS_CROSS_TU_HELPER_H
+
+#include "llvm/ADT/Optional.h"
+#include "clang/Basic/SourceManager.h"
+
+namespace clang {
+
+class ASTUnit;
+
+/// This class is an abstract interface acting as a bridge between
+/// an analysis that requires lookups across translation units (a user
+/// of that interface) and the facility that implements such lookups
+/// (an implementation of that interface). This is useful to break direct
+/// link-time dependencies between the (possibly shared) libraries in which
+/// the user and the implementation live.
+class CrossTUAnalysisHelper {
+public:
+ /// Determine the original source location in the original TU for an
+ /// imported source location.
+ /// \p ToLoc Source location in the imported-to AST.
+ /// \return Source location in the imported-from AST and the corresponding
+ /// ASTUnit object (the AST was loaded from a file using an internal ASTUnit
+ /// object that is returned here).
+ /// If any error happens (ToLoc is a non-imported source location) empty is
+ /// returned.
+ virtual llvm::Optional<std::pair<SourceLocation /*FromLoc*/, Preprocessor *>>
+ getImportedFromSourceLocationWithPreprocessor(SourceLocation ToLoc) const = 0;
+
+ virtual ~CrossTUAnalysisHelper() {}
+};
+} // namespace clang
+
+#endif // LLVM_CLANG_ANALYSIS_CROSS_TU_HELPER_H
diff --git a/clang/include/clang/Analysis/PathDiagnosticConsumers.def b/clang/include/clang/Analysis/PathDiagnosticConsumers.def
new file mode 100644
index 000000000000..33d2072fcf31
--- /dev/null
+++ b/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
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/PathDiagnosticConsumers.h b/clang/include/clang/Analysis/PathDiagnosticConsumers.h
similarity index 78%
rename from clang/include/clang/StaticAnalyzer/Core/PathDiagnosticConsumers.h
rename to clang/include/clang/Analysis/PathDiagnosticConsumers.h
index f40f88eb32ff..fde2e3498216 100644
--- a/clang/include/clang/StaticAnalyzer/Core/PathDiagnosticConsumers.h
+++ b/clang/include/clang/Analysis/PathDiagnosticConsumers.h
@@ -18,25 +18,24 @@
#include <string>
#include <vector>
+#include "clang/Analysis/PathDiagnostic.h"
+
namespace clang {
class AnalyzerOptions;
class Preprocessor;
-namespace cross_tu {
-class CrossTranslationUnitContext;
-}
+class CrossTUAnalysisHelper;
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/StaticAnalyzer/Core/Analyses.def"
+ const Preprocessor &PP, const CrossTUAnalysisHelper &CTU);
+#include "clang/Analysis/PathDiagnosticConsumers.def"
} // end 'ento' namespace
} // end 'clang' namespace
diff --git a/clang/include/clang/CrossTU/CrossTranslationUnit.h b/clang/include/clang/CrossTU/CrossTranslationUnit.h
index 027c6f16430b..21201f637833 100644
--- a/clang/include/clang/CrossTU/CrossTranslationUnit.h
+++ b/clang/include/clang/CrossTU/CrossTranslationUnit.h
@@ -14,6 +14,7 @@
#ifndef LLVM_CLANG_CROSSTU_CROSSTRANSLATIONUNIT_H
#define LLVM_CLANG_CROSSTU_CROSSTRANSLATIONUNIT_H
+#include "clang/Analysis/CrossTUAnalysisHelper.h"
#include "clang/AST/ASTImporterSharedState.h"
#include "clang/Basic/LLVM.h"
#include "llvm/ADT/DenseMap.h"
@@ -120,10 +121,10 @@ bool containsConst(const VarDecl *VD, const ASTContext &ACtx);
/// the locations of the AST files for each definition.
///
/// Note that this class also implements caching.
-class CrossTranslationUnitContext {
+class CrossTranslationUnitContext : public CrossTUAnalysisHelper {
public:
CrossTranslationUnitContext(CompilerInstance &CI);
- ~CrossTranslationUnitContext();
+ ~CrossTranslationUnitContext() override;
/// This function loads a function or variable definition from an
/// external AST file and merges it into the original AST.
@@ -186,12 +187,24 @@ class CrossTranslationUnitContext {
/// imported source location.
/// \p ToLoc Source location in the imported-to AST.
/// \return Source location in the imported-from AST and the corresponding
- /// ASTUnit object (the AST was loaded from a file using an internal ASTUnit
+ /// ASTUnit object (the AST was loaded from a file using an internal ASTUni
/// object that is returned here).
/// If any error happens (ToLoc is a non-imported source location) empty is
/// returned.
llvm::Optional<std::pair<SourceLocation /*FromLoc*/, ASTUnit *>>
- getImportedFromSourceLocation(const clang::SourceLocation &ToLoc) const;
+ getImportedFromSourceLocation(SourceLocation ToLoc) const;
+
+ /// Determine the original source location in the original TU for an
+ /// imported source location.
+ /// \p ToLoc Source location in the imported-to AST.
+ /// \return Source location in the imported-from AST and the Preprocessor
+ /// corresponding to the AST unit that originally contained the imported-from
+ /// source location.
+ /// If any error happens (ToLoc is a non-imported source location) empty is
+ /// returned.
+ llvm::Optional<std::pair<SourceLocation /*FromLoc*/, Preprocessor *>>
+ getImportedFromSourceLocationWithPreprocessor(
+ SourceLocation ToLoc) const override;
private:
using ImportedFileIDMap =
diff --git a/clang/include/clang/StaticAnalyzer/Core/Analyses.def b/clang/include/clang/StaticAnalyzer/Core/Analyses.def
index c4e5f5be6fd7..2e98cbba4c9e 100644
--- a/clang/include/clang/StaticAnalyzer/Core/Analyses.def
+++ b/clang/include/clang/StaticAnalyzer/Core/Analyses.def
@@ -28,42 +28,6 @@ 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
@@ -91,7 +55,6 @@ 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 ccf35e0a81ec..0dd2c86c5ca9 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/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
index c76e9c0326af..7e8b9de3a942 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 332e533f0347..ec396e1532e0 100644
--- a/clang/include/clang/module.modulemap
+++ b/clang/include/clang/module.modulemap
@@ -3,6 +3,7 @@ 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 ed626a6e130c..94c6e322e02b 100644
--- a/clang/lib/Analysis/CMakeLists.txt
+++ b/clang/lib/Analysis/CMakeLists.txt
@@ -18,14 +18,19 @@ 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
@@ -37,6 +42,8 @@ add_clang_library(clangAnalysis
clangASTMatchers
clangBasic
clangLex
+ clangRewrite
+ clangToolingCore
DEPENDS
omp_gen
diff --git a/clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp b/clang/lib/Analysis/HTMLPathDiagnosticConsumer.cpp
similarity index 91%
rename from clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp
rename to clang/lib/Analysis/HTMLPathDiagnosticConsumer.cpp
index 149459cf986a..fb60819b1c15 100644
--- 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"
@@ -50,13 +50,17 @@
using namespace clang;
using namespace ento;
+namespace clang {
+class CrossTUAnalysisHelper;
+}
+
//===----------------------------------------------------------------------===//
// Boilerplate.
//===----------------------------------------------------------------------===//
namespace {
-class HTMLDiagnostics : public PathDiagnosticConsumer {
+class HTMLPathDiagnosticConsumer : public PathDiagnosticConsumer {
PathDiagnosticConsumerOptions DiagOpts;
std::string Directory;
bool createdDir = false;
@@ -65,20 +69,18 @@ class HTMLDiagnostics : public PathDiagnosticConsumer {
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<const PathDiagnostic *> &Diags,
FilesMade *filesMade) override;
- StringRef getName() const override {
- return "HTMLDiagnostics";
- }
+ StringRef getName() const override { return "HTMLPathDiagnosticConsumer"; }
bool supportsCrossFileDiagnostics() const override {
return SupportsCrossFileDiagnostics;
@@ -135,7 +137,7 @@ class HTMLDiagnostics : public PathDiagnosticConsumer {
void ento::createHTMLDiagnosticConsumer(
PathDiagnosticConsumerOptions DiagOpts, PathDiagnosticConsumers &C,
const std::string &OutputDir, const Preprocessor &PP,
- const cross_tu::CrossTranslationUnitContext &CTU) {
+ const CrossTUAnalysisHelper &CTU) {
// FIXME: HTML is currently our default output type, but if the output
// directory isn't specified, it acts like if it was in the minimal text
@@ -148,47 +150,36 @@ void ento::createHTMLDiagnosticConsumer(
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(
PathDiagnosticConsumerOptions DiagOpts, PathDiagnosticConsumers &C,
const std::string &OutputDir, const Preprocessor &PP,
- const cross_tu::CrossTranslationUnitContext &CTU) {
+ const CrossTUAnalysisHelper &CTU) {
createTextMinimalPathDiagnosticConsumer(DiagOpts, C, OutputDir, PP, CTU);
// TODO: Emit an error here.
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<const PathDiagnostic *> &Diags,
- FilesMade *filesMade) {
+void HTMLPathDiagnosticConsumer::FlushDiagnosticsImpl(
+ std::vector<const PathDiagnostic *> &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 +287,11 @@ void HTMLDiagnostics::ReportDiag(const PathDiagnostic& D,
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<FileID> FileIDs;
for (auto I : path) {
@@ -369,9 +363,8 @@ std::string HTMLDiagnostics::GenerateHTML(const PathDiagnostic& D, Rewriter &R,
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 +388,8 @@ void HTMLDiagnostics::dumpCoverageData(
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 << "<script type='text/javascript'>\n";
@@ -460,9 +453,10 @@ document.addEventListener("DOMContentLoaded", function() {
return os.str();
}
-void HTMLDiagnostics::FinalizeHTML(const PathDiagnostic& D, Rewriter &R,
- const SourceManager& SMgr, const PathPieces& path, FileID FID,
- const FileEntry *Entry, const char *declName) {
+void HTMLPathDiagnosticConsumer::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.
@@ -607,7 +601,7 @@ void HTMLDiagnostics::FinalizeHTML(const PathDiagnostic& D, Rewriter &R,
html::AddHeaderFooterInternalBuiltinCSS(R, FID, Entry->getName());
}
-StringRef HTMLDiagnostics::showHelpJavascript() {
+StringRef HTMLPathDiagnosticConsumer::showHelpJavascript() {
return R"<<<(
<script type='text/javascript'>
@@ -690,8 +684,9 @@ static void HandlePopUpPieceEndTag(Rewriter &R,
}
}
-void HTMLDiagnostics::RewriteFile(Rewriter &R,
- const PathPieces& path, FileID FID) {
+void HTMLPathDiagnosticConsumer::RewriteFile(Rewriter &R,
+ const PathPieces &path,
+ FileID FID) {
// Process the path.
// Maintain the counts of extra note pieces separately.
unsigned TotalPieces = path.size();
@@ -769,10 +764,9 @@ void HTMLDiagnostics::RewriteFile(Rewriter &R,
html::HighlightMacros(R, FID, PP);
}
-void HTMLDiagnostics::HandlePiece(Rewriter &R, FileID BugFileID,
- const PathDiagnosticPiece &P,
- const std::vector<SourceRange> &PopUpRanges,
- unsigned num, unsigned max) {
+void HTMLPathDiagnosticConsumer::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();
@@ -1004,9 +998,8 @@ static void EmitAlphaCounter(raw_ostream &os, unsigned n) {
os << char('a' + x);
}
-unsigned HTMLDiagnostics::ProcessMacroPiece(raw_ostream &os,
- const PathDiagnosticMacroPiece& P,
- unsigned num) {
+unsigned HTMLPathDiagnosticConsumer::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);
@@ -1028,10 +1021,10 @@ unsigned HTMLDiagnostics::ProcessMacroPiece(raw_ostream &os,
return num;
}
-void HTMLDiagnostics::HighlightRange(Rewriter& R, FileID BugFileID,
- SourceRange Range,
- const char *HighlightStart,
- const char *HighlightEnd) {
+void HTMLPathDiagnosticConsumer::HighlightRange(Rewriter &R, FileID BugFileID,
+ SourceRange Range,
+ const char *HighlightStart,
+ const char *HighlightEnd) {
SourceManager &SM = R.getSourceMgr();
const LangOptions &LangOpts = R.getLangOpts();
@@ -1066,7 +1059,7 @@ void HTMLDiagnostics::HighlightRange(Rewriter& R, FileID BugFileID,
html::HighlightRange(R, InstantiationStart, E, HighlightStart, HighlightEnd);
}
-StringRef HTMLDiagnostics::generateKeyboardNavigationJavascript() {
+StringRef HTMLPathDiagnosticConsumer::generateKeyboardNavigationJavascript() {
return R"<<<(
<script type='text/javascript'>
var digitMatcher = new RegExp("[0-9]+");
diff --git a/clang/lib/Analysis/PlistHTMLPathDiagnosticConsumer.cpp b/clang/lib/Analysis/PlistHTMLPathDiagnosticConsumer.cpp
new file mode 100644
index 000000000000..ca453ff700bd
--- /dev/null
+++ b/clang/lib/Analysis/PlistHTMLPathDiagnosticConsumer.cpp
@@ -0,0 +1,35 @@
+//===--- 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/Lex/Preprocessor.h"
+#include "llvm/Support/Path.h"
+
+using namespace clang;
+using namespace ento;
+
+namespace clang {
+class CrossTUAnalysisHelper;
+}
+
+void ento::createPlistHTMLDiagnosticConsumer(
+ PathDiagnosticConsumerOptions DiagOpts, PathDiagnosticConsumers &C,
+ const std::string &Prefix, const Preprocessor &PP,
+ const CrossTUAnalysisHelper &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/StaticAnalyzer/Core/PlistDiagnostics.cpp b/clang/lib/Analysis/PlistPathDiagnosticConsumer.cpp
similarity index 96%
rename from clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
rename to clang/lib/Analysis/PlistPathDiagnosticConsumer.cpp
index 35e320c7755f..52a488162dba 100644
--- a/clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
+++ b/clang/lib/Analysis/PlistPathDiagnosticConsumer.cpp
@@ -1,4 +1,4 @@
-//===--- PlistDiagnostics.cpp - Plist Diagnostics for Paths -----*- C++ -*-===//
+//===--- PlistPathDiagnosticConsumer.cpp - Plist Diagnostics ----*- 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,22 +6,21 @@
//
//===----------------------------------------------------------------------===//
//
-// This file defines the PlistDiagnostics object.
+// This file defines the PlistPathDiagnosticConsumer object.
//
//===----------------------------------------------------------------------===//
+#include "clang/Analysis/CrossTUAnalysisHelper.h"
#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"
#include "clang/Basic/Version.h"
-#include "clang/CrossTU/CrossTranslationUnit.h"
-#include "clang/Frontend/ASTUnit.h"
#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,29 +37,29 @@ using namespace markup;
//===----------------------------------------------------------------------===//
namespace {
- class PlistDiagnostics : public PathDiagnosticConsumer {
+ class PlistPathDiagnosticConsumer : public PathDiagnosticConsumer {
PathDiagnosticConsumerOptions DiagOpts;
const std::string OutputFile;
const Preprocessor &PP;
- const cross_tu::CrossTranslationUnitContext &CTU;
+ const CrossTUAnalysisHelper &CTU;
const bool SupportsCrossFileDiagnostics;
void printBugPath(llvm::raw_ostream &o, const FIDMap &FM,
const PathPieces &Path);
public:
- PlistDiagnostics(PathDiagnosticConsumerOptions DiagOpts,
+ PlistPathDiagnosticConsumer(PathDiagnosticConsumerOptions DiagOpts,
const std::string &OutputFile, const Preprocessor &PP,
- const cross_tu::CrossTranslationUnitContext &CTU,
+ const CrossTUAnalysisHelper &CTU,
bool supportsMultipleFiles);
- ~PlistDiagnostics() override {}
+ ~PlistPathDiagnosticConsumer() override {}
void FlushDiagnosticsImpl(std::vector<const PathDiagnostic *> &Diags,
FilesMade *filesMade) override;
StringRef getName() const override {
- return "PlistDiagnostics";
+ return "PlistPathDiagnosticConsumer";
}
PathGenerationScheme getGenerationScheme() const override {
@@ -79,13 +78,13 @@ namespace {
class PlistPrinter {
const FIDMap& FM;
const Preprocessor &PP;
- const cross_tu::CrossTranslationUnitContext &CTU;
+ const CrossTUAnalysisHelper &CTU;
llvm::SmallVector<const PathDiagnosticMacroPiece *, 0> MacroPieces;
public:
PlistPrinter(const FIDMap& FM,
const Preprocessor &PP,
- const cross_tu::CrossTranslationUnitContext &CTU)
+ const CrossTUAnalysisHelper &CTU)
: FM(FM), PP(PP), CTU(CTU) {
}
@@ -175,7 +174,7 @@ static void printCoverage(const PathDiagnostic *D,
static ExpansionInfo
getExpandedMacro(SourceLocation MacroLoc, const Preprocessor &PP,
- const cross_tu::CrossTranslationUnitContext &CTU);
+ const CrossTUAnalysisHelper &CTU);
//===----------------------------------------------------------------------===//
// Methods of PlistPrinter.
@@ -516,12 +515,12 @@ static void printCoverage(const PathDiagnostic *D,
}
//===----------------------------------------------------------------------===//
-// Methods of PlistDiagnostics.
+// Methods of PlistPathDiagnosticConsumer.
//===----------------------------------------------------------------------===//
-PlistDiagnostics::PlistDiagnostics(
+PlistPathDiagnosticConsumer::PlistPathDiagnosticConsumer(
PathDiagnosticConsumerOptions DiagOpts, const std::string &output,
- const Preprocessor &PP, const cross_tu::CrossTranslationUnitContext &CTU,
+ const Preprocessor &PP, const CrossTUAnalysisHelper &CTU,
bool supportsMultipleFiles)
: DiagOpts(std::move(DiagOpts)), OutputFile(output), PP(PP), CTU(CTU),
SupportsCrossFileDiagnostics(supportsMultipleFiles) {
@@ -532,14 +531,14 @@ PlistDiagnostics::PlistDiagnostics(
void ento::createPlistDiagnosticConsumer(
PathDiagnosticConsumerOptions DiagOpts, PathDiagnosticConsumers &C,
const std::string &OutputFile, const Preprocessor &PP,
- const cross_tu::CrossTranslationUnitContext &CTU) {
+ const CrossTUAnalysisHelper &CTU) {
// TODO: Emit an error here.
if (OutputFile.empty())
return;
- C.push_back(new PlistDiagnostics(DiagOpts, OutputFile, PP, CTU,
- /*supportsMultipleFiles=*/false));
+ C.push_back(new PlistPathDiagnosticConsumer(DiagOpts, OutputFile, PP, CTU,
+ /*supportsMultipleFiles=*/false));
createTextMinimalPathDiagnosticConsumer(std::move(DiagOpts), C, OutputFile,
PP, CTU);
}
@@ -547,20 +546,21 @@ void ento::createPlistDiagnosticConsumer(
void ento::createPlistMultiFileDiagnosticConsumer(
PathDiagnosticConsumerOptions DiagOpts, PathDiagnosticConsumers &C,
const std::string &OutputFile, const Preprocessor &PP,
- const cross_tu::CrossTranslationUnitContext &CTU) {
+ const CrossTUAnalysisHelper &CTU) {
// TODO: Emit an error here.
if (OutputFile.empty())
return;
- C.push_back(new PlistDiagnostics(DiagOpts, OutputFile, PP, CTU,
- /*supportsMultipleFiles=*/true));
+ C.push_back(new PlistPathDiagnosticConsumer(DiagOpts, OutputFile, PP, CTU,
+ /*supportsMultipleFiles=*/true));
createTextMinimalPathDiagnosticConsumer(std::move(DiagOpts), C, OutputFile,
PP, CTU);
}
-void PlistDiagnostics::printBugPath(llvm::raw_ostream &o, const FIDMap &FM,
- const PathPieces &Path) {
+void PlistPathDiagnosticConsumer::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) {
@@ -603,9 +603,8 @@ void PlistDiagnostics::printBugPath(llvm::raw_ostream &o, const FIDMap &FM,
o << " </array>\n";
}
-void PlistDiagnostics::FlushDiagnosticsImpl(
- std::vector<const PathDiagnostic *> &Diags,
- FilesMade *filesMade) {
+void PlistPathDiagnosticConsumer::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;
@@ -985,12 +984,13 @@ static const MacroInfo *getMacroInfoForLocation(const Preprocessor &PP,
static ExpansionInfo
getExpandedMacro(SourceLocation MacroLoc, const Preprocessor &PP,
- const cross_tu::CrossTranslationUnitContext &CTU) {
+ const CrossTUAnalysisHelper &CTU) {
const Preprocessor *PPToUse = &PP;
- if (auto LocAndUnit = CTU.getImportedFromSourceLocation(MacroLoc)) {
+ if (auto LocAndUnit =
+ CTU.getImportedFromSourceLocationWithPreprocessor(MacroLoc)) {
MacroLoc = LocAndUnit->first;
- PPToUse = &LocAndUnit->second->getPreprocessor();
+ PPToUse = LocAndUnit->second;
}
llvm::SmallString<200> ExpansionBuf;
diff --git a/clang/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp b/clang/lib/Analysis/SarifPathDiagnosticConsumer.cpp
similarity index 93%
rename from clang/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp
rename to clang/lib/Analysis/SarifPathDiagnosticConsumer.cpp
index f93d04ccd61a..e2fcad5b8e15 100644
--- a/clang/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp
+++ b/clang/lib/Analysis/SarifPathDiagnosticConsumer.cpp
@@ -1,4 +1,4 @@
-//===--- SarifDiagnostics.cpp - Sarif Diagnostics for Paths -----*- C++ -*-===//
+//===--- SarifPathDiagnosticConsumer.cpp - Sarif Diagnostics ---*- 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 SarifDiagnostics object.
+// This file defines the SarifPathDiagnosticConsumer 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"
@@ -25,20 +25,24 @@ using namespace llvm;
using namespace clang;
using namespace ento;
+namespace clang {
+class CrossTUAnalysisHelper;
+}
+
namespace {
-class SarifDiagnostics : public PathDiagnosticConsumer {
+class SarifPathDiagnosticConsumer : public PathDiagnosticConsumer {
std::string OutputFile;
const LangOptions &LO;
public:
- SarifDiagnostics(const std::string &Output, const LangOptions &LO)
+ SarifPathDiagnosticConsumer(const std::string &Output, const LangOptions &LO)
: OutputFile(Output), LO(LO) {}
- ~SarifDiagnostics() override = default;
+ ~SarifPathDiagnosticConsumer() override = default;
void FlushDiagnosticsImpl(std::vector<const PathDiagnostic *> &Diags,
FilesMade *FM) override;
- StringRef getName() const override { return "SarifDiagnostics"; }
+ StringRef getName() const override { return "SarifPathDiagnosticConsumer"; }
PathGenerationScheme getGenerationScheme() const override { return Minimal; }
bool supportsLogicalOpControlFlow() const override { return true; }
bool supportsCrossFileDiagnostics() const override { return true; }
@@ -48,13 +52,13 @@ class SarifDiagnostics : public PathDiagnosticConsumer {
void ento::createSarifDiagnosticConsumer(
PathDiagnosticConsumerOptions DiagOpts, PathDiagnosticConsumers &C,
const std::string &Output, const Preprocessor &PP,
- const cross_tu::CrossTranslationUnitContext &CTU) {
+ const CrossTUAnalysisHelper &CTU) {
// TODO: Emit an error here.
if (Output.empty())
return;
- C.push_back(new SarifDiagnostics(Output, PP.getLangOpts()));
+ C.push_back(new SarifPathDiagnosticConsumer(Output, PP.getLangOpts()));
createTextMinimalPathDiagnosticConsumer(std::move(DiagOpts), C, Output, PP,
CTU);
}
@@ -299,6 +303,9 @@ 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) \
@@ -310,6 +317,9 @@ 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) \
@@ -377,7 +387,7 @@ static json::Object createRun(const LangOptions &LO,
{"columnKind", "unicodeCodePoints"}};
}
-void SarifDiagnostics::FlushDiagnosticsImpl(
+void SarifPathDiagnosticConsumer::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/StaticAnalyzer/Core/TextDiagnostics.cpp b/clang/lib/Analysis/TextPathDiagnosticConsumer.cpp
similarity index 79%
rename from clang/lib/StaticAnalyzer/Core/TextDiagnostics.cpp
rename to clang/lib/Analysis/TextPathDiagnosticConsumer.cpp
index ae2bad7ee77c..e9010d5c08aa 100644
--- a/clang/lib/StaticAnalyzer/Core/TextDiagnostics.cpp
+++ b/clang/lib/Analysis/TextPathDiagnosticConsumer.cpp
@@ -1,4 +1,4 @@
-//===--- TextDiagnostics.cpp - Text Diagnostics for Paths -------*- C++ -*-===//
+//===--- TextPathDiagnosticConsumer.cpp - Text Diagnostics ------*- 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,19 +6,17 @@
//
//===----------------------------------------------------------------------===//
//
-// This file defines the TextDiagnostics object.
+// This file defines the TextPathDiagnosticConsumer 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"
@@ -29,25 +27,29 @@ using namespace clang;
using namespace ento;
using namespace tooling;
+namespace clang {
+class CrossTUAnalysisHelper;
+}
+
namespace {
-/// Emitsd minimal diagnostics (report message + notes) for the 'none' output
+/// Emits 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 TextDiagnostics : public PathDiagnosticConsumer {
+class TextPathDiagnosticConsumer : public PathDiagnosticConsumer {
PathDiagnosticConsumerOptions DiagOpts;
DiagnosticsEngine &DiagEng;
const LangOptions &LO;
bool ShouldDisplayPathNotes;
public:
- TextDiagnostics(PathDiagnosticConsumerOptions DiagOpts,
- DiagnosticsEngine &DiagEng, const LangOptions &LO,
- bool ShouldDisplayPathNotes)
+ TextPathDiagnosticConsumer(PathDiagnosticConsumerOptions DiagOpts,
+ DiagnosticsEngine &DiagEng, const LangOptions &LO,
+ bool ShouldDisplayPathNotes)
: DiagOpts(std::move(DiagOpts)), DiagEng(DiagEng), LO(LO),
ShouldDisplayPathNotes(ShouldDisplayPathNotes) {}
- ~TextDiagnostics() override {}
+ ~TextPathDiagnosticConsumer() override {}
- StringRef getName() const override { return "TextDiagnostics"; }
+ StringRef getName() const override { return "TextPathDiagnosticConsumer"; }
bool supportsLogicalOpControlFlow() const override { return true; }
bool supportsCrossFileDiagnostics() const override { return true; }
@@ -139,17 +141,17 @@ class TextDiagnostics : public PathDiagnosticConsumer {
void ento::createTextPathDiagnosticConsumer(
PathDiagnosticConsumerOptions DiagOpts, PathDiagnosticConsumers &C,
const std::string &Prefix, const clang::Preprocessor &PP,
- const cross_tu::CrossTranslationUnitContext &CTU) {
- C.emplace_back(new TextDiagnostics(std::move(DiagOpts), PP.getDiagnostics(),
- PP.getLangOpts(),
- /*ShouldDisplayPathNotes=*/true));
+ const CrossTUAnalysisHelper &CTU) {
+ C.emplace_back(new TextPathDiagnosticConsumer(
+ 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 TextDiagnostics(std::move(DiagOpts), PP.getDiagnostics(),
- PP.getLangOpts(),
- /*ShouldDisplayPathNotes=*/false));
+ const CrossTUAnalysisHelper &CTU) {
+ C.emplace_back(new TextPathDiagnosticConsumer(
+ std::move(DiagOpts), PP.getDiagnostics(), PP.getLangOpts(),
+ /*ShouldDisplayPathNotes=*/false));
}
diff --git a/clang/lib/CrossTU/CrossTranslationUnit.cpp b/clang/lib/CrossTU/CrossTranslationUnit.cpp
index e27779f91abc..5ab5d6def2a2 100644
--- a/clang/lib/CrossTU/CrossTranslationUnit.cpp
+++ b/clang/lib/CrossTU/CrossTranslationUnit.cpp
@@ -765,7 +765,7 @@ CrossTranslationUnitContext::getOrCreateASTImporter(ASTUnit *Unit) {
llvm::Optional<std::pair<SourceLocation, ASTUnit *>>
CrossTranslationUnitContext::getImportedFromSourceLocation(
- const clang::SourceLocation &ToLoc) const {
+ SourceLocation ToLoc) const {
const SourceManager &SM = Context.getSourceManager();
auto DecToLoc = SM.getDecomposedLoc(ToLoc);
@@ -781,5 +781,16 @@ CrossTranslationUnitContext::getImportedFromSourceLocation(
return std::make_pair(FromLoc, Unit);
}
+llvm::Optional<std::pair<SourceLocation, Preprocessor *>>
+CrossTranslationUnitContext::getImportedFromSourceLocationWithPreprocessor(
+ SourceLocation ToLoc) const {
+ if (llvm::Optional<std::pair<SourceLocation, ASTUnit *>> LocAndUnit =
+ getImportedFromSourceLocation(ToLoc)) {
+ return std::make_pair(LocAndUnit->first,
+ &LocAndUnit->second->getPreprocessor());
+ }
+ return None;
+}
+
} // namespace cross_tu
} // namespace clang
diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp
index 6795151d08d5..348f5582bde2 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -571,7 +571,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/StaticAnalyzer/Core/Analyses.def"
+#include "clang/Analysis/PathDiagnosticConsumers.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 d947d415ad6e..b1f527ed75d5 100644
--- a/clang/lib/StaticAnalyzer/Core/CMakeLists.txt
+++ b/clang/lib/StaticAnalyzer/Core/CMakeLists.txt
@@ -30,16 +30,13 @@ 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
@@ -47,7 +44,6 @@ add_clang_library(clangStaticAnalyzerCore
SValBuilder.cpp
SVals.cpp
SymbolManager.cpp
- TextDiagnostics.cpp
WorkList.cpp
LINK_LIBS
diff --git a/clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp b/clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
index f2a19b2ccc90..1e94950ca097 100644
--- a/clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
+++ b/clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
@@ -21,6 +21,7 @@
#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"
@@ -30,7 +31,6 @@
#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/StaticAnalyzer/Core/Analyses.def"
+#include "clang/Analysis/PathDiagnosticConsumers.def"
default:
llvm_unreachable("Unknown analyzer output type!");
}
More information about the llvm-branch-commits
mailing list