[clang] 10f1ca9 - Revert "[analyzer] NFC: Separate PathDiagnosticConsumer options from AnalyzerOptions."
Artem Dergachev via cfe-commits
cfe-commits at lists.llvm.org
Tue Oct 13 12:07:52 PDT 2020
Author: Artem Dergachev
Date: 2020-10-13T12:07:36-07:00
New Revision: 10f1ca99b498347186ec74b01046ad292bde9a4c
URL: https://github.com/llvm/llvm-project/commit/10f1ca99b498347186ec74b01046ad292bde9a4c
DIFF: https://github.com/llvm/llvm-project/commit/10f1ca99b498347186ec74b01046ad292bde9a4c.diff
LOG: Revert "[analyzer] NFC: Separate PathDiagnosticConsumer options from AnalyzerOptions."
This reverts commit fd4b3f123d6e64769881e4c6351d5bbbdac30ce3.
Added:
Modified:
clang/include/clang/Analysis/PathDiagnostic.h
clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
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
clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/Analysis/PathDiagnostic.h b/clang/include/clang/Analysis/PathDiagnostic.h
index 544e9f4662d3..c4b042a51bb5 100644
--- a/clang/include/clang/Analysis/PathDiagnostic.h
+++ b/clang/include/clang/Analysis/PathDiagnostic.h
@@ -58,47 +58,6 @@ namespace ento {
class PathDiagnostic;
-/// These options tweak the behavior of path diangostic consumers.
-/// Most of these options are currently supported by very few consumers.
-struct PathDiagnosticConsumerOptions {
- /// Run-line of the tool that produced the diagnostic.
- /// It can be included with the diagnostic for debugging purposes.
- std::string ToolInvocation;
-
- /// Whether to include additional information about macro expansions
- /// with the diagnostics, because otherwise they can be hard to obtain
- /// without re-compiling the program under analysis.
- bool ShouldDisplayMacroExpansions;
-
- /// Whether to include LLVM statistics of the process in the diagnostic.
- /// Useful for profiling the tool on large real-world codebases.
- bool ShouldSerializeStats;
-
- /// If the consumer intends to produce multiple output files, should it
- /// use randomly generated file names for these files (with the tiny risk of
- /// having random collisions) or deterministic human-readable file names
- /// (with a larger risk of deterministic collisions or invalid characters
- /// in the file name). We should not really give this choice to the users
- /// because deterministic mode is always superior when done right, but
- /// for some consumers this mode is experimental and needs to be
- /// off by default.
- bool ShouldWriteStableReportFilename;
-
- /// Whether the consumer should treat consumed diagnostics as hard errors.
- /// Useful for breaking your build when issues are found.
- bool ShouldDisplayWarningsAsErrors;
-
- /// Whether the consumer should attempt to rewrite the source file
- /// with fix-it hints attached to the diagnostics it consumes.
- bool ShouldApplyFixIts;
-
- /// Whether the consumer should present the name of the entity that emitted
- /// the diagnostic (eg., a checker) so that the user knew how to disable it.
- bool ShouldDisplayDiagnosticName;
-
- PathDiagnosticConsumerOptions() = delete;
-};
-
class PathDiagnosticConsumer {
public:
class PDFileEntry : public llvm::FoldingSetNode {
diff --git a/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h b/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
index e1093772e02c..4907b0757a8a 100644
--- a/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
+++ b/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
@@ -14,7 +14,6 @@
#ifndef LLVM_CLANG_STATICANALYZER_CORE_ANALYZEROPTIONS_H
#define LLVM_CLANG_STATICANALYZER_CORE_ANALYZEROPTIONS_H
-#include "clang/Analysis/PathDiagnostic.h"
#include "clang/Basic/LLVM.h"
#include "llvm/ADT/IntrusiveRefCntPtr.h"
#include "llvm/ADT/Optional.h"
@@ -256,7 +255,7 @@ class AnalyzerOptions : public RefCountedBase<AnalyzerOptions> {
unsigned NoRetryExhausted : 1;
/// Emit analyzer warnings as errors.
- bool AnalyzerWerror : 1;
+ unsigned AnalyzerWerror : 1;
/// The inlining stack depth limit.
// Cap the stack depth at 4 calls (5 stack frames, base + 4 calls).
@@ -391,16 +390,6 @@ class AnalyzerOptions : public RefCountedBase<AnalyzerOptions> {
///
/// \sa CXXMemberInliningMode
bool mayInlineCXXMemberFunction(CXXInlineableMemberKind K) const;
-
- ento::PathDiagnosticConsumerOptions getDiagOpts() const {
- return {FullCompilerInvocation,
- ShouldDisplayMacroExpansions,
- ShouldSerializeStats,
- ShouldWriteStableReportFilename,
- AnalyzerWerror,
- ShouldApplyFixIts,
- ShouldDisplayCheckerNameForText};
- }
};
using AnalyzerOptionsRef = IntrusiveRefCntPtr<AnalyzerOptions>;
diff --git a/clang/include/clang/StaticAnalyzer/Core/PathDiagnosticConsumers.h b/clang/include/clang/StaticAnalyzer/Core/PathDiagnosticConsumers.h
index 4b63812b2f83..8601966c91e5 100644
--- a/clang/include/clang/StaticAnalyzer/Core/PathDiagnosticConsumers.h
+++ b/clang/include/clang/StaticAnalyzer/Core/PathDiagnosticConsumers.h
@@ -30,9 +30,8 @@ class PathDiagnosticConsumer;
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, \
+ void CREATEFN(AnalyzerOptions &AnalyzerOpts, PathDiagnosticConsumers &C, \
+ const std::string &Prefix, const Preprocessor &PP, \
const cross_tu::CrossTranslationUnitContext &CTU);
#include "clang/StaticAnalyzer/Core/Analyses.def"
diff --git a/clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp b/clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp
index 20e1ad307bc3..bc7c41d039c4 100644
--- a/clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp
+++ b/clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp
@@ -23,6 +23,7 @@
#include "clang/Lex/Token.h"
#include "clang/Rewrite/Core/HTMLRewrite.h"
#include "clang/Rewrite/Core/Rewriter.h"
+#include "clang/StaticAnalyzer/Core/AnalyzerOptions.h"
#include "clang/StaticAnalyzer/Core/IssueHash.h"
#include "clang/StaticAnalyzer/Core/PathDiagnosticConsumers.h"
#include "llvm/ADT/ArrayRef.h"
@@ -57,18 +58,17 @@ using namespace ento;
namespace {
class HTMLDiagnostics : public PathDiagnosticConsumer {
- PathDiagnosticConsumerOptions DiagOpts;
std::string Directory;
bool createdDir = false;
bool noDir = false;
const Preprocessor &PP;
+ AnalyzerOptions &AnalyzerOpts;
const bool SupportsCrossFileDiagnostics;
public:
- HTMLDiagnostics(PathDiagnosticConsumerOptions DiagOpts,
- const std::string &OutputDir, const Preprocessor &pp,
- bool supportsMultipleFiles)
- : DiagOpts(std::move(DiagOpts)), Directory(OutputDir), PP(pp),
+ HTMLDiagnostics(AnalyzerOptions &AnalyzerOpts, const std::string &OutputDir,
+ const Preprocessor &pp, bool supportsMultipleFiles)
+ : Directory(OutputDir), PP(pp), AnalyzerOpts(AnalyzerOpts),
SupportsCrossFileDiagnostics(supportsMultipleFiles) {}
~HTMLDiagnostics() override { FlushDiagnostics(nullptr); }
@@ -133,7 +133,7 @@ class HTMLDiagnostics : public PathDiagnosticConsumer {
} // namespace
void ento::createHTMLDiagnosticConsumer(
- PathDiagnosticConsumerOptions DiagOpts, PathDiagnosticConsumers &C,
+ AnalyzerOptions &AnalyzerOpts, PathDiagnosticConsumers &C,
const std::string &OutputDir, const Preprocessor &PP,
const cross_tu::CrossTranslationUnitContext &CTU) {
@@ -142,38 +142,37 @@ void ento::createHTMLDiagnosticConsumer(
// output mode. This doesn't make much sense, we should have the minimal text
// as our default. In the case of backward compatibility concerns, this could
// be preserved with -analyzer-config-compatibility-mode=true.
- createTextMinimalPathDiagnosticConsumer(DiagOpts, C, OutputDir, PP, CTU);
+ createTextMinimalPathDiagnosticConsumer(AnalyzerOpts, C, OutputDir, PP, CTU);
// TODO: Emit an error here.
if (OutputDir.empty())
return;
- C.push_back(new HTMLDiagnostics(std::move(DiagOpts), OutputDir, PP, true));
+ C.push_back(new HTMLDiagnostics(AnalyzerOpts, OutputDir, PP, true));
}
void ento::createHTMLSingleFileDiagnosticConsumer(
- PathDiagnosticConsumerOptions DiagOpts, PathDiagnosticConsumers &C,
+ AnalyzerOptions &AnalyzerOpts, PathDiagnosticConsumers &C,
const std::string &OutputDir, const Preprocessor &PP,
const cross_tu::CrossTranslationUnitContext &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));
+ C.push_back(new HTMLDiagnostics(AnalyzerOpts, OutputDir, PP, false));
+ createTextMinimalPathDiagnosticConsumer(AnalyzerOpts, C, OutputDir, PP, CTU);
}
void ento::createPlistHTMLDiagnosticConsumer(
- PathDiagnosticConsumerOptions DiagOpts, PathDiagnosticConsumers &C,
+ AnalyzerOptions &AnalyzerOpts, 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,
+ AnalyzerOpts, 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);
+ createPlistMultiFileDiagnosticConsumer(AnalyzerOpts, C, prefix, PP, CTU);
+ createTextMinimalPathDiagnosticConsumer(AnalyzerOpts, C, prefix, PP, CTU);
}
//===----------------------------------------------------------------------===//
@@ -246,7 +245,7 @@ void HTMLDiagnostics::ReportDiag(const PathDiagnostic& D,
int FD;
SmallString<128> Model, ResultPath;
- if (!DiagOpts.ShouldWriteStableReportFilename) {
+ if (!AnalyzerOpts.ShouldWriteStableReportFilename) {
llvm::sys::path::append(Model, Directory, "report-%%%%%%.html");
if (std::error_code EC =
llvm::sys::fs::make_absolute(Model)) {
@@ -536,7 +535,7 @@ void HTMLDiagnostics::FinalizeHTML(const PathDiagnostic& D, Rewriter &R,
<input type="checkbox" class="spoilerhider" id="showinvocation" />
<label for="showinvocation" >Show analyzer invocation</label>
<div class="spoiler">clang -cc1 )<<<";
- os << html::EscapeText(DiagOpts.ToolInvocation);
+ os << html::EscapeText(AnalyzerOpts.FullCompilerInvocation);
os << R"<<<(
</div>
<div id='tooltiphint' hidden="true">
diff --git a/clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp b/clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
index c11fcc90efe1..676d621e4978 100644
--- a/clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
+++ b/clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
@@ -20,6 +20,7 @@
#include "clang/Lex/Preprocessor.h"
#include "clang/Lex/TokenConcatenation.h"
#include "clang/Rewrite/Core/HTMLRewrite.h"
+#include "clang/StaticAnalyzer/Core/AnalyzerOptions.h"
#include "clang/StaticAnalyzer/Core/IssueHash.h"
#include "clang/StaticAnalyzer/Core/PathDiagnosticConsumers.h"
#include "llvm/ADT/SmallPtrSet.h"
@@ -39,17 +40,13 @@ using namespace markup;
namespace {
class PlistDiagnostics : public PathDiagnosticConsumer {
- PathDiagnosticConsumerOptions DiagOpts;
const std::string OutputFile;
const Preprocessor &PP;
const cross_tu::CrossTranslationUnitContext &CTU;
+ AnalyzerOptions &AnOpts;
const bool SupportsCrossFileDiagnostics;
-
- void printBugPath(llvm::raw_ostream &o, const FIDMap &FM,
- const PathPieces &Path);
-
public:
- PlistDiagnostics(PathDiagnosticConsumerOptions DiagOpts,
+ PlistDiagnostics(AnalyzerOptions &AnalyzerOpts,
const std::string &OutputFile, const Preprocessor &PP,
const cross_tu::CrossTranslationUnitContext &CTU,
bool supportsMultipleFiles);
@@ -78,19 +75,23 @@ namespace {
/// A helper class for emitting a single report.
class PlistPrinter {
const FIDMap& FM;
+ AnalyzerOptions &AnOpts;
const Preprocessor &PP;
const cross_tu::CrossTranslationUnitContext &CTU;
llvm::SmallVector<const PathDiagnosticMacroPiece *, 0> MacroPieces;
public:
- PlistPrinter(const FIDMap& FM,
+ PlistPrinter(const FIDMap& FM, AnalyzerOptions &AnOpts,
const Preprocessor &PP,
const cross_tu::CrossTranslationUnitContext &CTU)
- : FM(FM), PP(PP), CTU(CTU) {
+ : FM(FM), AnOpts(AnOpts), PP(PP), CTU(CTU) {
}
void ReportDiag(raw_ostream &o, const PathDiagnosticPiece& P) {
ReportPiece(o, P, /*indent*/ 4, /*depth*/ 0, /*includeControlFlow*/ true);
+
+ // Don't emit a warning about an unused private field.
+ (void)AnOpts;
}
/// Print the expansions of the collected macro pieces.
@@ -165,6 +166,11 @@ struct ExpansionInfo {
} // end of anonymous namespace
+static void printBugPath(llvm::raw_ostream &o, const FIDMap& FM,
+ AnalyzerOptions &AnOpts, const Preprocessor &PP,
+ const cross_tu::CrossTranslationUnitContext &CTU,
+ const PathPieces &Path);
+
/// Print coverage information to output stream {@code o}.
/// May modify the used list of files {@code Fids} by inserting new ones.
static void printCoverage(const PathDiagnostic *D,
@@ -515,53 +521,11 @@ static void printCoverage(const PathDiagnostic *D,
assert(IndentLevel == InputIndentLevel);
}
-//===----------------------------------------------------------------------===//
-// Methods of PlistDiagnostics.
-//===----------------------------------------------------------------------===//
-
-PlistDiagnostics::PlistDiagnostics(
- PathDiagnosticConsumerOptions DiagOpts, const std::string &output,
- const Preprocessor &PP, const cross_tu::CrossTranslationUnitContext &CTU,
- bool supportsMultipleFiles)
- : DiagOpts(std::move(DiagOpts)), OutputFile(output), PP(PP), CTU(CTU),
- SupportsCrossFileDiagnostics(supportsMultipleFiles) {
- // FIXME: Will be used by a later planned change.
- (void)this->CTU;
-}
-
-void ento::createPlistDiagnosticConsumer(
- PathDiagnosticConsumerOptions DiagOpts, PathDiagnosticConsumers &C,
- const std::string &OutputFile, const Preprocessor &PP,
- const cross_tu::CrossTranslationUnitContext &CTU) {
-
- // TODO: Emit an error here.
- if (OutputFile.empty())
- return;
-
- C.push_back(new PlistDiagnostics(DiagOpts, OutputFile, PP, CTU,
- /*supportsMultipleFiles=*/false));
- createTextMinimalPathDiagnosticConsumer(std::move(DiagOpts), C, OutputFile,
- PP, CTU);
-}
-
-void ento::createPlistMultiFileDiagnosticConsumer(
- PathDiagnosticConsumerOptions DiagOpts, PathDiagnosticConsumers &C,
- const std::string &OutputFile, const Preprocessor &PP,
- const cross_tu::CrossTranslationUnitContext &CTU) {
-
- // TODO: Emit an error here.
- if (OutputFile.empty())
- return;
-
- C.push_back(new PlistDiagnostics(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) {
- PlistPrinter Printer(FM, PP, CTU);
+static void printBugPath(llvm::raw_ostream &o, const FIDMap& FM,
+ AnalyzerOptions &AnOpts, const Preprocessor &PP,
+ const cross_tu::CrossTranslationUnitContext &CTU,
+ const PathPieces &Path) {
+ PlistPrinter Printer(FM, AnOpts, PP, CTU);
assert(std::is_partitioned(Path.begin(), Path.end(),
[](const PathDiagnosticPieceRef &E) {
return E->getKind() == PathDiagnosticPiece::Note;
@@ -594,7 +558,7 @@ void PlistDiagnostics::printBugPath(llvm::raw_ostream &o, const FIDMap &FM,
o << " </array>\n";
- if (!DiagOpts.ShouldDisplayMacroExpansions)
+ if (!AnOpts.ShouldDisplayMacroExpansions)
return;
o << " <key>macro_expansions</key>\n"
@@ -603,6 +567,48 @@ void PlistDiagnostics::printBugPath(llvm::raw_ostream &o, const FIDMap &FM,
o << " </array>\n";
}
+//===----------------------------------------------------------------------===//
+// Methods of PlistDiagnostics.
+//===----------------------------------------------------------------------===//
+
+PlistDiagnostics::PlistDiagnostics(
+ AnalyzerOptions &AnalyzerOpts, const std::string &output,
+ const Preprocessor &PP, const cross_tu::CrossTranslationUnitContext &CTU,
+ bool supportsMultipleFiles)
+ : OutputFile(output), PP(PP), CTU(CTU), AnOpts(AnalyzerOpts),
+ SupportsCrossFileDiagnostics(supportsMultipleFiles) {
+ // FIXME: Will be used by a later planned change.
+ (void)this->CTU;
+}
+
+void ento::createPlistDiagnosticConsumer(
+ AnalyzerOptions &AnalyzerOpts, PathDiagnosticConsumers &C,
+ const std::string &OutputFile, const Preprocessor &PP,
+ const cross_tu::CrossTranslationUnitContext &CTU) {
+
+ // TODO: Emit an error here.
+ if (OutputFile.empty())
+ return;
+
+ C.push_back(new PlistDiagnostics(AnalyzerOpts, OutputFile, PP, CTU,
+ /*supportsMultipleFiles*/ false));
+ createTextMinimalPathDiagnosticConsumer(AnalyzerOpts, C, OutputFile, PP, CTU);
+}
+
+void ento::createPlistMultiFileDiagnosticConsumer(
+ AnalyzerOptions &AnalyzerOpts, PathDiagnosticConsumers &C,
+ const std::string &OutputFile, const Preprocessor &PP,
+ const cross_tu::CrossTranslationUnitContext &CTU) {
+
+ // TODO: Emit an error here.
+ if (OutputFile.empty())
+ return;
+
+ C.push_back(new PlistDiagnostics(AnalyzerOpts, OutputFile, PP, CTU,
+ /*supportsMultipleFiles*/ true));
+ createTextMinimalPathDiagnosticConsumer(AnalyzerOpts, C, OutputFile, PP, CTU);
+}
+
void PlistDiagnostics::FlushDiagnosticsImpl(
std::vector<const PathDiagnostic *> &Diags,
FilesMade *filesMade) {
@@ -677,7 +683,7 @@ void PlistDiagnostics::FlushDiagnosticsImpl(
o << " <dict>\n";
const PathDiagnostic *D = *DI;
- printBugPath(o, FM, D->path);
+ printBugPath(o, FM, AnOpts, PP, CTU, D->path);
// Output the bug type and bug category.
o << " <key>description</key>";
@@ -801,7 +807,7 @@ void PlistDiagnostics::FlushDiagnosticsImpl(
EmitString(o << " ", SM.getFileEntryForID(FID)->getName()) << '\n';
o << " </array>\n";
- if (llvm::AreStatisticsEnabled() && DiagOpts.ShouldSerializeStats) {
+ if (llvm::AreStatisticsEnabled() && AnOpts.ShouldSerializeStats) {
o << " <key>statistics</key>\n";
std::string stats;
llvm::raw_string_ostream os(stats);
diff --git a/clang/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp b/clang/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp
index 9abc5dedeb7a..8c2e85601576 100644
--- a/clang/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp
+++ b/clang/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp
@@ -14,6 +14,7 @@
#include "clang/Basic/FileManager.h"
#include "clang/Basic/Version.h"
#include "clang/Lex/Preprocessor.h"
+#include "clang/StaticAnalyzer/Core/AnalyzerOptions.h"
#include "clang/StaticAnalyzer/Core/PathDiagnosticConsumers.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/StringMap.h"
@@ -31,7 +32,8 @@ class SarifDiagnostics : public PathDiagnosticConsumer {
const LangOptions &LO;
public:
- SarifDiagnostics(const std::string &Output, const LangOptions &LO)
+ SarifDiagnostics(AnalyzerOptions &, const std::string &Output,
+ const LangOptions &LO)
: OutputFile(Output), LO(LO) {}
~SarifDiagnostics() override = default;
@@ -46,7 +48,7 @@ class SarifDiagnostics : public PathDiagnosticConsumer {
} // end anonymous namespace
void ento::createSarifDiagnosticConsumer(
- PathDiagnosticConsumerOptions DiagOpts, PathDiagnosticConsumers &C,
+ AnalyzerOptions &AnalyzerOpts, PathDiagnosticConsumers &C,
const std::string &Output, const Preprocessor &PP,
const cross_tu::CrossTranslationUnitContext &CTU) {
@@ -54,9 +56,8 @@ void ento::createSarifDiagnosticConsumer(
if (Output.empty())
return;
- C.push_back(new SarifDiagnostics(Output, PP.getLangOpts()));
- createTextMinimalPathDiagnosticConsumer(std::move(DiagOpts), C, Output, PP,
- CTU);
+ C.push_back(new SarifDiagnostics(AnalyzerOpts, Output, PP.getLangOpts()));
+ createTextMinimalPathDiagnosticConsumer(AnalyzerOpts, C, Output, PP, CTU);
}
static StringRef getFileName(const FileEntry &FE) {
diff --git a/clang/lib/StaticAnalyzer/Core/TextDiagnostics.cpp b/clang/lib/StaticAnalyzer/Core/TextDiagnostics.cpp
index ae2bad7ee77c..f4c7e5978e19 100644
--- a/clang/lib/StaticAnalyzer/Core/TextDiagnostics.cpp
+++ b/clang/lib/StaticAnalyzer/Core/TextDiagnostics.cpp
@@ -34,17 +34,20 @@ namespace {
/// 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 {
- PathDiagnosticConsumerOptions DiagOpts;
DiagnosticsEngine &DiagEng;
const LangOptions &LO;
- bool ShouldDisplayPathNotes;
+ const bool IncludePath = false;
+ const bool ShouldEmitAsError = false;
+ const bool ApplyFixIts = false;
+ const bool ShouldDisplayCheckerName = false;
public:
- TextDiagnostics(PathDiagnosticConsumerOptions DiagOpts,
- DiagnosticsEngine &DiagEng, const LangOptions &LO,
- bool ShouldDisplayPathNotes)
- : DiagOpts(std::move(DiagOpts)), DiagEng(DiagEng), LO(LO),
- ShouldDisplayPathNotes(ShouldDisplayPathNotes) {}
+ TextDiagnostics(DiagnosticsEngine &DiagEng, const LangOptions &LO,
+ bool ShouldIncludePath, const AnalyzerOptions &AnOpts)
+ : DiagEng(DiagEng), LO(LO), IncludePath(ShouldIncludePath),
+ ShouldEmitAsError(AnOpts.AnalyzerWerror),
+ ApplyFixIts(AnOpts.ShouldApplyFixIts),
+ ShouldDisplayCheckerName(AnOpts.ShouldDisplayCheckerNameForText) {}
~TextDiagnostics() override {}
StringRef getName() const override { return "TextDiagnostics"; }
@@ -53,13 +56,13 @@ class TextDiagnostics : public PathDiagnosticConsumer {
bool supportsCrossFileDiagnostics() const override { return true; }
PathGenerationScheme getGenerationScheme() const override {
- return ShouldDisplayPathNotes ? Minimal : None;
+ return IncludePath ? Minimal : None;
}
void FlushDiagnosticsImpl(std::vector<const PathDiagnostic *> &Diags,
FilesMade *filesMade) override {
unsigned WarnID =
- DiagOpts.ShouldDisplayWarningsAsErrors
+ ShouldEmitAsError
? DiagEng.getCustomDiagID(DiagnosticsEngine::Error, "%0")
: DiagEng.getCustomDiagID(DiagnosticsEngine::Warning, "%0");
unsigned NoteID = DiagEng.getCustomDiagID(DiagnosticsEngine::Note, "%0");
@@ -69,7 +72,7 @@ class TextDiagnostics : public PathDiagnosticConsumer {
auto reportPiece = [&](unsigned ID, FullSourceLoc Loc, StringRef String,
ArrayRef<SourceRange> Ranges,
ArrayRef<FixItHint> Fixits) {
- if (!DiagOpts.ShouldApplyFixIts) {
+ if (!ApplyFixIts) {
DiagEng.Report(Loc, ID) << String << Ranges << Fixits;
return;
}
@@ -89,10 +92,9 @@ class TextDiagnostics : public PathDiagnosticConsumer {
E = Diags.end();
I != E; ++I) {
const PathDiagnostic *PD = *I;
- std::string WarningMsg = (DiagOpts.ShouldDisplayDiagnosticName
- ? " [" + PD->getCheckerName() + "]"
- : "")
- .str();
+ std::string WarningMsg =
+ (ShouldDisplayCheckerName ? " [" + PD->getCheckerName() + "]" : "")
+ .str();
reportPiece(WarnID, PD->getLocation().asLocation(),
(PD->getShortDescription() + WarningMsg).str(),
@@ -108,7 +110,7 @@ class TextDiagnostics : public PathDiagnosticConsumer {
Piece->getFixits());
}
- if (!ShouldDisplayPathNotes)
+ if (!IncludePath)
continue;
// Then, add the path notes if necessary.
@@ -123,7 +125,7 @@ class TextDiagnostics : public PathDiagnosticConsumer {
}
}
- if (Repls.empty())
+ if (!ApplyFixIts || Repls.empty())
return;
Rewriter Rewrite(SM, LO);
@@ -137,19 +139,18 @@ class TextDiagnostics : public PathDiagnosticConsumer {
} // end anonymous namespace
void ento::createTextPathDiagnosticConsumer(
- PathDiagnosticConsumerOptions DiagOpts, PathDiagnosticConsumers &C,
+ AnalyzerOptions &AnalyzerOpts, 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));
+ C.emplace_back(new TextDiagnostics(PP.getDiagnostics(), PP.getLangOpts(),
+ /*ShouldIncludePath*/ true, AnalyzerOpts));
}
void ento::createTextMinimalPathDiagnosticConsumer(
- PathDiagnosticConsumerOptions DiagOpts, PathDiagnosticConsumers &C,
+ AnalyzerOptions &AnalyzerOpts, 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));
+ C.emplace_back(new TextDiagnostics(PP.getDiagnostics(), PP.getLangOpts(),
+ /*ShouldIncludePath*/ false,
+ AnalyzerOpts));
}
diff --git a/clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp b/clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
index f41f8343086f..392049e21c6e 100644
--- a/clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
+++ b/clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
@@ -150,7 +150,7 @@ class AnalysisConsumer : public AnalysisASTConsumer,
break;
#define ANALYSIS_DIAGNOSTICS(NAME, CMDFLAG, DESC, CREATEFN) \
case PD_##NAME: \
- CREATEFN(Opts->getDiagOpts(), PathConsumers, OutDir, PP, CTU); \
+ CREATEFN(*Opts.get(), PathConsumers, OutDir, PP, CTU); \
break;
#include "clang/StaticAnalyzer/Core/Analyses.def"
default:
More information about the cfe-commits
mailing list