njames93 updated this revision to Diff 423230.
njames93 added a comment.
Added clangd release notes.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D97121/new/
https://reviews.llvm.org/D97121
Files:
clang-tools-extra/clang-tidy/ClangTidyCheck.h
clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h
clang-tools-extra/clang-tidy/abseil/StringFindStartswithCheck.cpp
clang-tools-extra/clang-tidy/bugprone/ImplicitWideningOfMultiplicationResultCheck.cpp
clang-tools-extra/clang-tidy/cppcoreguidelines/InitVariablesCheck.cpp
clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.cpp
clang-tools-extra/clang-tidy/misc/UniqueptrResetReleaseCheck.cpp
clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp
clang-tools-extra/clang-tidy/modernize/PassByValueCheck.cpp
clang-tools-extra/clang-tidy/modernize/ReplaceAutoPtrCheck.cpp
clang-tools-extra/clang-tidy/modernize/ReplaceRandomShuffleCheck.cpp
clang-tools-extra/clang-tidy/performance/TypePromotionInMathFnCheck.cpp
clang-tools-extra/clang-tidy/performance/UnnecessaryValueParamCheck.cpp
clang-tools-extra/clang-tidy/utils/IncludeInserter.cpp
clang-tools-extra/clang-tidy/utils/IncludeInserter.h
clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.cpp
clang-tools-extra/clangd/ParsedAST.cpp
clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/unittests/clang-tidy/IncludeInserterTest.cpp
Index: clang-tools-extra/unittests/clang-tidy/IncludeInserterTest.cpp
===================================================================
--- clang-tools-extra/unittests/clang-tidy/IncludeInserterTest.cpp
+++ clang-tools-extra/unittests/clang-tidy/IncludeInserterTest.cpp
@@ -30,8 +30,10 @@
public:
IncludeInserterCheckBase(StringRef CheckName, ClangTidyContext *Context,
utils::IncludeSorter::IncludeStyle Style =
- utils::IncludeSorter::IS_Google)
- : ClangTidyCheck(CheckName, Context), Inserter(Style) {}
+ utils::IncludeSorter::IS_Google,
+ bool SelfContainedDiags = false)
+ : ClangTidyCheck(CheckName, Context),
+ Inserter(Style, SelfContainedDiags) {}
void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP,
Preprocessor *ModuleExpanderPP) override {
@@ -85,6 +87,19 @@
}
};
+class MultipleHeaderSingleInserterCheck : public IncludeInserterCheckBase {
+public:
+ MultipleHeaderSingleInserterCheck(StringRef CheckName,
+ ClangTidyContext *Context)
+ : IncludeInserterCheckBase(CheckName, Context,
+ utils::IncludeSorter::IS_Google,
+ /*SelfContainedDiags=*/true) {}
+
+ std::vector<StringRef> headersToInclude() const override {
+ return {"path/to/header.h", "path/to/header2.h", "path/to/header.h"};
+ }
+};
+
class CSystemIncludeInserterCheck : public IncludeInserterCheckBase {
public:
CSystemIncludeInserterCheck(StringRef CheckName, ClangTidyContext *Context)
@@ -246,6 +261,41 @@
PreCode, "clang_tidy/tests/insert_includes_test_input2.cc"));
}
+TEST(IncludeInserterTest, InsertMultipleIncludesNoDeduplicate) {
+ const char *PreCode = R"(
+#include "clang_tidy/tests/insert_includes_test_header.h"
+
+#include <list>
+#include <map>
+
+#include "path/to/a/header.h"
+
+void foo() {
+ int a = 0;
+})";
+ // FIXME: ClangFormat bug - https://bugs.llvm.org/show_bug.cgi?id=49298
+ // clang-format off
+ const char *PostCode = R"(
+#include "clang_tidy/tests/insert_includes_test_header.h"
+
+#include <list>
+#include <map>
+
+#include "path/to/a/header.h"
+#include "path/to/header.h"
+#include "path/to/header2.h"
+#include "path/to/header.h"
+
+void foo() {
+ int a = 0;
+})";
+ // clang-format on
+
+ EXPECT_EQ(PostCode,
+ runCheckOnCode<MultipleHeaderSingleInserterCheck>(
+ PreCode, "clang_tidy/tests/insert_includes_test_input2.cc"));
+}
+
TEST(IncludeInserterTest, InsertBeforeFirstNonSystemInclude) {
const char *PreCode = R"(
#include "clang_tidy/tests/insert_includes_test_header.h"
Index: clang-tools-extra/docs/ReleaseNotes.rst
===================================================================
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -53,6 +53,7 @@
Diagnostics
^^^^^^^^^^^
+- Improved Fix-its of some clang-tidy checks when applied with clangd.
Semantic Highlighting
^^^^^^^^^^^^^^^^^^^^^
Index: clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
+++ clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
@@ -678,6 +678,67 @@
Diag(Main.range(), "do not use 'else' after 'return'"))));
}
+TEST(DiagnosticTest, ClangTidySelfContainedDiags) {
+ Annotations Main(R"cpp($MathHeader[[]]
+ struct Foo{
+ int A, B;
+ Foo()$Fix[[]] {
+ $A[[A = 1;]]
+ $B[[B = 1;]]
+ }
+ };
+ void InitVariables() {
+ float $C[[C]]$CFix[[]];
+ double $D[[D]]$DFix[[]];
+ }
+ )cpp");
+ TestTU TU = TestTU::withCode(Main.code());
+ TU.ClangTidyProvider =
+ addTidyChecks("cppcoreguidelines-prefer-member-initializer,"
+ "cppcoreguidelines-init-variables");
+ clangd::Fix ExpectedAFix;
+ ExpectedAFix.Message =
+ "'A' should be initialized in a member initializer of the constructor";
+ ExpectedAFix.Edits.push_back(TextEdit{Main.range("Fix"), " : A(1)"});
+ ExpectedAFix.Edits.push_back(TextEdit{Main.range("A"), ""});
+
+ // When invoking clang-tidy normally, this code would produce `, B(1)` as the
+ // fix the `B` member, as it would think its already included the ` : ` from
+ // the previous `A` fix.
+ clangd::Fix ExpectedBFix;
+ ExpectedBFix.Message =
+ "'B' should be initialized in a member initializer of the constructor";
+ ExpectedBFix.Edits.push_back(TextEdit{Main.range("Fix"), " : B(1)"});
+ ExpectedBFix.Edits.push_back(TextEdit{Main.range("B"), ""});
+
+ clangd::Fix ExpectedCFix;
+ ExpectedCFix.Message = "variable 'C' is not initialized";
+ ExpectedCFix.Edits.push_back(TextEdit{Main.range("CFix"), " = NAN"});
+ ExpectedCFix.Edits.push_back(
+ TextEdit{Main.range("MathHeader"), "#include <math.h>\n\n"});
+
+ // Again in clang-tidy only the include directive would be emitted for the
+ // first warning. However we need the include attaching for both warnings.
+ clangd::Fix ExpectedDFix;
+ ExpectedDFix.Message = "variable 'D' is not initialized";
+ ExpectedDFix.Edits.push_back(TextEdit{Main.range("DFix"), " = NAN"});
+ ExpectedDFix.Edits.push_back(
+ TextEdit{Main.range("MathHeader"), "#include <math.h>\n\n"});
+ EXPECT_THAT(
+ *TU.build().getDiagnostics(),
+ UnorderedElementsAre(
+ AllOf(Diag(Main.range("A"), "'A' should be initialized in a member "
+ "initializer of the constructor"),
+ withFix(equalToFix(ExpectedAFix))),
+ AllOf(Diag(Main.range("B"), "'B' should be initialized in a member "
+ "initializer of the constructor"),
+ withFix(equalToFix(ExpectedBFix))),
+ AllOf(Diag(Main.range("C"), "variable 'C' is not initialized"),
+ withFix(equalToFix(ExpectedCFix))),
+ AllOf(Diag(Main.range("D"), "variable 'D' is not initialized"),
+ withFix(equalToFix(ExpectedDFix)))));
+}
+
TEST(DiagnosticsTest, Preprocessor) {
// This looks like a preamble, but there's an #else in the middle!
// Check that:
Index: clang-tools-extra/clangd/ParsedAST.cpp
===================================================================
--- clang-tools-extra/clangd/ParsedAST.cpp
+++ clang-tools-extra/clangd/ParsedAST.cpp
@@ -412,6 +412,7 @@
CTContext->setDiagnosticsEngine(&Clang->getDiagnostics());
CTContext->setASTContext(&Clang->getASTContext());
CTContext->setCurrentFile(Filename);
+ CTContext->setSelfContainedDiags(true);
CTChecks = CTFactories.createChecks(CTContext.getPointer());
llvm::erase_if(CTChecks, [&](const auto &Check) {
return !Check->isLanguageVersionSupported(CTContext->getLangOpts());
Index: clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.cpp
===================================================================
--- clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.cpp
+++ clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.cpp
@@ -30,8 +30,8 @@
TransformerClangTidyCheck::TransformerClangTidyCheck(StringRef Name,
ClangTidyContext *Context)
: ClangTidyCheck(Name, Context),
- Inserter(
- Options.getLocalOrGlobal("IncludeStyle", IncludeSorter::IS_LLVM)) {}
+ Inserter(Options.getLocalOrGlobal("IncludeStyle", IncludeSorter::IS_LLVM),
+ areDiagsSelfContained()) {}
// This constructor cannot dispatch to the simpler one (below), because, in
// order to get meaningful results from `getLangOpts` and `Options`, we need the
Index: clang-tools-extra/clang-tidy/utils/IncludeInserter.h
===================================================================
--- clang-tools-extra/clang-tidy/utils/IncludeInserter.h
+++ clang-tools-extra/clang-tidy/utils/IncludeInserter.h
@@ -59,7 +59,8 @@
/// using \code
/// Options.getLocalOrGlobal("IncludeStyle", <DefaultStyle>)
/// \endcode
- explicit IncludeInserter(IncludeSorter::IncludeStyle Style);
+ explicit IncludeInserter(IncludeSorter::IncludeStyle Style,
+ bool SelfContainedDiags);
/// Registers this with the Preprocessor \p PP, must be called before this
/// class is used.
@@ -93,6 +94,7 @@
llvm::DenseMap<FileID, llvm::StringSet<>> InsertedHeaders;
const SourceManager *SourceMgr{nullptr};
const IncludeSorter::IncludeStyle Style;
+ const bool SelfContainedDiags;
friend class IncludeInserterCallback;
};
Index: clang-tools-extra/clang-tidy/utils/IncludeInserter.cpp
===================================================================
--- clang-tools-extra/clang-tidy/utils/IncludeInserter.cpp
+++ clang-tools-extra/clang-tidy/utils/IncludeInserter.cpp
@@ -36,8 +36,9 @@
IncludeInserter *Inserter;
};
-IncludeInserter::IncludeInserter(IncludeSorter::IncludeStyle Style)
- : Style(Style) {}
+IncludeInserter::IncludeInserter(IncludeSorter::IncludeStyle Style,
+ bool SelfContainedDiags)
+ : Style(Style), SelfContainedDiags(SelfContainedDiags) {}
void IncludeInserter::registerPreprocessor(Preprocessor *PP) {
assert(PP && "PP shouldn't be null");
@@ -73,7 +74,9 @@
return llvm::None;
// We assume the same Header will never be included both angled and not
// angled.
- if (!InsertedHeaders[FileID].insert(Header).second)
+ // In self contained diags mode we don't track what headers we have already
+ // inserted.
+ if (!SelfContainedDiags && !InsertedHeaders[FileID].insert(Header).second)
return llvm::None;
return getOrCreate(FileID).createIncludeInsertion(Header, IsAngled);
Index: clang-tools-extra/clang-tidy/performance/UnnecessaryValueParamCheck.cpp
===================================================================
--- clang-tools-extra/clang-tidy/performance/UnnecessaryValueParamCheck.cpp
+++ clang-tools-extra/clang-tidy/performance/UnnecessaryValueParamCheck.cpp
@@ -69,7 +69,8 @@
StringRef Name, ClangTidyContext *Context)
: ClangTidyCheck(Name, Context),
Inserter(Options.getLocalOrGlobal("IncludeStyle",
- utils::IncludeSorter::IS_LLVM)),
+ utils::IncludeSorter::IS_LLVM),
+ areDiagsSelfContained()),
AllowedTypes(
utils::options::parseStringList(Options.get("AllowedTypes", ""))) {}
Index: clang-tools-extra/clang-tidy/performance/TypePromotionInMathFnCheck.cpp
===================================================================
--- clang-tools-extra/clang-tidy/performance/TypePromotionInMathFnCheck.cpp
+++ clang-tools-extra/clang-tidy/performance/TypePromotionInMathFnCheck.cpp
@@ -32,8 +32,8 @@
StringRef Name, ClangTidyContext *Context)
: ClangTidyCheck(Name, Context),
IncludeInserter(Options.getLocalOrGlobal("IncludeStyle",
- utils::IncludeSorter::IS_LLVM)) {
-}
+ utils::IncludeSorter::IS_LLVM),
+ areDiagsSelfContained()) {}
void TypePromotionInMathFnCheck::registerPPCallbacks(
const SourceManager &SM, Preprocessor *PP, Preprocessor *ModuleExpanderPP) {
Index: clang-tools-extra/clang-tidy/modernize/ReplaceRandomShuffleCheck.cpp
===================================================================
--- clang-tools-extra/clang-tidy/modernize/ReplaceRandomShuffleCheck.cpp
+++ clang-tools-extra/clang-tidy/modernize/ReplaceRandomShuffleCheck.cpp
@@ -24,8 +24,8 @@
ClangTidyContext *Context)
: ClangTidyCheck(Name, Context),
IncludeInserter(Options.getLocalOrGlobal("IncludeStyle",
- utils::IncludeSorter::IS_LLVM)) {
-}
+ utils::IncludeSorter::IS_LLVM),
+ areDiagsSelfContained()) {}
void ReplaceRandomShuffleCheck::registerMatchers(MatchFinder *Finder) {
const auto Begin = hasArgument(0, expr());
Index: clang-tools-extra/clang-tidy/modernize/ReplaceAutoPtrCheck.cpp
===================================================================
--- clang-tools-extra/clang-tidy/modernize/ReplaceAutoPtrCheck.cpp
+++ clang-tools-extra/clang-tidy/modernize/ReplaceAutoPtrCheck.cpp
@@ -41,7 +41,8 @@
ClangTidyContext *Context)
: ClangTidyCheck(Name, Context),
Inserter(Options.getLocalOrGlobal("IncludeStyle",
- utils::IncludeSorter::IS_LLVM)) {}
+ utils::IncludeSorter::IS_LLVM),
+ areDiagsSelfContained()) {}
void ReplaceAutoPtrCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
Options.store(Opts, "IncludeStyle", Inserter.getStyle());
Index: clang-tools-extra/clang-tidy/modernize/PassByValueCheck.cpp
===================================================================
--- clang-tools-extra/clang-tidy/modernize/PassByValueCheck.cpp
+++ clang-tools-extra/clang-tidy/modernize/PassByValueCheck.cpp
@@ -190,7 +190,8 @@
PassByValueCheck::PassByValueCheck(StringRef Name, ClangTidyContext *Context)
: ClangTidyCheck(Name, Context),
Inserter(Options.getLocalOrGlobal("IncludeStyle",
- utils::IncludeSorter::IS_LLVM)),
+ utils::IncludeSorter::IS_LLVM),
+ areDiagsSelfContained()),
ValuesOnly(Options.get("ValuesOnly", false)) {}
void PassByValueCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
Index: clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp
===================================================================
--- clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp
+++ clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp
@@ -44,7 +44,8 @@
StringRef MakeSmartPtrFunctionName)
: ClangTidyCheck(Name, Context),
Inserter(Options.getLocalOrGlobal("IncludeStyle",
- utils::IncludeSorter::IS_LLVM)),
+ utils::IncludeSorter::IS_LLVM),
+ areDiagsSelfContained()),
MakeSmartPtrFunctionHeader(
Options.get("MakeSmartPtrFunctionHeader", "<memory>")),
MakeSmartPtrFunctionName(
Index: clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
===================================================================
--- clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
+++ clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
@@ -463,7 +463,8 @@
MinConfidence(Options.get("MinConfidence", Confidence::CL_Reasonable)),
NamingStyle(Options.get("NamingStyle", VariableNamer::NS_CamelCase)),
Inserter(Options.getLocalOrGlobal("IncludeStyle",
- utils::IncludeSorter::IS_LLVM)),
+ utils::IncludeSorter::IS_LLVM),
+ areDiagsSelfContained()),
UseCxx20IfAvailable(Options.get("UseCxx20ReverseRanges", true)),
ReverseFunction(Options.get("MakeReverseRangeFunction", "")),
ReverseHeader(Options.get("MakeReverseRangeHeader", "")) {
@@ -800,9 +801,12 @@
const ast_matchers::BoundNodes &Nodes,
const ForStmt *Loop,
LoopFixerKind FixerKind) {
- // If we already modified the range of this for loop, don't do any further
- // updates on this iteration.
- if (TUInfo->getReplacedVars().count(Loop))
+ // In self contained diagnosics mode we don't want dependancies on other
+ // loops, otherwise, If we already modified the range of this for loop, don't
+ // do any further updates on this iteration.
+ if (areDiagsSelfContained())
+ TUInfo = std::make_unique<TUTrackingInfo>();
+ else if (TUInfo->getReplacedVars().count(Loop))
return false;
// Check that we have exactly one index variable and at most one end variable.
Index: clang-tools-extra/clang-tidy/misc/UniqueptrResetReleaseCheck.cpp
===================================================================
--- clang-tools-extra/clang-tidy/misc/UniqueptrResetReleaseCheck.cpp
+++ clang-tools-extra/clang-tidy/misc/UniqueptrResetReleaseCheck.cpp
@@ -20,7 +20,8 @@
StringRef Name, ClangTidyContext *Context)
: ClangTidyCheck(Name, Context),
Inserter(Options.getLocalOrGlobal("IncludeStyle",
- utils::IncludeSorter::IS_LLVM)) {}
+ utils::IncludeSorter::IS_LLVM),
+ areDiagsSelfContained()) {}
void UniqueptrResetReleaseCheck::storeOptions(
ClangTidyOptions::OptionMap &Opts) {
Index: clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.cpp
===================================================================
--- clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.cpp
+++ clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.cpp
@@ -22,7 +22,8 @@
StringRef Name, ClangTidyContext *Context)
: ClangTidyCheck(Name, Context), GslHeader(Options.get("GslHeader", "")),
Inserter(Options.getLocalOrGlobal("IncludeStyle",
- utils::IncludeSorter::IS_LLVM)) {}
+ utils::IncludeSorter::IS_LLVM),
+ areDiagsSelfContained()) {}
void ProBoundsConstantArrayIndexCheck::storeOptions(
ClangTidyOptions::OptionMap &Opts) {
Index: clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
===================================================================
--- clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
+++ clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
@@ -306,10 +306,10 @@
NewInit, AddComma ? "), " : ")"});
Diag << FixItHint::CreateInsertion(InsertPos, Insertion,
FirstToCtorInits);
+ FirstToCtorInits = areDiagsSelfContained();
}
Diag << FixItHint::CreateRemoval(
CharSourceRange::getCharRange(S->getBeginLoc(), SemiColonEnd));
- FirstToCtorInits = false;
}
}
}
Index: clang-tools-extra/clang-tidy/cppcoreguidelines/InitVariablesCheck.cpp
===================================================================
--- clang-tools-extra/clang-tidy/cppcoreguidelines/InitVariablesCheck.cpp
+++ clang-tools-extra/clang-tidy/cppcoreguidelines/InitVariablesCheck.cpp
@@ -27,7 +27,8 @@
ClangTidyContext *Context)
: ClangTidyCheck(Name, Context),
IncludeInserter(Options.getLocalOrGlobal("IncludeStyle",
- utils::IncludeSorter::IS_LLVM)),
+ utils::IncludeSorter::IS_LLVM),
+ areDiagsSelfContained()),
MathHeader(Options.get("MathHeader", "<math.h>")) {}
void InitVariablesCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
Index: clang-tools-extra/clang-tidy/bugprone/ImplicitWideningOfMultiplicationResultCheck.cpp
===================================================================
--- clang-tools-extra/clang-tidy/bugprone/ImplicitWideningOfMultiplicationResultCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/ImplicitWideningOfMultiplicationResultCheck.cpp
@@ -43,8 +43,8 @@
Options.get("UseCXXStaticCastsInCppSources", true)),
UseCXXHeadersInCppSources(Options.get("UseCXXHeadersInCppSources", true)),
IncludeInserter(Options.getLocalOrGlobal("IncludeStyle",
- utils::IncludeSorter::IS_LLVM)) {
-}
+ utils::IncludeSorter::IS_LLVM),
+ areDiagsSelfContained()) {}
void ImplicitWideningOfMultiplicationResultCheck::registerPPCallbacks(
const SourceManager &SM, Preprocessor *PP, Preprocessor *ModuleExpanderPP) {
Index: clang-tools-extra/clang-tidy/abseil/StringFindStartswithCheck.cpp
===================================================================
--- clang-tools-extra/clang-tidy/abseil/StringFindStartswithCheck.cpp
+++ clang-tools-extra/clang-tidy/abseil/StringFindStartswithCheck.cpp
@@ -27,7 +27,8 @@
StringLikeClasses(utils::options::parseStringList(
Options.get("StringLikeClasses", "::std::basic_string"))),
IncludeInserter(Options.getLocalOrGlobal("IncludeStyle",
- utils::IncludeSorter::IS_LLVM)),
+ utils::IncludeSorter::IS_LLVM),
+ areDiagsSelfContained()),
AbseilStringsMatchHeader(
Options.get("AbseilStringsMatchHeader", "absl/strings/match.h")) {}
Index: clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h
===================================================================
--- clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h
+++ clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h
@@ -187,6 +187,10 @@
return AllowEnablingAnalyzerAlphaCheckers;
}
+ void setSelfContainedDiags(bool Value) { SelfContainedDiags = Value; }
+
+ bool areDiagsSelfContained() const { return SelfContainedDiags; }
+
using DiagLevelAndFormatString = std::pair<DiagnosticIDs::Level, std::string>;
DiagLevelAndFormatString getDiagLevelAndFormatString(unsigned DiagnosticID,
SourceLocation Loc) {
@@ -223,6 +227,8 @@
bool AllowEnablingAnalyzerAlphaCheckers;
+ bool SelfContainedDiags;
+
NoLintDirectiveHandler NoLintHandler;
};
Index: clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
===================================================================
--- clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
+++ clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
@@ -162,7 +162,8 @@
bool AllowEnablingAnalyzerAlphaCheckers)
: DiagEngine(nullptr), OptionsProvider(std::move(OptionsProvider)),
Profile(false),
- AllowEnablingAnalyzerAlphaCheckers(AllowEnablingAnalyzerAlphaCheckers) {
+ AllowEnablingAnalyzerAlphaCheckers(AllowEnablingAnalyzerAlphaCheckers),
+ SelfContainedDiags(false) {
// Before the first translation unit we can get errors related to command-line
// parsing, use empty string for the file name in this case.
setCurrentFile("");
Index: clang-tools-extra/clang-tidy/ClangTidyCheck.h
===================================================================
--- clang-tools-extra/clang-tidy/ClangTidyCheck.h
+++ clang-tools-extra/clang-tidy/ClangTidyCheck.h
@@ -417,6 +417,11 @@
StringRef getCurrentMainFile() const { return Context->getCurrentFile(); }
/// Returns the language options from the context.
const LangOptions &getLangOpts() const { return Context->getLangOpts(); }
+ /// Returns true when the check is run in a use case when only 1 fix will be
+ /// applied at a time.
+ bool areDiagsSelfContained() const {
+ return Context->areDiagsSelfContained();
+ }
};
/// Read a named option from the ``Context`` and parse it as a bool.
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits