2021-01-08 21:17:18 +08:00
|
|
|
//===--- TextDiagnostics.cpp - Text Diagnostics for Paths -------*- C++ -*-===//
|
[analyzer][NFC] Move the text output type to its own file, move code to PathDiagnosticConsumer creator functions
TableGen and .def files (which are meant to be used with the preprocessor) come
with obvious downsides. One of those issues is that generated switch-case
branches have to be identical. This pushes corner cases either to an outer code
block, or into the generated code.
Inspect the removed code in AnalysisConsumer::DigestAnalyzerOptions. You can see
how corner cases like a not existing output file, the analysis output type being
set to PD_NONE, or whether to complement the output with additional diagnostics
on stderr lay around the preprocessor generated code. This is a bit problematic,
as to how to deal with such errors is not in the hands of the users of this
interface (those implementing output types, like PlistDiagnostics etc).
This patch changes this by moving these corner cases into the generated code,
more specifically, into the called functions. In addition, I introduced a new
output type for convenience purposes, PD_TEXT_MINIMAL, which always existed
conceptually, but never in the actual Analyses.def file. This refactoring
allowed me to move TextDiagnostics (renamed from ClangDiagPathDiagConsumer) to
its own file, which it really deserved.
Also, those that had the misfortune to gaze upon Analyses.def will probably
enjoy the sight that a clang-format did on it.
Differential Revision: https://reviews.llvm.org/D76509
2020-03-19 21:53:09 +08:00
|
|
|
//
|
|
|
|
// 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
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2021-01-08 21:17:18 +08:00
|
|
|
// This file defines the TextDiagnostics object.
|
[analyzer][NFC] Move the text output type to its own file, move code to PathDiagnosticConsumer creator functions
TableGen and .def files (which are meant to be used with the preprocessor) come
with obvious downsides. One of those issues is that generated switch-case
branches have to be identical. This pushes corner cases either to an outer code
block, or into the generated code.
Inspect the removed code in AnalysisConsumer::DigestAnalyzerOptions. You can see
how corner cases like a not existing output file, the analysis output type being
set to PD_NONE, or whether to complement the output with additional diagnostics
on stderr lay around the preprocessor generated code. This is a bit problematic,
as to how to deal with such errors is not in the hands of the users of this
interface (those implementing output types, like PlistDiagnostics etc).
This patch changes this by moving these corner cases into the generated code,
more specifically, into the called functions. In addition, I introduced a new
output type for convenience purposes, PD_TEXT_MINIMAL, which always existed
conceptually, but never in the actual Analyses.def file. This refactoring
allowed me to move TextDiagnostics (renamed from ClangDiagPathDiagConsumer) to
its own file, which it really deserved.
Also, those that had the misfortune to gaze upon Analyses.def will probably
enjoy the sight that a clang-format did on it.
Differential Revision: https://reviews.llvm.org/D76509
2020-03-19 21:53:09 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2021-02-22 18:12:14 +08:00
|
|
|
#include "clang/Analysis/MacroExpansionContext.h"
|
[analyzer][NFC] Move the text output type to its own file, move code to PathDiagnosticConsumer creator functions
TableGen and .def files (which are meant to be used with the preprocessor) come
with obvious downsides. One of those issues is that generated switch-case
branches have to be identical. This pushes corner cases either to an outer code
block, or into the generated code.
Inspect the removed code in AnalysisConsumer::DigestAnalyzerOptions. You can see
how corner cases like a not existing output file, the analysis output type being
set to PD_NONE, or whether to complement the output with additional diagnostics
on stderr lay around the preprocessor generated code. This is a bit problematic,
as to how to deal with such errors is not in the hands of the users of this
interface (those implementing output types, like PlistDiagnostics etc).
This patch changes this by moving these corner cases into the generated code,
more specifically, into the called functions. In addition, I introduced a new
output type for convenience purposes, PD_TEXT_MINIMAL, which always existed
conceptually, but never in the actual Analyses.def file. This refactoring
allowed me to move TextDiagnostics (renamed from ClangDiagPathDiagConsumer) to
its own file, which it really deserved.
Also, those that had the misfortune to gaze upon Analyses.def will probably
enjoy the sight that a clang-format did on it.
Differential Revision: https://reviews.llvm.org/D76509
2020-03-19 21:53:09 +08:00
|
|
|
#include "clang/Analysis/PathDiagnostic.h"
|
|
|
|
#include "clang/Basic/SourceManager.h"
|
|
|
|
#include "clang/Basic/Version.h"
|
2021-01-08 21:17:18 +08:00
|
|
|
#include "clang/CrossTU/CrossTranslationUnit.h"
|
[analyzer][NFC] Move the text output type to its own file, move code to PathDiagnosticConsumer creator functions
TableGen and .def files (which are meant to be used with the preprocessor) come
with obvious downsides. One of those issues is that generated switch-case
branches have to be identical. This pushes corner cases either to an outer code
block, or into the generated code.
Inspect the removed code in AnalysisConsumer::DigestAnalyzerOptions. You can see
how corner cases like a not existing output file, the analysis output type being
set to PD_NONE, or whether to complement the output with additional diagnostics
on stderr lay around the preprocessor generated code. This is a bit problematic,
as to how to deal with such errors is not in the hands of the users of this
interface (those implementing output types, like PlistDiagnostics etc).
This patch changes this by moving these corner cases into the generated code,
more specifically, into the called functions. In addition, I introduced a new
output type for convenience purposes, PD_TEXT_MINIMAL, which always existed
conceptually, but never in the actual Analyses.def file. This refactoring
allowed me to move TextDiagnostics (renamed from ClangDiagPathDiagConsumer) to
its own file, which it really deserved.
Also, those that had the misfortune to gaze upon Analyses.def will probably
enjoy the sight that a clang-format did on it.
Differential Revision: https://reviews.llvm.org/D76509
2020-03-19 21:53:09 +08:00
|
|
|
#include "clang/Frontend/ASTUnit.h"
|
|
|
|
#include "clang/Lex/Preprocessor.h"
|
|
|
|
#include "clang/Rewrite/Core/Rewriter.h"
|
2021-01-08 21:17:18 +08:00
|
|
|
#include "clang/StaticAnalyzer/Core/AnalyzerOptions.h"
|
|
|
|
#include "clang/StaticAnalyzer/Core/PathDiagnosticConsumers.h"
|
[analyzer][NFC] Move the text output type to its own file, move code to PathDiagnosticConsumer creator functions
TableGen and .def files (which are meant to be used with the preprocessor) come
with obvious downsides. One of those issues is that generated switch-case
branches have to be identical. This pushes corner cases either to an outer code
block, or into the generated code.
Inspect the removed code in AnalysisConsumer::DigestAnalyzerOptions. You can see
how corner cases like a not existing output file, the analysis output type being
set to PD_NONE, or whether to complement the output with additional diagnostics
on stderr lay around the preprocessor generated code. This is a bit problematic,
as to how to deal with such errors is not in the hands of the users of this
interface (those implementing output types, like PlistDiagnostics etc).
This patch changes this by moving these corner cases into the generated code,
more specifically, into the called functions. In addition, I introduced a new
output type for convenience purposes, PD_TEXT_MINIMAL, which always existed
conceptually, but never in the actual Analyses.def file. This refactoring
allowed me to move TextDiagnostics (renamed from ClangDiagPathDiagConsumer) to
its own file, which it really deserved.
Also, those that had the misfortune to gaze upon Analyses.def will probably
enjoy the sight that a clang-format did on it.
Differential Revision: https://reviews.llvm.org/D76509
2020-03-19 21:53:09 +08:00
|
|
|
#include "clang/Tooling/Core/Replacement.h"
|
|
|
|
#include "clang/Tooling/Tooling.h"
|
|
|
|
#include "llvm/ADT/SmallPtrSet.h"
|
|
|
|
#include "llvm/ADT/SmallVector.h"
|
|
|
|
#include "llvm/Support/Casting.h"
|
|
|
|
|
|
|
|
using namespace clang;
|
|
|
|
using namespace ento;
|
|
|
|
using namespace tooling;
|
|
|
|
|
|
|
|
namespace {
|
2021-01-08 21:17:18 +08:00
|
|
|
/// Emitsd minimal diagnostics (report message + notes) for the 'none' output
|
[analyzer][NFC] Move the text output type to its own file, move code to PathDiagnosticConsumer creator functions
TableGen and .def files (which are meant to be used with the preprocessor) come
with obvious downsides. One of those issues is that generated switch-case
branches have to be identical. This pushes corner cases either to an outer code
block, or into the generated code.
Inspect the removed code in AnalysisConsumer::DigestAnalyzerOptions. You can see
how corner cases like a not existing output file, the analysis output type being
set to PD_NONE, or whether to complement the output with additional diagnostics
on stderr lay around the preprocessor generated code. This is a bit problematic,
as to how to deal with such errors is not in the hands of the users of this
interface (those implementing output types, like PlistDiagnostics etc).
This patch changes this by moving these corner cases into the generated code,
more specifically, into the called functions. In addition, I introduced a new
output type for convenience purposes, PD_TEXT_MINIMAL, which always existed
conceptually, but never in the actual Analyses.def file. This refactoring
allowed me to move TextDiagnostics (renamed from ClangDiagPathDiagConsumer) to
its own file, which it really deserved.
Also, those that had the misfortune to gaze upon Analyses.def will probably
enjoy the sight that a clang-format did on it.
Differential Revision: https://reviews.llvm.org/D76509
2020-03-19 21:53:09 +08:00
|
|
|
/// type to the standard error, or to to compliment many others. Emits detailed
|
|
|
|
/// diagnostics in textual format for the 'text' output type.
|
2021-01-08 21:17:18 +08:00
|
|
|
class TextDiagnostics : public PathDiagnosticConsumer {
|
2020-11-11 06:03:57 +08:00
|
|
|
PathDiagnosticConsumerOptions DiagOpts;
|
[analyzer][NFC] Move the text output type to its own file, move code to PathDiagnosticConsumer creator functions
TableGen and .def files (which are meant to be used with the preprocessor) come
with obvious downsides. One of those issues is that generated switch-case
branches have to be identical. This pushes corner cases either to an outer code
block, or into the generated code.
Inspect the removed code in AnalysisConsumer::DigestAnalyzerOptions. You can see
how corner cases like a not existing output file, the analysis output type being
set to PD_NONE, or whether to complement the output with additional diagnostics
on stderr lay around the preprocessor generated code. This is a bit problematic,
as to how to deal with such errors is not in the hands of the users of this
interface (those implementing output types, like PlistDiagnostics etc).
This patch changes this by moving these corner cases into the generated code,
more specifically, into the called functions. In addition, I introduced a new
output type for convenience purposes, PD_TEXT_MINIMAL, which always existed
conceptually, but never in the actual Analyses.def file. This refactoring
allowed me to move TextDiagnostics (renamed from ClangDiagPathDiagConsumer) to
its own file, which it really deserved.
Also, those that had the misfortune to gaze upon Analyses.def will probably
enjoy the sight that a clang-format did on it.
Differential Revision: https://reviews.llvm.org/D76509
2020-03-19 21:53:09 +08:00
|
|
|
DiagnosticsEngine &DiagEng;
|
2020-03-20 23:45:53 +08:00
|
|
|
const LangOptions &LO;
|
2020-11-11 06:03:57 +08:00
|
|
|
bool ShouldDisplayPathNotes;
|
[analyzer][NFC] Move the text output type to its own file, move code to PathDiagnosticConsumer creator functions
TableGen and .def files (which are meant to be used with the preprocessor) come
with obvious downsides. One of those issues is that generated switch-case
branches have to be identical. This pushes corner cases either to an outer code
block, or into the generated code.
Inspect the removed code in AnalysisConsumer::DigestAnalyzerOptions. You can see
how corner cases like a not existing output file, the analysis output type being
set to PD_NONE, or whether to complement the output with additional diagnostics
on stderr lay around the preprocessor generated code. This is a bit problematic,
as to how to deal with such errors is not in the hands of the users of this
interface (those implementing output types, like PlistDiagnostics etc).
This patch changes this by moving these corner cases into the generated code,
more specifically, into the called functions. In addition, I introduced a new
output type for convenience purposes, PD_TEXT_MINIMAL, which always existed
conceptually, but never in the actual Analyses.def file. This refactoring
allowed me to move TextDiagnostics (renamed from ClangDiagPathDiagConsumer) to
its own file, which it really deserved.
Also, those that had the misfortune to gaze upon Analyses.def will probably
enjoy the sight that a clang-format did on it.
Differential Revision: https://reviews.llvm.org/D76509
2020-03-19 21:53:09 +08:00
|
|
|
|
|
|
|
public:
|
2021-01-08 21:17:18 +08:00
|
|
|
TextDiagnostics(PathDiagnosticConsumerOptions DiagOpts,
|
|
|
|
DiagnosticsEngine &DiagEng, const LangOptions &LO,
|
|
|
|
bool ShouldDisplayPathNotes)
|
2020-11-11 06:03:57 +08:00
|
|
|
: DiagOpts(std::move(DiagOpts)), DiagEng(DiagEng), LO(LO),
|
|
|
|
ShouldDisplayPathNotes(ShouldDisplayPathNotes) {}
|
2021-01-08 21:17:18 +08:00
|
|
|
~TextDiagnostics() override {}
|
[analyzer][NFC] Move the text output type to its own file, move code to PathDiagnosticConsumer creator functions
TableGen and .def files (which are meant to be used with the preprocessor) come
with obvious downsides. One of those issues is that generated switch-case
branches have to be identical. This pushes corner cases either to an outer code
block, or into the generated code.
Inspect the removed code in AnalysisConsumer::DigestAnalyzerOptions. You can see
how corner cases like a not existing output file, the analysis output type being
set to PD_NONE, or whether to complement the output with additional diagnostics
on stderr lay around the preprocessor generated code. This is a bit problematic,
as to how to deal with such errors is not in the hands of the users of this
interface (those implementing output types, like PlistDiagnostics etc).
This patch changes this by moving these corner cases into the generated code,
more specifically, into the called functions. In addition, I introduced a new
output type for convenience purposes, PD_TEXT_MINIMAL, which always existed
conceptually, but never in the actual Analyses.def file. This refactoring
allowed me to move TextDiagnostics (renamed from ClangDiagPathDiagConsumer) to
its own file, which it really deserved.
Also, those that had the misfortune to gaze upon Analyses.def will probably
enjoy the sight that a clang-format did on it.
Differential Revision: https://reviews.llvm.org/D76509
2020-03-19 21:53:09 +08:00
|
|
|
|
2021-01-08 21:17:18 +08:00
|
|
|
StringRef getName() const override { return "TextDiagnostics"; }
|
[analyzer][NFC] Move the text output type to its own file, move code to PathDiagnosticConsumer creator functions
TableGen and .def files (which are meant to be used with the preprocessor) come
with obvious downsides. One of those issues is that generated switch-case
branches have to be identical. This pushes corner cases either to an outer code
block, or into the generated code.
Inspect the removed code in AnalysisConsumer::DigestAnalyzerOptions. You can see
how corner cases like a not existing output file, the analysis output type being
set to PD_NONE, or whether to complement the output with additional diagnostics
on stderr lay around the preprocessor generated code. This is a bit problematic,
as to how to deal with such errors is not in the hands of the users of this
interface (those implementing output types, like PlistDiagnostics etc).
This patch changes this by moving these corner cases into the generated code,
more specifically, into the called functions. In addition, I introduced a new
output type for convenience purposes, PD_TEXT_MINIMAL, which always existed
conceptually, but never in the actual Analyses.def file. This refactoring
allowed me to move TextDiagnostics (renamed from ClangDiagPathDiagConsumer) to
its own file, which it really deserved.
Also, those that had the misfortune to gaze upon Analyses.def will probably
enjoy the sight that a clang-format did on it.
Differential Revision: https://reviews.llvm.org/D76509
2020-03-19 21:53:09 +08:00
|
|
|
|
|
|
|
bool supportsLogicalOpControlFlow() const override { return true; }
|
|
|
|
bool supportsCrossFileDiagnostics() const override { return true; }
|
|
|
|
|
|
|
|
PathGenerationScheme getGenerationScheme() const override {
|
2020-11-11 06:03:57 +08:00
|
|
|
return ShouldDisplayPathNotes ? Minimal : None;
|
[analyzer][NFC] Move the text output type to its own file, move code to PathDiagnosticConsumer creator functions
TableGen and .def files (which are meant to be used with the preprocessor) come
with obvious downsides. One of those issues is that generated switch-case
branches have to be identical. This pushes corner cases either to an outer code
block, or into the generated code.
Inspect the removed code in AnalysisConsumer::DigestAnalyzerOptions. You can see
how corner cases like a not existing output file, the analysis output type being
set to PD_NONE, or whether to complement the output with additional diagnostics
on stderr lay around the preprocessor generated code. This is a bit problematic,
as to how to deal with such errors is not in the hands of the users of this
interface (those implementing output types, like PlistDiagnostics etc).
This patch changes this by moving these corner cases into the generated code,
more specifically, into the called functions. In addition, I introduced a new
output type for convenience purposes, PD_TEXT_MINIMAL, which always existed
conceptually, but never in the actual Analyses.def file. This refactoring
allowed me to move TextDiagnostics (renamed from ClangDiagPathDiagConsumer) to
its own file, which it really deserved.
Also, those that had the misfortune to gaze upon Analyses.def will probably
enjoy the sight that a clang-format did on it.
Differential Revision: https://reviews.llvm.org/D76509
2020-03-19 21:53:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void FlushDiagnosticsImpl(std::vector<const PathDiagnostic *> &Diags,
|
|
|
|
FilesMade *filesMade) override {
|
|
|
|
unsigned WarnID =
|
2020-11-11 06:03:57 +08:00
|
|
|
DiagOpts.ShouldDisplayWarningsAsErrors
|
[analyzer][NFC] Move the text output type to its own file, move code to PathDiagnosticConsumer creator functions
TableGen and .def files (which are meant to be used with the preprocessor) come
with obvious downsides. One of those issues is that generated switch-case
branches have to be identical. This pushes corner cases either to an outer code
block, or into the generated code.
Inspect the removed code in AnalysisConsumer::DigestAnalyzerOptions. You can see
how corner cases like a not existing output file, the analysis output type being
set to PD_NONE, or whether to complement the output with additional diagnostics
on stderr lay around the preprocessor generated code. This is a bit problematic,
as to how to deal with such errors is not in the hands of the users of this
interface (those implementing output types, like PlistDiagnostics etc).
This patch changes this by moving these corner cases into the generated code,
more specifically, into the called functions. In addition, I introduced a new
output type for convenience purposes, PD_TEXT_MINIMAL, which always existed
conceptually, but never in the actual Analyses.def file. This refactoring
allowed me to move TextDiagnostics (renamed from ClangDiagPathDiagConsumer) to
its own file, which it really deserved.
Also, those that had the misfortune to gaze upon Analyses.def will probably
enjoy the sight that a clang-format did on it.
Differential Revision: https://reviews.llvm.org/D76509
2020-03-19 21:53:09 +08:00
|
|
|
? DiagEng.getCustomDiagID(DiagnosticsEngine::Error, "%0")
|
|
|
|
: DiagEng.getCustomDiagID(DiagnosticsEngine::Warning, "%0");
|
|
|
|
unsigned NoteID = DiagEng.getCustomDiagID(DiagnosticsEngine::Note, "%0");
|
|
|
|
SourceManager &SM = DiagEng.getSourceManager();
|
|
|
|
|
|
|
|
Replacements Repls;
|
|
|
|
auto reportPiece = [&](unsigned ID, FullSourceLoc Loc, StringRef String,
|
|
|
|
ArrayRef<SourceRange> Ranges,
|
|
|
|
ArrayRef<FixItHint> Fixits) {
|
2020-11-11 06:03:57 +08:00
|
|
|
if (!DiagOpts.ShouldApplyFixIts) {
|
[analyzer][NFC] Move the text output type to its own file, move code to PathDiagnosticConsumer creator functions
TableGen and .def files (which are meant to be used with the preprocessor) come
with obvious downsides. One of those issues is that generated switch-case
branches have to be identical. This pushes corner cases either to an outer code
block, or into the generated code.
Inspect the removed code in AnalysisConsumer::DigestAnalyzerOptions. You can see
how corner cases like a not existing output file, the analysis output type being
set to PD_NONE, or whether to complement the output with additional diagnostics
on stderr lay around the preprocessor generated code. This is a bit problematic,
as to how to deal with such errors is not in the hands of the users of this
interface (those implementing output types, like PlistDiagnostics etc).
This patch changes this by moving these corner cases into the generated code,
more specifically, into the called functions. In addition, I introduced a new
output type for convenience purposes, PD_TEXT_MINIMAL, which always existed
conceptually, but never in the actual Analyses.def file. This refactoring
allowed me to move TextDiagnostics (renamed from ClangDiagPathDiagConsumer) to
its own file, which it really deserved.
Also, those that had the misfortune to gaze upon Analyses.def will probably
enjoy the sight that a clang-format did on it.
Differential Revision: https://reviews.llvm.org/D76509
2020-03-19 21:53:09 +08:00
|
|
|
DiagEng.Report(Loc, ID) << String << Ranges << Fixits;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
DiagEng.Report(Loc, ID) << String << Ranges;
|
|
|
|
for (const FixItHint &Hint : Fixits) {
|
|
|
|
Replacement Repl(SM, Hint.RemoveRange, Hint.CodeToInsert);
|
|
|
|
|
|
|
|
if (llvm::Error Err = Repls.add(Repl)) {
|
|
|
|
llvm::errs() << "Error applying replacement " << Repl.toString()
|
|
|
|
<< ": " << Err << "\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
for (std::vector<const PathDiagnostic *>::iterator I = Diags.begin(),
|
|
|
|
E = Diags.end();
|
|
|
|
I != E; ++I) {
|
|
|
|
const PathDiagnostic *PD = *I;
|
2020-11-11 06:03:57 +08:00
|
|
|
std::string WarningMsg = (DiagOpts.ShouldDisplayDiagnosticName
|
|
|
|
? " [" + PD->getCheckerName() + "]"
|
|
|
|
: "")
|
|
|
|
.str();
|
2020-03-20 23:45:53 +08:00
|
|
|
|
[analyzer][NFC] Move the text output type to its own file, move code to PathDiagnosticConsumer creator functions
TableGen and .def files (which are meant to be used with the preprocessor) come
with obvious downsides. One of those issues is that generated switch-case
branches have to be identical. This pushes corner cases either to an outer code
block, or into the generated code.
Inspect the removed code in AnalysisConsumer::DigestAnalyzerOptions. You can see
how corner cases like a not existing output file, the analysis output type being
set to PD_NONE, or whether to complement the output with additional diagnostics
on stderr lay around the preprocessor generated code. This is a bit problematic,
as to how to deal with such errors is not in the hands of the users of this
interface (those implementing output types, like PlistDiagnostics etc).
This patch changes this by moving these corner cases into the generated code,
more specifically, into the called functions. In addition, I introduced a new
output type for convenience purposes, PD_TEXT_MINIMAL, which always existed
conceptually, but never in the actual Analyses.def file. This refactoring
allowed me to move TextDiagnostics (renamed from ClangDiagPathDiagConsumer) to
its own file, which it really deserved.
Also, those that had the misfortune to gaze upon Analyses.def will probably
enjoy the sight that a clang-format did on it.
Differential Revision: https://reviews.llvm.org/D76509
2020-03-19 21:53:09 +08:00
|
|
|
reportPiece(WarnID, PD->getLocation().asLocation(),
|
2020-03-20 23:45:53 +08:00
|
|
|
(PD->getShortDescription() + WarningMsg).str(),
|
|
|
|
PD->path.back()->getRanges(), PD->path.back()->getFixits());
|
[analyzer][NFC] Move the text output type to its own file, move code to PathDiagnosticConsumer creator functions
TableGen and .def files (which are meant to be used with the preprocessor) come
with obvious downsides. One of those issues is that generated switch-case
branches have to be identical. This pushes corner cases either to an outer code
block, or into the generated code.
Inspect the removed code in AnalysisConsumer::DigestAnalyzerOptions. You can see
how corner cases like a not existing output file, the analysis output type being
set to PD_NONE, or whether to complement the output with additional diagnostics
on stderr lay around the preprocessor generated code. This is a bit problematic,
as to how to deal with such errors is not in the hands of the users of this
interface (those implementing output types, like PlistDiagnostics etc).
This patch changes this by moving these corner cases into the generated code,
more specifically, into the called functions. In addition, I introduced a new
output type for convenience purposes, PD_TEXT_MINIMAL, which always existed
conceptually, but never in the actual Analyses.def file. This refactoring
allowed me to move TextDiagnostics (renamed from ClangDiagPathDiagConsumer) to
its own file, which it really deserved.
Also, those that had the misfortune to gaze upon Analyses.def will probably
enjoy the sight that a clang-format did on it.
Differential Revision: https://reviews.llvm.org/D76509
2020-03-19 21:53:09 +08:00
|
|
|
|
|
|
|
// First, add extra notes, even if paths should not be included.
|
|
|
|
for (const auto &Piece : PD->path) {
|
|
|
|
if (!isa<PathDiagnosticNotePiece>(Piece.get()))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
reportPiece(NoteID, Piece->getLocation().asLocation(),
|
2020-03-20 23:45:53 +08:00
|
|
|
Piece->getString(), Piece->getRanges(),
|
|
|
|
Piece->getFixits());
|
[analyzer][NFC] Move the text output type to its own file, move code to PathDiagnosticConsumer creator functions
TableGen and .def files (which are meant to be used with the preprocessor) come
with obvious downsides. One of those issues is that generated switch-case
branches have to be identical. This pushes corner cases either to an outer code
block, or into the generated code.
Inspect the removed code in AnalysisConsumer::DigestAnalyzerOptions. You can see
how corner cases like a not existing output file, the analysis output type being
set to PD_NONE, or whether to complement the output with additional diagnostics
on stderr lay around the preprocessor generated code. This is a bit problematic,
as to how to deal with such errors is not in the hands of the users of this
interface (those implementing output types, like PlistDiagnostics etc).
This patch changes this by moving these corner cases into the generated code,
more specifically, into the called functions. In addition, I introduced a new
output type for convenience purposes, PD_TEXT_MINIMAL, which always existed
conceptually, but never in the actual Analyses.def file. This refactoring
allowed me to move TextDiagnostics (renamed from ClangDiagPathDiagConsumer) to
its own file, which it really deserved.
Also, those that had the misfortune to gaze upon Analyses.def will probably
enjoy the sight that a clang-format did on it.
Differential Revision: https://reviews.llvm.org/D76509
2020-03-19 21:53:09 +08:00
|
|
|
}
|
|
|
|
|
2020-11-11 06:03:57 +08:00
|
|
|
if (!ShouldDisplayPathNotes)
|
[analyzer][NFC] Move the text output type to its own file, move code to PathDiagnosticConsumer creator functions
TableGen and .def files (which are meant to be used with the preprocessor) come
with obvious downsides. One of those issues is that generated switch-case
branches have to be identical. This pushes corner cases either to an outer code
block, or into the generated code.
Inspect the removed code in AnalysisConsumer::DigestAnalyzerOptions. You can see
how corner cases like a not existing output file, the analysis output type being
set to PD_NONE, or whether to complement the output with additional diagnostics
on stderr lay around the preprocessor generated code. This is a bit problematic,
as to how to deal with such errors is not in the hands of the users of this
interface (those implementing output types, like PlistDiagnostics etc).
This patch changes this by moving these corner cases into the generated code,
more specifically, into the called functions. In addition, I introduced a new
output type for convenience purposes, PD_TEXT_MINIMAL, which always existed
conceptually, but never in the actual Analyses.def file. This refactoring
allowed me to move TextDiagnostics (renamed from ClangDiagPathDiagConsumer) to
its own file, which it really deserved.
Also, those that had the misfortune to gaze upon Analyses.def will probably
enjoy the sight that a clang-format did on it.
Differential Revision: https://reviews.llvm.org/D76509
2020-03-19 21:53:09 +08:00
|
|
|
continue;
|
|
|
|
|
|
|
|
// Then, add the path notes if necessary.
|
|
|
|
PathPieces FlatPath = PD->path.flatten(/*ShouldFlattenMacros=*/true);
|
|
|
|
for (const auto &Piece : FlatPath) {
|
|
|
|
if (isa<PathDiagnosticNotePiece>(Piece.get()))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
reportPiece(NoteID, Piece->getLocation().asLocation(),
|
2020-03-20 23:45:53 +08:00
|
|
|
Piece->getString(), Piece->getRanges(),
|
|
|
|
Piece->getFixits());
|
[analyzer][NFC] Move the text output type to its own file, move code to PathDiagnosticConsumer creator functions
TableGen and .def files (which are meant to be used with the preprocessor) come
with obvious downsides. One of those issues is that generated switch-case
branches have to be identical. This pushes corner cases either to an outer code
block, or into the generated code.
Inspect the removed code in AnalysisConsumer::DigestAnalyzerOptions. You can see
how corner cases like a not existing output file, the analysis output type being
set to PD_NONE, or whether to complement the output with additional diagnostics
on stderr lay around the preprocessor generated code. This is a bit problematic,
as to how to deal with such errors is not in the hands of the users of this
interface (those implementing output types, like PlistDiagnostics etc).
This patch changes this by moving these corner cases into the generated code,
more specifically, into the called functions. In addition, I introduced a new
output type for convenience purposes, PD_TEXT_MINIMAL, which always existed
conceptually, but never in the actual Analyses.def file. This refactoring
allowed me to move TextDiagnostics (renamed from ClangDiagPathDiagConsumer) to
its own file, which it really deserved.
Also, those that had the misfortune to gaze upon Analyses.def will probably
enjoy the sight that a clang-format did on it.
Differential Revision: https://reviews.llvm.org/D76509
2020-03-19 21:53:09 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-11 06:03:57 +08:00
|
|
|
if (Repls.empty())
|
[analyzer][NFC] Move the text output type to its own file, move code to PathDiagnosticConsumer creator functions
TableGen and .def files (which are meant to be used with the preprocessor) come
with obvious downsides. One of those issues is that generated switch-case
branches have to be identical. This pushes corner cases either to an outer code
block, or into the generated code.
Inspect the removed code in AnalysisConsumer::DigestAnalyzerOptions. You can see
how corner cases like a not existing output file, the analysis output type being
set to PD_NONE, or whether to complement the output with additional diagnostics
on stderr lay around the preprocessor generated code. This is a bit problematic,
as to how to deal with such errors is not in the hands of the users of this
interface (those implementing output types, like PlistDiagnostics etc).
This patch changes this by moving these corner cases into the generated code,
more specifically, into the called functions. In addition, I introduced a new
output type for convenience purposes, PD_TEXT_MINIMAL, which always existed
conceptually, but never in the actual Analyses.def file. This refactoring
allowed me to move TextDiagnostics (renamed from ClangDiagPathDiagConsumer) to
its own file, which it really deserved.
Also, those that had the misfortune to gaze upon Analyses.def will probably
enjoy the sight that a clang-format did on it.
Differential Revision: https://reviews.llvm.org/D76509
2020-03-19 21:53:09 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
Rewriter Rewrite(SM, LO);
|
|
|
|
if (!applyAllReplacements(Repls, Rewrite)) {
|
2022-02-09 04:33:01 +08:00
|
|
|
llvm::errs() << "An error occurred during applying fix-it.\n";
|
[analyzer][NFC] Move the text output type to its own file, move code to PathDiagnosticConsumer creator functions
TableGen and .def files (which are meant to be used with the preprocessor) come
with obvious downsides. One of those issues is that generated switch-case
branches have to be identical. This pushes corner cases either to an outer code
block, or into the generated code.
Inspect the removed code in AnalysisConsumer::DigestAnalyzerOptions. You can see
how corner cases like a not existing output file, the analysis output type being
set to PD_NONE, or whether to complement the output with additional diagnostics
on stderr lay around the preprocessor generated code. This is a bit problematic,
as to how to deal with such errors is not in the hands of the users of this
interface (those implementing output types, like PlistDiagnostics etc).
This patch changes this by moving these corner cases into the generated code,
more specifically, into the called functions. In addition, I introduced a new
output type for convenience purposes, PD_TEXT_MINIMAL, which always existed
conceptually, but never in the actual Analyses.def file. This refactoring
allowed me to move TextDiagnostics (renamed from ClangDiagPathDiagConsumer) to
its own file, which it really deserved.
Also, those that had the misfortune to gaze upon Analyses.def will probably
enjoy the sight that a clang-format did on it.
Differential Revision: https://reviews.llvm.org/D76509
2020-03-19 21:53:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Rewrite.overwriteChangedFiles();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
} // end anonymous namespace
|
|
|
|
|
|
|
|
void ento::createTextPathDiagnosticConsumer(
|
2020-11-11 06:03:57 +08:00
|
|
|
PathDiagnosticConsumerOptions DiagOpts, PathDiagnosticConsumers &C,
|
2021-02-22 18:12:14 +08:00
|
|
|
const std::string &Prefix, const Preprocessor &PP,
|
|
|
|
const cross_tu::CrossTranslationUnitContext &CTU,
|
|
|
|
const MacroExpansionContext &MacroExpansions) {
|
2021-01-08 21:17:18 +08:00
|
|
|
C.emplace_back(new TextDiagnostics(std::move(DiagOpts), PP.getDiagnostics(),
|
|
|
|
PP.getLangOpts(),
|
|
|
|
/*ShouldDisplayPathNotes=*/true));
|
[analyzer][NFC] Move the text output type to its own file, move code to PathDiagnosticConsumer creator functions
TableGen and .def files (which are meant to be used with the preprocessor) come
with obvious downsides. One of those issues is that generated switch-case
branches have to be identical. This pushes corner cases either to an outer code
block, or into the generated code.
Inspect the removed code in AnalysisConsumer::DigestAnalyzerOptions. You can see
how corner cases like a not existing output file, the analysis output type being
set to PD_NONE, or whether to complement the output with additional diagnostics
on stderr lay around the preprocessor generated code. This is a bit problematic,
as to how to deal with such errors is not in the hands of the users of this
interface (those implementing output types, like PlistDiagnostics etc).
This patch changes this by moving these corner cases into the generated code,
more specifically, into the called functions. In addition, I introduced a new
output type for convenience purposes, PD_TEXT_MINIMAL, which always existed
conceptually, but never in the actual Analyses.def file. This refactoring
allowed me to move TextDiagnostics (renamed from ClangDiagPathDiagConsumer) to
its own file, which it really deserved.
Also, those that had the misfortune to gaze upon Analyses.def will probably
enjoy the sight that a clang-format did on it.
Differential Revision: https://reviews.llvm.org/D76509
2020-03-19 21:53:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ento::createTextMinimalPathDiagnosticConsumer(
|
2020-11-11 06:03:57 +08:00
|
|
|
PathDiagnosticConsumerOptions DiagOpts, PathDiagnosticConsumers &C,
|
2021-02-22 18:12:14 +08:00
|
|
|
const std::string &Prefix, const Preprocessor &PP,
|
|
|
|
const cross_tu::CrossTranslationUnitContext &CTU,
|
|
|
|
const MacroExpansionContext &MacroExpansions) {
|
2021-01-08 21:17:18 +08:00
|
|
|
C.emplace_back(new TextDiagnostics(std::move(DiagOpts), PP.getDiagnostics(),
|
|
|
|
PP.getLangOpts(),
|
|
|
|
/*ShouldDisplayPathNotes=*/false));
|
[analyzer][NFC] Move the text output type to its own file, move code to PathDiagnosticConsumer creator functions
TableGen and .def files (which are meant to be used with the preprocessor) come
with obvious downsides. One of those issues is that generated switch-case
branches have to be identical. This pushes corner cases either to an outer code
block, or into the generated code.
Inspect the removed code in AnalysisConsumer::DigestAnalyzerOptions. You can see
how corner cases like a not existing output file, the analysis output type being
set to PD_NONE, or whether to complement the output with additional diagnostics
on stderr lay around the preprocessor generated code. This is a bit problematic,
as to how to deal with such errors is not in the hands of the users of this
interface (those implementing output types, like PlistDiagnostics etc).
This patch changes this by moving these corner cases into the generated code,
more specifically, into the called functions. In addition, I introduced a new
output type for convenience purposes, PD_TEXT_MINIMAL, which always existed
conceptually, but never in the actual Analyses.def file. This refactoring
allowed me to move TextDiagnostics (renamed from ClangDiagPathDiagConsumer) to
its own file, which it really deserved.
Also, those that had the misfortune to gaze upon Analyses.def will probably
enjoy the sight that a clang-format did on it.
Differential Revision: https://reviews.llvm.org/D76509
2020-03-19 21:53:09 +08:00
|
|
|
}
|