https://github.com/localspook updated https://github.com/llvm/llvm-project/pull/185879
>From 27a2db908061eb9a7c9fbcae8e164615b396db90 Mon Sep 17 00:00:00 2001 From: Victor Chernyakin <[email protected]> Date: Wed, 11 Mar 2026 05:23:41 -0700 Subject: [PATCH 1/2] [clang-tidy] Prototype: removing the `IncludeStyle` option --- .../abseil/StringFindStartswithCheck.cpp | 5 +- ...citWideningOfMultiplicationResultCheck.cpp | 5 +- .../cppcoreguidelines/InitVariablesCheck.cpp | 6 +- .../ProBoundsConstantArrayIndexCheck.cpp | 5 +- .../clang-tidy/custom/CustomTidyModule.cpp | 2 +- .../clang-tidy/llvm/UseVectorUtilsCheck.cpp | 3 +- .../misc/UniqueptrResetReleaseCheck.cpp | 10 +- .../misc/UniqueptrResetReleaseCheck.h | 1 - .../clang-tidy/modernize/LoopConvertCheck.cpp | 5 +- .../modernize/MakeSmartPtrCheck.cpp | 6 +- .../MinMaxUseInitializerListCheck.cpp | 5 +- .../clang-tidy/modernize/PassByValueCheck.cpp | 6 +- .../modernize/ReplaceAutoPtrCheck.cpp | 9 +- .../modernize/ReplaceAutoPtrCheck.h | 1 - .../modernize/ReplaceRandomShuffleCheck.cpp | 10 +- .../modernize/ReplaceRandomShuffleCheck.h | 1 - .../UseIntegerSignComparisonCheck.cpp | 6 +- .../modernize/UseStdFormatCheck.cpp | 5 +- .../modernize/UseStdNumbersCheck.cpp | 6 +- .../clang-tidy/modernize/UseStdPrintCheck.cpp | 5 +- .../TypePromotionInMathFnCheck.cpp | 10 +- .../performance/TypePromotionInMathFnCheck.h | 1 - .../UnnecessaryValueParamCheck.cpp | 6 +- .../readability/UseStdMinMaxCheck.cpp | 9 +- .../readability/UseStdMinMaxCheck.h | 1 - .../clang-tidy/utils/CMakeLists.txt | 1 - .../clang-tidy/utils/IncludeInserter.cpp | 64 +++-- .../clang-tidy/utils/IncludeInserter.h | 36 +-- .../clang-tidy/utils/IncludeSorter.cpp | 228 ------------------ .../clang-tidy/utils/IncludeSorter.h | 76 ------ .../utils/TransformerClangTidyCheck.cpp | 9 +- .../utils/TransformerClangTidyCheck.h | 3 +- .../clang-tidy/utils/UseRangesCheck.cpp | 9 +- .../clang-tidy/utils/UseRangesCheck.h | 1 - .../checks/abseil/string-find-startswith.rst | 5 - .../abseil/string-find-str-contains.rst | 5 - .../clang-tidy/checks/boost/use-ranges.rst | 5 - .../cppcoreguidelines/init-variables.rst | 5 - .../pro-bounds-constant-array-index.rst | 5 - .../checks/misc/uniqueptr-reset-release.rst | 8 - .../checks/modernize/loop-convert.rst | 5 - .../checks/modernize/make-shared.rst | 5 - .../checks/modernize/make-unique.rst | 5 - .../min-max-use-initializer-list.rst | 5 - .../checks/modernize/pass-by-value.rst | 5 - .../checks/modernize/replace-auto-ptr.rst | 8 - .../modernize/use-integer-sign-comparison.rst | 5 - .../checks/modernize/use-ranges.rst | 5 - .../checks/modernize/use-std-numbers.rst | 5 - .../performance/unnecessary-value-param.rst | 5 - .../infrastructure/dump-config-invalid.cpp | 6 +- .../clang-tidy/IncludeInserterTest.cpp | 2 +- .../clang-tidy/utils/BUILD.gn | 1 - 53 files changed, 66 insertions(+), 585 deletions(-) delete mode 100644 clang-tools-extra/clang-tidy/utils/IncludeSorter.cpp delete mode 100644 clang-tools-extra/clang-tidy/utils/IncludeSorter.h diff --git a/clang-tools-extra/clang-tidy/abseil/StringFindStartswithCheck.cpp b/clang-tools-extra/clang-tidy/abseil/StringFindStartswithCheck.cpp index e1063c4f8a46e..3e44ee10b8293 100644 --- a/clang-tools-extra/clang-tidy/abseil/StringFindStartswithCheck.cpp +++ b/clang-tools-extra/clang-tidy/abseil/StringFindStartswithCheck.cpp @@ -27,9 +27,7 @@ StringFindStartswithCheck::StringFindStartswithCheck(StringRef Name, : ClangTidyCheck(Name, Context), StringLikeClasses(utils::options::parseStringList( Options.get("StringLikeClasses", DefaultStringLikeClasses))), - IncludeInserter(Options.getLocalOrGlobal("IncludeStyle", - utils::IncludeSorter::IS_LLVM), - areDiagsSelfContained()), + IncludeInserter(areDiagsSelfContained()), AbseilStringsMatchHeader( Options.get("AbseilStringsMatchHeader", "absl/strings/match.h")) {} @@ -138,7 +136,6 @@ void StringFindStartswithCheck::storeOptions( ClangTidyOptions::OptionMap &Opts) { Options.store(Opts, "StringLikeClasses", utils::options::serializeStringList(StringLikeClasses)); - Options.store(Opts, "IncludeStyle", IncludeInserter.getStyle()); Options.store(Opts, "AbseilStringsMatchHeader", AbseilStringsMatchHeader); } diff --git a/clang-tools-extra/clang-tidy/bugprone/ImplicitWideningOfMultiplicationResultCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/ImplicitWideningOfMultiplicationResultCheck.cpp index 7c259a6199832..5ecdb08f35179 100644 --- a/clang-tools-extra/clang-tidy/bugprone/ImplicitWideningOfMultiplicationResultCheck.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/ImplicitWideningOfMultiplicationResultCheck.cpp @@ -43,9 +43,7 @@ ImplicitWideningOfMultiplicationResultCheck:: Options.get("UseCXXStaticCastsInCppSources", true)), UseCXXHeadersInCppSources(Options.get("UseCXXHeadersInCppSources", true)), IgnoreConstantIntExpr(Options.get("IgnoreConstantIntExpr", false)), - IncludeInserter(Options.getLocalOrGlobal("IncludeStyle", - utils::IncludeSorter::IS_LLVM), - areDiagsSelfContained()) {} + IncludeInserter(areDiagsSelfContained()) {} void ImplicitWideningOfMultiplicationResultCheck::registerPPCallbacks( const SourceManager &SM, Preprocessor *PP, Preprocessor *ModuleExpanderPP) { @@ -58,7 +56,6 @@ void ImplicitWideningOfMultiplicationResultCheck::storeOptions( UseCXXStaticCastsInCppSources); Options.store(Opts, "UseCXXHeadersInCppSources", UseCXXHeadersInCppSources); Options.store(Opts, "IgnoreConstantIntExpr", IgnoreConstantIntExpr); - Options.store(Opts, "IncludeStyle", IncludeInserter.getStyle()); } std::optional<FixItHint> diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/InitVariablesCheck.cpp b/clang-tools-extra/clang-tidy/cppcoreguidelines/InitVariablesCheck.cpp index 402ee9efcbc04..99ddd45669adb 100644 --- a/clang-tools-extra/clang-tidy/cppcoreguidelines/InitVariablesCheck.cpp +++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/InitVariablesCheck.cpp @@ -25,14 +25,10 @@ AST_MATCHER(VarDecl, isLocalVarDecl) { return Node.isLocalVarDecl(); } InitVariablesCheck::InitVariablesCheck(StringRef Name, ClangTidyContext *Context) - : ClangTidyCheck(Name, Context), - IncludeInserter(Options.getLocalOrGlobal("IncludeStyle", - utils::IncludeSorter::IS_LLVM), - areDiagsSelfContained()), + : ClangTidyCheck(Name, Context), IncludeInserter(areDiagsSelfContained()), MathHeader(Options.get("MathHeader", "<math.h>")) {} void InitVariablesCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) { - Options.store(Opts, "IncludeStyle", IncludeInserter.getStyle()); Options.store(Opts, "MathHeader", MathHeader); } diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.cpp b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.cpp index 82fc9f253ac1c..f34895b47c304 100644 --- a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.cpp +++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.cpp @@ -20,14 +20,11 @@ namespace clang::tidy::cppcoreguidelines { ProBoundsConstantArrayIndexCheck::ProBoundsConstantArrayIndexCheck( StringRef Name, ClangTidyContext *Context) : ClangTidyCheck(Name, Context), GslHeader(Options.get("GslHeader", "")), - Inserter(Options.getLocalOrGlobal("IncludeStyle", - utils::IncludeSorter::IS_LLVM), - areDiagsSelfContained()) {} + Inserter(areDiagsSelfContained()) {} void ProBoundsConstantArrayIndexCheck::storeOptions( ClangTidyOptions::OptionMap &Opts) { Options.store(Opts, "GslHeader", GslHeader); - Options.store(Opts, "IncludeStyle", Inserter.getStyle()); } void ProBoundsConstantArrayIndexCheck::registerPPCallbacks( diff --git a/clang-tools-extra/clang-tidy/custom/CustomTidyModule.cpp b/clang-tools-extra/clang-tidy/custom/CustomTidyModule.cpp index f2267c2549eac..2415cab1d30c0 100644 --- a/clang-tools-extra/clang-tidy/custom/CustomTidyModule.cpp +++ b/clang-tools-extra/clang-tidy/custom/CustomTidyModule.cpp @@ -15,7 +15,7 @@ namespace custom { // will changed dynamically when switching to different source file. static void registerCustomChecks(const ClangTidyOptions &Options, ClangTidyCheckFactories &Factories) { - static llvm::SmallSet<llvm::SmallString<32>, 8> CustomCheckNames{}; + static llvm::SmallSet<SmallString<32>, 8> CustomCheckNames{}; if (!Options.CustomChecks.has_value() || Options.CustomChecks->empty()) return; for (const llvm::SmallString<32> &Name : CustomCheckNames) diff --git a/clang-tools-extra/clang-tidy/llvm/UseVectorUtilsCheck.cpp b/clang-tools-extra/clang-tidy/llvm/UseVectorUtilsCheck.cpp index bd915eb55b448..9fc176de1f502 100644 --- a/clang-tools-extra/clang-tidy/llvm/UseVectorUtilsCheck.cpp +++ b/clang-tools-extra/clang-tidy/llvm/UseVectorUtilsCheck.cpp @@ -17,8 +17,7 @@ namespace clang::tidy::llvm_check { UseVectorUtilsCheck::UseVectorUtilsCheck(StringRef Name, ClangTidyContext *Context) - : ClangTidyCheck(Name, Context), - Inserter(utils::IncludeSorter::IS_LLVM, areDiagsSelfContained()) {} + : ClangTidyCheck(Name, Context), Inserter(areDiagsSelfContained()) {} void UseVectorUtilsCheck::registerPPCallbacks(const SourceManager &SM, Preprocessor *PP, diff --git a/clang-tools-extra/clang-tidy/misc/UniqueptrResetReleaseCheck.cpp b/clang-tools-extra/clang-tidy/misc/UniqueptrResetReleaseCheck.cpp index ab2077b304f13..df934b6ab999e 100644 --- a/clang-tools-extra/clang-tidy/misc/UniqueptrResetReleaseCheck.cpp +++ b/clang-tools-extra/clang-tidy/misc/UniqueptrResetReleaseCheck.cpp @@ -16,15 +16,7 @@ namespace clang::tidy::misc { UniqueptrResetReleaseCheck::UniqueptrResetReleaseCheck( StringRef Name, ClangTidyContext *Context) - : ClangTidyCheck(Name, Context), - Inserter(Options.getLocalOrGlobal("IncludeStyle", - utils::IncludeSorter::IS_LLVM), - areDiagsSelfContained()) {} - -void UniqueptrResetReleaseCheck::storeOptions( - ClangTidyOptions::OptionMap &Opts) { - Options.store(Opts, "IncludeStyle", Inserter.getStyle()); -} + : ClangTidyCheck(Name, Context), Inserter(areDiagsSelfContained()) {} void UniqueptrResetReleaseCheck::registerPPCallbacks( const SourceManager &SM, Preprocessor *PP, Preprocessor *ModuleExpanderPP) { diff --git a/clang-tools-extra/clang-tidy/misc/UniqueptrResetReleaseCheck.h b/clang-tools-extra/clang-tidy/misc/UniqueptrResetReleaseCheck.h index cb83ac7b11985..732135a07b1ee 100644 --- a/clang-tools-extra/clang-tidy/misc/UniqueptrResetReleaseCheck.h +++ b/clang-tools-extra/clang-tidy/misc/UniqueptrResetReleaseCheck.h @@ -39,7 +39,6 @@ class UniqueptrResetReleaseCheck : public ClangTidyCheck { Preprocessor *ModuleExpanderPP) override; void registerMatchers(ast_matchers::MatchFinder *Finder) override; void check(const ast_matchers::MatchFinder::MatchResult &Result) override; - void storeOptions(ClangTidyOptions::OptionMap &Opts) override; private: utils::IncludeInserter Inserter; diff --git a/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp b/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp index 2d63da2fef974..433664e528e6d 100644 --- a/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp +++ b/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp @@ -557,9 +557,7 @@ LoopConvertCheck::LoopConvertCheck(StringRef Name, ClangTidyContext *Context) MaxCopySize(Options.get("MaxCopySize", 16ULL)), MinConfidence(Options.get("MinConfidence", Confidence::CL_Reasonable)), NamingStyle(Options.get("NamingStyle", VariableNamer::NS_CamelCase)), - Inserter(Options.getLocalOrGlobal("IncludeStyle", - utils::IncludeSorter::IS_LLVM), - areDiagsSelfContained()), + Inserter(areDiagsSelfContained()), UseCxx20IfAvailable(Options.get("UseCxx20ReverseRanges", true)), ReverseFunction(Options.get("MakeReverseRangeFunction", "")), ReverseHeader(Options.get("MakeReverseRangeHeader", "")) { @@ -580,7 +578,6 @@ void LoopConvertCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) { Options.store(Opts, "MaxCopySize", MaxCopySize); Options.store(Opts, "MinConfidence", MinConfidence); Options.store(Opts, "NamingStyle", NamingStyle); - Options.store(Opts, "IncludeStyle", Inserter.getStyle()); Options.store(Opts, "UseCxx20ReverseRanges", UseCxx20IfAvailable); Options.store(Opts, "MakeReverseRangeFunction", ReverseFunction); Options.store(Opts, "MakeReverseRangeHeader", ReverseHeader); diff --git a/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp b/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp index 42a60bb897028..e19da39f41560 100644 --- a/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp +++ b/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp @@ -35,10 +35,7 @@ static std::string getNewExprName(const CXXNewExpr *NewExpr, MakeSmartPtrCheck::MakeSmartPtrCheck(StringRef Name, ClangTidyContext *Context, StringRef MakeSmartPtrFunctionName) - : ClangTidyCheck(Name, Context), - Inserter(Options.getLocalOrGlobal("IncludeStyle", - utils::IncludeSorter::IS_LLVM), - areDiagsSelfContained()), + : ClangTidyCheck(Name, Context), Inserter(areDiagsSelfContained()), MakeSmartPtrFunctionHeader( Options.get("MakeSmartPtrFunctionHeader", "<memory>")), MakeSmartPtrFunctionName( @@ -48,7 +45,6 @@ MakeSmartPtrCheck::MakeSmartPtrCheck(StringRef Name, ClangTidyContext *Context, Options.get("IgnoreDefaultInitialization", true)) {} void MakeSmartPtrCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) { - Options.store(Opts, "IncludeStyle", Inserter.getStyle()); Options.store(Opts, "MakeSmartPtrFunctionHeader", MakeSmartPtrFunctionHeader); Options.store(Opts, "MakeSmartPtrFunction", MakeSmartPtrFunctionName); Options.store(Opts, "IgnoreMacros", IgnoreMacros); diff --git a/clang-tools-extra/clang-tidy/modernize/MinMaxUseInitializerListCheck.cpp b/clang-tools-extra/clang-tidy/modernize/MinMaxUseInitializerListCheck.cpp index f4592950fc05e..27da146357adc 100644 --- a/clang-tools-extra/clang-tidy/modernize/MinMaxUseInitializerListCheck.cpp +++ b/clang-tools-extra/clang-tidy/modernize/MinMaxUseInitializerListCheck.cpp @@ -207,16 +207,13 @@ MinMaxUseInitializerListCheck::MinMaxUseInitializerListCheck( IgnoreNonTrivialTypes(Options.get("IgnoreNonTrivialTypes", true)), IgnoreTrivialTypesOfSizeAbove( Options.get("IgnoreTrivialTypesOfSizeAbove", 32L)), - Inserter(Options.getLocalOrGlobal("IncludeStyle", - utils::IncludeSorter::IS_LLVM), - areDiagsSelfContained()) {} + Inserter(areDiagsSelfContained()) {} void MinMaxUseInitializerListCheck::storeOptions( ClangTidyOptions::OptionMap &Opts) { Options.store(Opts, "IgnoreNonTrivialTypes", IgnoreNonTrivialTypes); Options.store(Opts, "IgnoreTrivialTypesOfSizeAbove", IgnoreTrivialTypesOfSizeAbove); - Options.store(Opts, "IncludeStyle", Inserter.getStyle()); } void MinMaxUseInitializerListCheck::registerMatchers(MatchFinder *Finder) { diff --git a/clang-tools-extra/clang-tidy/modernize/PassByValueCheck.cpp b/clang-tools-extra/clang-tidy/modernize/PassByValueCheck.cpp index 2619331cba0b0..d932c6ad79ee1 100644 --- a/clang-tools-extra/clang-tidy/modernize/PassByValueCheck.cpp +++ b/clang-tools-extra/clang-tidy/modernize/PassByValueCheck.cpp @@ -212,15 +212,11 @@ collectParamDecls(const CXXConstructorDecl *Ctor, } PassByValueCheck::PassByValueCheck(StringRef Name, ClangTidyContext *Context) - : ClangTidyCheck(Name, Context), - Inserter(Options.getLocalOrGlobal("IncludeStyle", - utils::IncludeSorter::IS_LLVM), - areDiagsSelfContained()), + : ClangTidyCheck(Name, Context), Inserter(areDiagsSelfContained()), ValuesOnly(Options.get("ValuesOnly", false)), IgnoreMacros(Options.get("IgnoreMacros", false)) {} void PassByValueCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) { - Options.store(Opts, "IncludeStyle", Inserter.getStyle()); Options.store(Opts, "ValuesOnly", ValuesOnly); Options.store(Opts, "IgnoreMacros", IgnoreMacros); } diff --git a/clang-tools-extra/clang-tidy/modernize/ReplaceAutoPtrCheck.cpp b/clang-tools-extra/clang-tidy/modernize/ReplaceAutoPtrCheck.cpp index 6af05b11bb395..a95da43087136 100644 --- a/clang-tools-extra/clang-tidy/modernize/ReplaceAutoPtrCheck.cpp +++ b/clang-tools-extra/clang-tidy/modernize/ReplaceAutoPtrCheck.cpp @@ -39,14 +39,7 @@ AST_MATCHER(Expr, isLValue) { return Node.getValueKind() == VK_LValue; } ReplaceAutoPtrCheck::ReplaceAutoPtrCheck(StringRef Name, ClangTidyContext *Context) - : ClangTidyCheck(Name, Context), - Inserter(Options.getLocalOrGlobal("IncludeStyle", - utils::IncludeSorter::IS_LLVM), - areDiagsSelfContained()) {} - -void ReplaceAutoPtrCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) { - Options.store(Opts, "IncludeStyle", Inserter.getStyle()); -} + : ClangTidyCheck(Name, Context), Inserter(areDiagsSelfContained()) {} void ReplaceAutoPtrCheck::registerMatchers(MatchFinder *Finder) { auto AutoPtrDecl = recordDecl(hasName("auto_ptr"), isInStdNamespace()); diff --git a/clang-tools-extra/clang-tidy/modernize/ReplaceAutoPtrCheck.h b/clang-tools-extra/clang-tidy/modernize/ReplaceAutoPtrCheck.h index 18f4740567d53..6bdbcc6fb8c26 100644 --- a/clang-tools-extra/clang-tidy/modernize/ReplaceAutoPtrCheck.h +++ b/clang-tools-extra/clang-tidy/modernize/ReplaceAutoPtrCheck.h @@ -44,7 +44,6 @@ class ReplaceAutoPtrCheck : public ClangTidyCheck { bool isLanguageVersionSupported(const LangOptions &LangOpts) const override { return LangOpts.CPlusPlus11; } - void storeOptions(ClangTidyOptions::OptionMap &Opts) override; void registerMatchers(ast_matchers::MatchFinder *Finder) override; void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP, Preprocessor *ModuleExpanderPP) override; diff --git a/clang-tools-extra/clang-tidy/modernize/ReplaceRandomShuffleCheck.cpp b/clang-tools-extra/clang-tidy/modernize/ReplaceRandomShuffleCheck.cpp index cfc546a06b40c..711b90748c6ce 100644 --- a/clang-tools-extra/clang-tidy/modernize/ReplaceRandomShuffleCheck.cpp +++ b/clang-tools-extra/clang-tidy/modernize/ReplaceRandomShuffleCheck.cpp @@ -18,10 +18,7 @@ namespace clang::tidy::modernize { ReplaceRandomShuffleCheck::ReplaceRandomShuffleCheck(StringRef Name, ClangTidyContext *Context) - : ClangTidyCheck(Name, Context), - IncludeInserter(Options.getLocalOrGlobal("IncludeStyle", - utils::IncludeSorter::IS_LLVM), - areDiagsSelfContained()) {} + : ClangTidyCheck(Name, Context), IncludeInserter(areDiagsSelfContained()) {} void ReplaceRandomShuffleCheck::registerMatchers(MatchFinder *Finder) { const auto Begin = hasArgument(0, expr()); @@ -44,11 +41,6 @@ void ReplaceRandomShuffleCheck::registerPPCallbacks( IncludeInserter.registerPreprocessor(PP); } -void ReplaceRandomShuffleCheck::storeOptions( - ClangTidyOptions::OptionMap &Opts) { - Options.store(Opts, "IncludeStyle", IncludeInserter.getStyle()); -} - void ReplaceRandomShuffleCheck::check(const MatchFinder::MatchResult &Result) { const auto *MatchedDecl = Result.Nodes.getNodeAs<DeclRefExpr>("name"); const auto *MatchedArgumentThree = Result.Nodes.getNodeAs<Expr>("randomFunc"); diff --git a/clang-tools-extra/clang-tidy/modernize/ReplaceRandomShuffleCheck.h b/clang-tools-extra/clang-tidy/modernize/ReplaceRandomShuffleCheck.h index 3ffa3878bc429..120f80c2fff35 100644 --- a/clang-tools-extra/clang-tidy/modernize/ReplaceRandomShuffleCheck.h +++ b/clang-tools-extra/clang-tidy/modernize/ReplaceRandomShuffleCheck.h @@ -27,7 +27,6 @@ class ReplaceRandomShuffleCheck : public ClangTidyCheck { bool isLanguageVersionSupported(const LangOptions &LangOpts) const override { return LangOpts.CPlusPlus11; } - void storeOptions(ClangTidyOptions::OptionMap &Opts) override; void registerMatchers(ast_matchers::MatchFinder *Finder) override; void check(const ast_matchers::MatchFinder::MatchResult &Result) override; diff --git a/clang-tools-extra/clang-tidy/modernize/UseIntegerSignComparisonCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseIntegerSignComparisonCheck.cpp index 574cbea46124b..a09b1434e6149 100644 --- a/clang-tools-extra/clang-tidy/modernize/UseIntegerSignComparisonCheck.cpp +++ b/clang-tools-extra/clang-tidy/modernize/UseIntegerSignComparisonCheck.cpp @@ -76,15 +76,11 @@ static StringRef parseOpCode(BinaryOperator::Opcode Code) { UseIntegerSignComparisonCheck::UseIntegerSignComparisonCheck( StringRef Name, ClangTidyContext *Context) - : ClangTidyCheck(Name, Context), - IncludeInserter(Options.getLocalOrGlobal("IncludeStyle", - utils::IncludeSorter::IS_LLVM), - areDiagsSelfContained()), + : ClangTidyCheck(Name, Context), IncludeInserter(areDiagsSelfContained()), EnableQtSupport(Options.get("EnableQtSupport", false)) {} void UseIntegerSignComparisonCheck::storeOptions( ClangTidyOptions::OptionMap &Opts) { - Options.store(Opts, "IncludeStyle", IncludeInserter.getStyle()); Options.store(Opts, "EnableQtSupport", EnableQtSupport); } diff --git a/clang-tools-extra/clang-tidy/modernize/UseStdFormatCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseStdFormatCheck.cpp index 101780ad0b186..8d0619b4472ae 100644 --- a/clang-tools-extra/clang-tidy/modernize/UseStdFormatCheck.cpp +++ b/clang-tools-extra/clang-tidy/modernize/UseStdFormatCheck.cpp @@ -28,9 +28,7 @@ UseStdFormatCheck::UseStdFormatCheck(StringRef Name, ClangTidyContext *Context) Options.get("StrFormatLikeFunctions", ""))), ReplacementFormatFunction( Options.get("ReplacementFormatFunction", "std::format")), - IncludeInserter(Options.getLocalOrGlobal("IncludeStyle", - utils::IncludeSorter::IS_LLVM), - areDiagsSelfContained()), + IncludeInserter(areDiagsSelfContained()), MaybeHeaderToInclude(Options.get("FormatHeader")) { if (StrFormatLikeFunctions.empty()) StrFormatLikeFunctions.emplace_back("absl::StrFormat"); @@ -63,7 +61,6 @@ void UseStdFormatCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) { Options.store(Opts, "StrFormatLikeFunctions", serializeStringList(StrFormatLikeFunctions)); Options.store(Opts, "ReplacementFormatFunction", ReplacementFormatFunction); - Options.store(Opts, "IncludeStyle", IncludeInserter.getStyle()); if (MaybeHeaderToInclude) Options.store(Opts, "FormatHeader", *MaybeHeaderToInclude); } diff --git a/clang-tools-extra/clang-tidy/modernize/UseStdNumbersCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseStdNumbersCheck.cpp index 2b84dcbe4eab8..8a70e690c4b7a 100644 --- a/clang-tools-extra/clang-tidy/modernize/UseStdNumbersCheck.cpp +++ b/clang-tools-extra/clang-tidy/modernize/UseStdNumbersCheck.cpp @@ -286,10 +286,7 @@ static bool isRangeOfCompleteMacro(const clang::SourceRange &Range, namespace clang::tidy::modernize { UseStdNumbersCheck::UseStdNumbersCheck(const StringRef Name, ClangTidyContext *const Context) - : ClangTidyCheck(Name, Context), - IncludeInserter(Options.getLocalOrGlobal("IncludeStyle", - utils::IncludeSorter::IS_LLVM), - areDiagsSelfContained()), + : ClangTidyCheck(Name, Context), IncludeInserter(areDiagsSelfContained()), DiffThresholdString{Options.get("DiffThreshold", "0.001")} { if (DiffThresholdString.getAsDouble(DiffThreshold)) { configurationDiag( @@ -434,7 +431,6 @@ void UseStdNumbersCheck::registerPPCallbacks( } void UseStdNumbersCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) { - Options.store(Opts, "IncludeStyle", IncludeInserter.getStyle()); Options.store(Opts, "DiffThreshold", DiffThresholdString); } } // namespace clang::tidy::modernize diff --git a/clang-tools-extra/clang-tidy/modernize/UseStdPrintCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseStdPrintCheck.cpp index e92155c822dc7..f6ca37bd38a21 100644 --- a/clang-tools-extra/clang-tidy/modernize/UseStdPrintCheck.cpp +++ b/clang-tools-extra/clang-tidy/modernize/UseStdPrintCheck.cpp @@ -32,9 +32,7 @@ UseStdPrintCheck::UseStdPrintCheck(StringRef Name, ClangTidyContext *Context) Options.get("ReplacementPrintFunction", "std::print")), ReplacementPrintlnFunction( Options.get("ReplacementPrintlnFunction", "std::println")), - IncludeInserter(Options.getLocalOrGlobal("IncludeStyle", - utils::IncludeSorter::IS_LLVM), - areDiagsSelfContained()), + IncludeInserter(areDiagsSelfContained()), MaybeHeaderToInclude(Options.get("PrintHeader")) { if (PrintfLikeFunctions.empty() && FprintfLikeFunctions.empty()) { PrintfLikeFunctions.emplace_back("::printf"); @@ -57,7 +55,6 @@ void UseStdPrintCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) { serializeStringList(FprintfLikeFunctions)); Options.store(Opts, "ReplacementPrintFunction", ReplacementPrintFunction); Options.store(Opts, "ReplacementPrintlnFunction", ReplacementPrintlnFunction); - Options.store(Opts, "IncludeStyle", IncludeInserter.getStyle()); if (MaybeHeaderToInclude) Options.store(Opts, "PrintHeader", *MaybeHeaderToInclude); } diff --git a/clang-tools-extra/clang-tidy/performance/TypePromotionInMathFnCheck.cpp b/clang-tools-extra/clang-tidy/performance/TypePromotionInMathFnCheck.cpp index 9825cf254c97c..4cd4c47d7fa1a 100644 --- a/clang-tools-extra/clang-tidy/performance/TypePromotionInMathFnCheck.cpp +++ b/clang-tools-extra/clang-tidy/performance/TypePromotionInMathFnCheck.cpp @@ -27,21 +27,13 @@ AST_MATCHER_P(Type, isBuiltinType, BuiltinType::Kind, Kind) { TypePromotionInMathFnCheck::TypePromotionInMathFnCheck( StringRef Name, ClangTidyContext *Context) - : ClangTidyCheck(Name, Context), - IncludeInserter(Options.getLocalOrGlobal("IncludeStyle", - utils::IncludeSorter::IS_LLVM), - areDiagsSelfContained()) {} + : ClangTidyCheck(Name, Context), IncludeInserter(areDiagsSelfContained()) {} void TypePromotionInMathFnCheck::registerPPCallbacks( const SourceManager &SM, Preprocessor *PP, Preprocessor *ModuleExpanderPP) { IncludeInserter.registerPreprocessor(PP); } -void TypePromotionInMathFnCheck::storeOptions( - ClangTidyOptions::OptionMap &Opts) { - Options.store(Opts, "IncludeStyle", IncludeInserter.getStyle()); -} - void TypePromotionInMathFnCheck::registerMatchers(MatchFinder *Finder) { constexpr BuiltinType::Kind IntTy = BuiltinType::Int; constexpr BuiltinType::Kind LongTy = BuiltinType::Long; diff --git a/clang-tools-extra/clang-tidy/performance/TypePromotionInMathFnCheck.h b/clang-tools-extra/clang-tidy/performance/TypePromotionInMathFnCheck.h index 21a7f4d040cd8..6e12378b343e4 100644 --- a/clang-tools-extra/clang-tidy/performance/TypePromotionInMathFnCheck.h +++ b/clang-tools-extra/clang-tidy/performance/TypePromotionInMathFnCheck.h @@ -29,7 +29,6 @@ class TypePromotionInMathFnCheck : public ClangTidyCheck { void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP, Preprocessor *ModuleExpanderPP) override; - void storeOptions(ClangTidyOptions::OptionMap &Opts) override; void registerMatchers(ast_matchers::MatchFinder *Finder) override; void check(const ast_matchers::MatchFinder::MatchResult &Result) override; diff --git a/clang-tools-extra/clang-tidy/performance/UnnecessaryValueParamCheck.cpp b/clang-tools-extra/clang-tidy/performance/UnnecessaryValueParamCheck.cpp index ffb2a81b862f6..3eca209e36daf 100644 --- a/clang-tools-extra/clang-tidy/performance/UnnecessaryValueParamCheck.cpp +++ b/clang-tools-extra/clang-tidy/performance/UnnecessaryValueParamCheck.cpp @@ -41,10 +41,7 @@ static bool hasLoopStmtAncestor(const DeclRefExpr &DeclRef, const Decl &Decl, UnnecessaryValueParamCheck::UnnecessaryValueParamCheck( StringRef Name, ClangTidyContext *Context) - : ClangTidyCheck(Name, Context), - Inserter(Options.getLocalOrGlobal("IncludeStyle", - utils::IncludeSorter::IS_LLVM), - areDiagsSelfContained()), + : ClangTidyCheck(Name, Context), Inserter(areDiagsSelfContained()), AllowedTypes( utils::options::parseStringList(Options.get("AllowedTypes", ""))), IgnoreCoroutines(Options.get("IgnoreCoroutines", true)) {} @@ -119,7 +116,6 @@ void UnnecessaryValueParamCheck::registerPPCallbacks( void UnnecessaryValueParamCheck::storeOptions( ClangTidyOptions::OptionMap &Opts) { - Options.store(Opts, "IncludeStyle", Inserter.getStyle()); Options.store(Opts, "AllowedTypes", utils::options::serializeStringList(AllowedTypes)); Options.store(Opts, "IgnoreCoroutines", IgnoreCoroutines); diff --git a/clang-tools-extra/clang-tidy/readability/UseStdMinMaxCheck.cpp b/clang-tools-extra/clang-tidy/readability/UseStdMinMaxCheck.cpp index 6255bbd9e5778..86db5e4744f57 100644 --- a/clang-tools-extra/clang-tidy/readability/UseStdMinMaxCheck.cpp +++ b/clang-tools-extra/clang-tidy/readability/UseStdMinMaxCheck.cpp @@ -120,14 +120,7 @@ createReplacement(const Expr *CondLhs, const Expr *CondRhs, } UseStdMinMaxCheck::UseStdMinMaxCheck(StringRef Name, ClangTidyContext *Context) - : ClangTidyCheck(Name, Context), - IncludeInserter(Options.getLocalOrGlobal("IncludeStyle", - utils::IncludeSorter::IS_LLVM), - areDiagsSelfContained()) {} - -void UseStdMinMaxCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) { - Options.store(Opts, "IncludeStyle", IncludeInserter.getStyle()); -} + : ClangTidyCheck(Name, Context), IncludeInserter(areDiagsSelfContained()) {} void UseStdMinMaxCheck::registerMatchers(MatchFinder *Finder) { auto AssignOperator = diff --git a/clang-tools-extra/clang-tidy/readability/UseStdMinMaxCheck.h b/clang-tools-extra/clang-tidy/readability/UseStdMinMaxCheck.h index e983412d6b7ba..6796db99420af 100644 --- a/clang-tools-extra/clang-tidy/readability/UseStdMinMaxCheck.h +++ b/clang-tools-extra/clang-tidy/readability/UseStdMinMaxCheck.h @@ -26,7 +26,6 @@ class UseStdMinMaxCheck : public ClangTidyCheck { } void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP, Preprocessor *ModuleExpanderPP) override; - void storeOptions(ClangTidyOptions::OptionMap &Opts) override; void registerMatchers(ast_matchers::MatchFinder *Finder) override; void check(const ast_matchers::MatchFinder::MatchResult &Result) override; std::optional<TraversalKind> getCheckTraversalKind() const override { diff --git a/clang-tools-extra/clang-tidy/utils/CMakeLists.txt b/clang-tools-extra/clang-tidy/utils/CMakeLists.txt index b83a1e9a77182..4b234351db71b 100644 --- a/clang-tools-extra/clang-tidy/utils/CMakeLists.txt +++ b/clang-tools-extra/clang-tidy/utils/CMakeLists.txt @@ -17,7 +17,6 @@ add_clang_library(clangTidyUtils STATIC FixItHintUtils.cpp HeaderGuard.cpp IncludeInserter.cpp - IncludeSorter.cpp LexerUtils.cpp Matchers.cpp NamespaceAliaser.cpp diff --git a/clang-tools-extra/clang-tidy/utils/IncludeInserter.cpp b/clang-tools-extra/clang-tidy/utils/IncludeInserter.cpp index 81bb8dec57a74..44e3756484b41 100644 --- a/clang-tools-extra/clang-tidy/utils/IncludeInserter.cpp +++ b/clang-tools-extra/clang-tidy/utils/IncludeInserter.cpp @@ -18,68 +18,67 @@ class IncludeInserterCallback : public PPCallbacks { public: explicit IncludeInserterCallback(IncludeInserter *Inserter) : Inserter(Inserter) {} + // Implements PPCallbacks::InclusionDirective(). Records the names and source // locations of the inclusions in the main source file being processed. void InclusionDirective(SourceLocation HashLocation, - const Token &IncludeToken, StringRef FileNameRef, + const Token &IncludeToken, StringRef FileName, bool IsAngled, CharSourceRange FileNameRange, OptionalFileEntryRef /*IncludedFile*/, StringRef /*SearchPath*/, StringRef /*RelativePath*/, const Module * /*SuggestedModule*/, bool /*ModuleImported*/, SrcMgr::CharacteristicKind /*FileType*/) override { - Inserter->addInclude(FileNameRef, IsAngled, HashLocation, - IncludeToken.getEndLoc()); + const FileID FileID = Inserter->SourceMgr->getFileID(HashLocation); + auto &[InsertionLoc, AlreadyPresentHeaders] = Inserter->InsertInfos[FileID]; + AlreadyPresentHeaders.try_emplace(FileName); + if (InsertionLoc.isInvalid()) + InsertionLoc = HashLocation; } private: IncludeInserter *Inserter; }; -IncludeInserter::IncludeInserter(IncludeSorter::IncludeStyle Style, - bool SelfContainedDiags) - : Style(Style), SelfContainedDiags(SelfContainedDiags) {} +IncludeInserter::IncludeInserter(bool SelfContainedDiags) + : SelfContainedDiags(SelfContainedDiags) {} void IncludeInserter::registerPreprocessor(Preprocessor *PP) { assert(PP && "PP shouldn't be null"); SourceMgr = &PP->getSourceManager(); - // If this gets registered multiple times, clear the maps - if (!IncludeSorterByFile.empty()) - IncludeSorterByFile.clear(); - if (!InsertedHeaders.empty()) - InsertedHeaders.clear(); + // If this gets registered multiple times, clear the map. + InsertInfos.clear(); PP->addPPCallbacks(std::make_unique<IncludeInserterCallback>(this)); } -IncludeSorter &IncludeInserter::getOrCreate(FileID FileID) { - assert(SourceMgr && "SourceMgr shouldn't be null; did you remember to call " - "registerPreprocessor()?"); - // std::unique_ptr is cheap to construct, so force a construction now to save - // the lookup needed if we were to insert into the map. - std::unique_ptr<IncludeSorter> &Entry = IncludeSorterByFile[FileID]; - if (!Entry) { - // If it wasn't found, Entry will be default constructed to nullptr. - Entry = std::make_unique<IncludeSorter>( - SourceMgr, FileID, - SourceMgr->getFilename(SourceMgr->getLocForStartOfFile(FileID)), Style); - } - return *Entry; -} - std::optional<FixItHint> IncludeInserter::createIncludeInsertion(FileID FileID, llvm::StringRef Header) { const bool IsAngled = Header.consume_front("<"); if (IsAngled != Header.consume_back(">")) return std::nullopt; + + auto &[InsertionLoc, AlreadyPresentHeaders] = InsertInfos[FileID]; + // We assume the same Header will never be included both angled and not // angled. // In self contained diags mode we don't track what headers we have already // inserted. - if (!SelfContainedDiags && !InsertedHeaders[FileID].insert(Header).second) + if (!SelfContainedDiags && !AlreadyPresentHeaders.try_emplace(Header).second) return std::nullopt; - return getOrCreate(FileID).createIncludeInsertion(Header, IsAngled); + std::string IncludeStmt = IsAngled + ? Twine("#include <" + Header + ">\n").str() + : Twine("#include \"" + Header + "\"\n").str(); + + // If there are no includes in this file, add it in the first line. + // FIXME: insert after the file comment or the header guard, if present. + if (InsertionLoc.isInvalid()) { + InsertionLoc = SourceMgr->getLocForStartOfFile(FileID); + IncludeStmt += '\n'; + } + + return FixItHint::CreateInsertion(InsertionLoc, IncludeStmt); } std::optional<FixItHint> @@ -89,13 +88,4 @@ IncludeInserter::createMainFileIncludeInsertion(StringRef Header) { return createIncludeInsertion(SourceMgr->getMainFileID(), Header); } -void IncludeInserter::addInclude(StringRef FileName, bool IsAngled, - SourceLocation HashLocation, - SourceLocation EndLocation) { - assert(SourceMgr && "SourceMgr shouldn't be null; did you remember to call " - "registerPreprocessor()?"); - const FileID FileID = SourceMgr->getFileID(HashLocation); - getOrCreate(FileID).addInclude(FileName, IsAngled, HashLocation, EndLocation); -} - } // namespace clang::tidy::utils diff --git a/clang-tools-extra/clang-tidy/utils/IncludeInserter.h b/clang-tools-extra/clang-tidy/utils/IncludeInserter.h index 9dbf2a76369cd..40caf02c90dbc 100644 --- a/clang-tools-extra/clang-tidy/utils/IncludeInserter.h +++ b/clang-tools-extra/clang-tidy/utils/IncludeInserter.h @@ -9,10 +9,8 @@ #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_INCLUDEINSERTER_H #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_INCLUDEINSERTER_H -#include "IncludeSorter.h" #include "clang/Basic/Diagnostic.h" #include "llvm/ADT/StringSet.h" -#include <memory> #include <optional> namespace clang { @@ -27,8 +25,7 @@ namespace tidy::utils { /// #include "../ClangTidyCheck.h" /// #include "../utils/IncludeInserter.h" /// -/// namespace clang { -/// namespace tidy { +/// namespace clang::tidy { /// /// class MyCheck : public ClangTidyCheck { /// public: @@ -47,20 +44,13 @@ namespace tidy::utils { /// } /// /// private: -/// utils::IncludeInserter Inserter{utils::IncludeSorter::IS_Google}; +/// utils::IncludeInserter Inserter; /// }; -/// } // namespace tidy -/// } // namespace clang +/// } // namespace clang::tidy /// \endcode class IncludeInserter { public: - /// Initializes the IncludeInserter using the IncludeStyle \p Style. - /// In most cases the \p Style will be retrieved from the ClangTidyOptions - /// using \code - /// Options.getLocalOrGlobal("IncludeStyle", <DefaultStyle>) - /// \endcode - explicit IncludeInserter(IncludeSorter::IncludeStyle Style, - bool SelfContainedDiags); + explicit IncludeInserter(bool SelfContainedDiags); /// Registers this with the Preprocessor \p PP, must be called before this /// class is used. @@ -82,22 +72,20 @@ class IncludeInserter { std::optional<FixItHint> createMainFileIncludeInsertion(llvm::StringRef Header); - IncludeSorter::IncludeStyle getStyle() const { return Style; } - private: - void addInclude(StringRef FileName, bool IsAngled, - SourceLocation HashLocation, SourceLocation EndLocation); - - IncludeSorter &getOrCreate(FileID FileID); + struct InsertInfo { + SourceLocation InsertionLoc; + llvm::StringSet<> AlreadyPresentHeaders; + }; - llvm::DenseMap<FileID, std::unique_ptr<IncludeSorter>> IncludeSorterByFile; - llvm::DenseMap<FileID, llvm::StringSet<>> InsertedHeaders; - const SourceManager *SourceMgr{nullptr}; - const IncludeSorter::IncludeStyle Style; + FileID CurrentFileID; + llvm::DenseMap<FileID, InsertInfo> InsertInfos; + const SourceManager *SourceMgr = nullptr; const bool SelfContainedDiags; friend class IncludeInserterCallback; }; } // namespace tidy::utils } // namespace clang + #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_INCLUDEINSERTER_H diff --git a/clang-tools-extra/clang-tidy/utils/IncludeSorter.cpp b/clang-tools-extra/clang-tidy/utils/IncludeSorter.cpp deleted file mode 100644 index 0ab517d5d9bd4..0000000000000 --- a/clang-tools-extra/clang-tidy/utils/IncludeSorter.cpp +++ /dev/null @@ -1,228 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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 -// -//===----------------------------------------------------------------------===// - -#include "IncludeSorter.h" -#include "clang/Basic/SourceManager.h" -#include "clang/Lex/Lexer.h" -#include <algorithm> -#include <optional> - -namespace clang::tidy { -namespace utils { - -static StringRef removeFirstSuffix(StringRef Str, - ArrayRef<const char *> Suffixes) { - for (const StringRef Suffix : Suffixes) - if (Str.consume_back(Suffix)) - return Str; - return Str; -} - -static StringRef makeCanonicalName(StringRef Str, - IncludeSorter::IncludeStyle Style) { - // The list of suffixes to remove from source file names to get the - // "canonical" file names. - // E.g. tools/sort_includes.cc and tools/sort_includes_test.cc - // would both canonicalize to tools/sort_includes and tools/sort_includes.h - // (once canonicalized) will match as being the main include file associated - // with the source files. - if (Style == IncludeSorter::IS_LLVM) { - return removeFirstSuffix( - removeFirstSuffix(Str, {".cc", ".cpp", ".c", ".h", ".hpp"}), {"Test"}); - } - if (Style == IncludeSorter::IS_Google_ObjC) { - const StringRef Canonical = - removeFirstSuffix(removeFirstSuffix(Str, {".cc", ".cpp", ".c", ".h", - ".hpp", ".mm", ".m"}), - {"_unittest", "_regtest", "_test", "Test"}); - - // Objective-C categories have a `+suffix` format, but should be grouped - // with the file they are a category of. - size_t StartIndex = Canonical.find_last_of('/'); - if (StartIndex == StringRef::npos) - StartIndex = 0; - return Canonical.substr(0, Canonical.find_first_of('+', StartIndex)); - } - return removeFirstSuffix( - removeFirstSuffix(Str, {".cc", ".cpp", ".c", ".h", ".hpp"}), - {"_unittest", "_regtest", "_test"}); -} - -// Scan to the end of the line and return the offset of the next line. -static size_t findNextLine(const char *Text) { - const size_t EOLIndex = std::strcspn(Text, "\n"); - return Text[EOLIndex] == '\0' ? EOLIndex : EOLIndex + 1; -} - -static IncludeSorter::IncludeKinds -determineIncludeKind(StringRef CanonicalFile, StringRef IncludeFile, - bool IsAngled, IncludeSorter::IncludeStyle Style) { - // Compute the two "canonical" forms of the include's filename sans extension. - // The first form is the include's filename without ".h" or "-inl.h" at the - // end. The second form is the first form with "/public/" in the file path - // replaced by "/internal/". - if (IsAngled) { - // If the system include (<foo>) ends with ".h", then it is a normal C-style - // include. Otherwise assume it is a C++-style extensionless include. - return IncludeFile.ends_with(".h") ? IncludeSorter::IK_CSystemInclude - : IncludeSorter::IK_CXXSystemInclude; - } - const StringRef CanonicalInclude = makeCanonicalName(IncludeFile, Style); - if (CanonicalFile.ends_with(CanonicalInclude) || - CanonicalInclude.ends_with(CanonicalFile)) { - return IncludeSorter::IK_MainTUInclude; - } - if ((Style == IncludeSorter::IS_Google) || - (Style == IncludeSorter::IS_Google_ObjC)) { - const std::pair<StringRef, StringRef> Parts = - CanonicalInclude.split("/public/"); - StringRef FileCopy = CanonicalFile; - if (FileCopy.consume_front(Parts.first) && - FileCopy.consume_back(Parts.second)) { - // Determine the kind of this inclusion. - if (FileCopy == "/internal/" || FileCopy == "/proto/") - return IncludeSorter::IK_MainTUInclude; - } - } - if (Style == IncludeSorter::IS_Google_ObjC) { - if (IncludeFile.ends_with(".generated.h") || - IncludeFile.ends_with(".proto.h") || - IncludeFile.ends_with(".pbobjc.h")) { - return IncludeSorter::IK_GeneratedInclude; - } - } - return IncludeSorter::IK_NonSystemInclude; -} - -static int compareHeaders(StringRef LHS, StringRef RHS, - IncludeSorter::IncludeStyle Style) { - if (Style == IncludeSorter::IncludeStyle::IS_Google_ObjC) { - const std::pair<const char *, const char *> &Mismatch = - llvm::mismatch(LHS, RHS); - if ((Mismatch.first != LHS.end()) && (Mismatch.second != RHS.end())) { - if ((*Mismatch.first == '.') && (*Mismatch.second == '+')) - return -1; - if ((*Mismatch.first == '+') && (*Mismatch.second == '.')) - return 1; - } - } - return LHS.compare(RHS); -} - -IncludeSorter::IncludeSorter(const SourceManager *SourceMgr, FileID FileID, - StringRef FileName, IncludeStyle Style) - : SourceMgr(SourceMgr), Style(Style), CurrentFileID(FileID), - CanonicalFile(makeCanonicalName(FileName, Style)) {} - -void IncludeSorter::addInclude(StringRef FileName, bool IsAngled, - SourceLocation HashLocation, - SourceLocation EndLocation) { - const int Offset = findNextLine(SourceMgr->getCharacterData(EndLocation)); - - // Record the relevant location information for this inclusion directive. - auto &IncludeLocation = IncludeLocations[FileName]; - IncludeLocation.push_back( - SourceRange(HashLocation, EndLocation.getLocWithOffset(Offset))); - SourceLocations.push_back(IncludeLocation.back()); - - // Stop if this inclusion is a duplicate. - if (IncludeLocation.size() > 1) - return; - - // Add the included file's name to the appropriate bucket. - const IncludeKinds Kind = - determineIncludeKind(CanonicalFile, FileName, IsAngled, Style); - if (Kind != IK_InvalidInclude) - IncludeBucket[Kind].push_back(FileName.str()); -} - -std::optional<FixItHint> -IncludeSorter::createIncludeInsertion(StringRef FileName, bool IsAngled) { - std::string IncludeStmt; - if (Style == IncludeStyle::IS_Google_ObjC) { - IncludeStmt = IsAngled - ? llvm::Twine("#import <" + FileName + ">\n").str() - : llvm::Twine("#import \"" + FileName + "\"\n").str(); - } else { - IncludeStmt = IsAngled - ? llvm::Twine("#include <" + FileName + ">\n").str() - : llvm::Twine("#include \"" + FileName + "\"\n").str(); - } - if (SourceLocations.empty()) { - // If there are no includes in this file, add it in the first line. - // FIXME: insert after the file comment or the header guard, if present. - IncludeStmt.append("\n"); - return FixItHint::CreateInsertion( - SourceMgr->getLocForStartOfFile(CurrentFileID), IncludeStmt); - } - - auto IncludeKind = - determineIncludeKind(CanonicalFile, FileName, IsAngled, Style); - - if (!IncludeBucket[IncludeKind].empty()) { - for (const std::string &IncludeEntry : IncludeBucket[IncludeKind]) { - if (compareHeaders(FileName, IncludeEntry, Style) < 0) { - const auto &Location = IncludeLocations[IncludeEntry][0]; - return FixItHint::CreateInsertion(Location.getBegin(), IncludeStmt); - } - if (FileName == IncludeEntry) - return std::nullopt; - } - // FileName comes after all include entries in bucket, insert it after - // last. - const std::string &LastInclude = IncludeBucket[IncludeKind].back(); - const SourceRange LastIncludeLocation = - IncludeLocations[LastInclude].back(); - return FixItHint::CreateInsertion(LastIncludeLocation.getEnd(), - IncludeStmt); - } - // Find the non-empty include bucket to be sorted directly above - // 'IncludeKind'. If such a bucket exists, we'll want to sort the include - // after that bucket. If no such bucket exists, find the first non-empty - // include bucket in the file. In that case, we'll want to sort the include - // before that bucket. - IncludeKinds NonEmptyKind = IK_InvalidInclude; - for (int I = IK_InvalidInclude - 1; I >= 0; --I) { - if (!IncludeBucket[I].empty()) { - NonEmptyKind = static_cast<IncludeKinds>(I); - if (NonEmptyKind < IncludeKind) - break; - } - } - if (NonEmptyKind == IK_InvalidInclude) - return std::nullopt; - - if (NonEmptyKind < IncludeKind) { - // Create a block after. - const std::string &LastInclude = IncludeBucket[NonEmptyKind].back(); - const SourceRange LastIncludeLocation = - IncludeLocations[LastInclude].back(); - IncludeStmt = '\n' + IncludeStmt; - return FixItHint::CreateInsertion(LastIncludeLocation.getEnd(), - IncludeStmt); - } - // Create a block before. - const std::string &FirstInclude = IncludeBucket[NonEmptyKind][0]; - const SourceRange FirstIncludeLocation = - IncludeLocations[FirstInclude].back(); - IncludeStmt.append("\n"); - return FixItHint::CreateInsertion(FirstIncludeLocation.getBegin(), - IncludeStmt); -} - -} // namespace utils - -llvm::ArrayRef<std::pair<utils::IncludeSorter::IncludeStyle, StringRef>> -OptionEnumMapping<utils::IncludeSorter::IncludeStyle>::getEnumMapping() { - static constexpr std::pair<utils::IncludeSorter::IncludeStyle, StringRef> - Mapping[] = {{utils::IncludeSorter::IS_LLVM, "llvm"}, - {utils::IncludeSorter::IS_Google, "google"}, - {utils::IncludeSorter::IS_Google_ObjC, "google-objc"}}; - return {Mapping}; -} -} // namespace clang::tidy diff --git a/clang-tools-extra/clang-tidy/utils/IncludeSorter.h b/clang-tools-extra/clang-tidy/utils/IncludeSorter.h deleted file mode 100644 index 6efec976847b5..0000000000000 --- a/clang-tools-extra/clang-tidy/utils/IncludeSorter.h +++ /dev/null @@ -1,76 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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_TOOLS_EXTRA_CLANG_TIDY_UTILS_INCLUDESORTER_H -#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_INCLUDESORTER_H - -#include "../ClangTidyCheck.h" -#include <optional> -#include <string> - -namespace clang::tidy { -namespace utils { - -/// Class used by ``IncludeInserterCallback`` to record the names of the -/// inclusions in a given source file being processed and generate the necessary -/// commands to sort the inclusions according to the precedence encoded in -/// ``IncludeKinds``. -class IncludeSorter { -public: - /// Supported include styles. - enum IncludeStyle { IS_LLVM = 0, IS_Google = 1, IS_Google_ObjC = 2 }; - - /// The classifications of inclusions, in the order they should be sorted. - enum IncludeKinds { - IK_MainTUInclude = 0, ///< e.g. ``#include "foo.h"`` when editing foo.cc - IK_CSystemInclude = 1, ///< e.g. ``#include <stdio.h>`` - IK_CXXSystemInclude = 2, ///< e.g. ``#include <vector>`` - IK_NonSystemInclude = 3, ///< e.g. ``#include "bar.h"`` - IK_GeneratedInclude = 4, ///< e.g. ``#include "bar.proto.h"`` - IK_InvalidInclude = 5 ///< total number of valid ``IncludeKind``s - }; - - /// ``IncludeSorter`` constructor; takes the FileID and name of the file to be - /// processed by the sorter. - IncludeSorter(const SourceManager *SourceMgr, FileID FileID, - StringRef FileName, IncludeStyle Style); - - /// Adds the given include directive to the sorter. - void addInclude(StringRef FileName, bool IsAngled, - SourceLocation HashLocation, SourceLocation EndLocation); - - /// Creates a quoted inclusion directive in the right sort order. Returns - /// std::nullopt on error or if header inclusion directive for header already - /// exists. - std::optional<FixItHint> createIncludeInsertion(StringRef FileName, - bool IsAngled); - -private: - using SourceRangeVector = SmallVector<SourceRange, 1>; - - const SourceManager *SourceMgr; - const IncludeStyle Style; - FileID CurrentFileID; - /// The file name stripped of common suffixes. - StringRef CanonicalFile; - /// Locations of visited include directives. - SourceRangeVector SourceLocations; - /// Mapping from file name to #include locations. - llvm::StringMap<SourceRangeVector> IncludeLocations; - /// Includes sorted into buckets. - SmallVector<std::string, 1> IncludeBucket[IK_InvalidInclude]; -}; - -} // namespace utils - -template <> struct OptionEnumMapping<utils::IncludeSorter::IncludeStyle> { - static ArrayRef<std::pair<utils::IncludeSorter::IncludeStyle, StringRef>> - getEnumMapping(); -}; -} // namespace clang::tidy -#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_INCLUDESORTER_H diff --git a/clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.cpp b/clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.cpp index 6fa623022ee9c..98427f28f44d7 100644 --- a/clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.cpp +++ b/clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.cpp @@ -55,9 +55,7 @@ static std::string escapeForDiagnostic(std::string ToEscape) { TransformerClangTidyCheck::TransformerClangTidyCheck(StringRef Name, ClangTidyContext *Context) - : ClangTidyCheck(Name, Context), - Inserter(Options.getLocalOrGlobal("IncludeStyle", IncludeSorter::IS_LLVM), - areDiagsSelfContained()) {} + : ClangTidyCheck(Name, Context), Inserter(areDiagsSelfContained()) {} // This constructor cannot dispatch to the simpler one (below), because, in // order to get meaningful results from `getLangOpts` and `Options`, we need the @@ -149,9 +147,4 @@ void TransformerClangTidyCheck::check( } } -void TransformerClangTidyCheck::storeOptions( - ClangTidyOptions::OptionMap &Opts) { - Options.store(Opts, "IncludeStyle", Inserter.getStyle()); -} - } // namespace clang::tidy::utils diff --git a/clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.h b/clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.h index da8606f993b6e..40b0ee0a65033 100644 --- a/clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.h +++ b/clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.h @@ -11,7 +11,6 @@ #include "../ClangTidyCheck.h" #include "IncludeInserter.h" -#include "IncludeSorter.h" #include "clang/ASTMatchers/ASTMatchFinder.h" #include "clang/Tooling/Transformer/Transformer.h" #include <optional> @@ -66,7 +65,7 @@ class TransformerClangTidyCheck : public ClangTidyCheck { /// Derived classes that override this function should call this method from /// the overridden method. - void storeOptions(ClangTidyOptions::OptionMap &Opts) override; + void storeOptions(ClangTidyOptions::OptionMap &Opts) override {} /// Set the rule that this check implements. All cases in the rule must have /// a non-null \c Explanation, even though \c Explanation is optional for diff --git a/clang-tools-extra/clang-tidy/utils/UseRangesCheck.cpp b/clang-tools-extra/clang-tidy/utils/UseRangesCheck.cpp index 004e61526b778..9fb6ee6e1074a 100644 --- a/clang-tools-extra/clang-tidy/utils/UseRangesCheck.cpp +++ b/clang-tools-extra/clang-tidy/utils/UseRangesCheck.cpp @@ -282,20 +282,13 @@ bool UseRangesCheck::isLanguageVersionSupported( } UseRangesCheck::UseRangesCheck(StringRef Name, ClangTidyContext *Context) - : ClangTidyCheck(Name, Context), - Inserter(Options.getLocalOrGlobal("IncludeStyle", - utils::IncludeSorter::IS_LLVM), - areDiagsSelfContained()) {} + : ClangTidyCheck(Name, Context), Inserter(areDiagsSelfContained()) {} void UseRangesCheck::registerPPCallbacks(const SourceManager &, Preprocessor *PP, Preprocessor *) { Inserter.registerPreprocessor(PP); } -void UseRangesCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) { - Options.store(Opts, "IncludeStyle", Inserter.getStyle()); -} - std::optional<std::string> UseRangesCheck::Replacer::getHeaderInclusion(const NamedDecl &) const { return std::nullopt; diff --git a/clang-tools-extra/clang-tidy/utils/UseRangesCheck.h b/clang-tools-extra/clang-tidy/utils/UseRangesCheck.h index b85a157ba2873..9eb93bba0fe09 100644 --- a/clang-tools-extra/clang-tidy/utils/UseRangesCheck.h +++ b/clang-tools-extra/clang-tidy/utils/UseRangesCheck.h @@ -81,7 +81,6 @@ class UseRangesCheck : public ClangTidyCheck { void registerMatchers(ast_matchers::MatchFinder *Finder) final; void check(const ast_matchers::MatchFinder::MatchResult &Result) final; bool isLanguageVersionSupported(const LangOptions &LangOpts) const override; - void storeOptions(ClangTidyOptions::OptionMap &Opts) override; std::optional<TraversalKind> getCheckTraversalKind() const override; private: diff --git a/clang-tools-extra/docs/clang-tidy/checks/abseil/string-find-startswith.rst b/clang-tools-extra/docs/clang-tidy/checks/abseil/string-find-startswith.rst index 41a7ab500d7ce..bddff89708454 100644 --- a/clang-tools-extra/docs/clang-tidy/checks/abseil/string-find-startswith.rst +++ b/clang-tools-extra/docs/clang-tidy/checks/abseil/string-find-startswith.rst @@ -37,11 +37,6 @@ Options ``std::basic_string`` and ``std::basic_string_view`` are considered. The list of methods to be considered is fixed. -.. option:: IncludeStyle - - A string specifying which include-style is used, `llvm` or `google`. Default - is `llvm`. - .. option:: AbseilStringsMatchHeader The location of Abseil's ``strings/match.h``. Defaults to diff --git a/clang-tools-extra/docs/clang-tidy/checks/abseil/string-find-str-contains.rst b/clang-tools-extra/docs/clang-tidy/checks/abseil/string-find-str-contains.rst index 418df193d6e0d..129301e24b3a2 100644 --- a/clang-tools-extra/docs/clang-tidy/checks/abseil/string-find-str-contains.rst +++ b/clang-tools-extra/docs/clang-tidy/checks/abseil/string-find-str-contains.rst @@ -41,11 +41,6 @@ Options ``::std::basic_string``, ``::std::basic_string_view``, and ``::absl::string_view``. -.. option:: IncludeStyle - - A string specifying which include-style is used, `llvm` or `google`. Default - is `llvm`. - .. option:: AbseilStringsMatchHeader The location of Abseil's ``strings/match.h``. Defaults to diff --git a/clang-tools-extra/docs/clang-tidy/checks/boost/use-ranges.rst b/clang-tools-extra/docs/clang-tidy/checks/boost/use-ranges.rst index 6cf54347ad613..3c560770043ea 100644 --- a/clang-tools-extra/docs/clang-tidy/checks/boost/use-ranges.rst +++ b/clang-tools-extra/docs/clang-tidy/checks/boost/use-ranges.rst @@ -160,11 +160,6 @@ Transforms to: Options ------- -.. option:: IncludeStyle - - A string specifying which include-style is used, `llvm` or `google`. Default - is `llvm`. - .. option:: IncludeBoostSystem If `true` (default value) the boost headers are included as system headers diff --git a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/init-variables.rst b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/init-variables.rst index e8ca8238887c5..1582ba67274dc 100644 --- a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/init-variables.rst +++ b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/init-variables.rst @@ -60,11 +60,6 @@ It warns for the uninitialized enum case, but without a FixIt: Options ------- -.. option:: IncludeStyle - - A string specifying which include-style is used, `llvm` or `google`. Default - is `llvm`. - .. option:: MathHeader A string specifying the header to include to get the definition of `NAN`. diff --git a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/pro-bounds-constant-array-index.rst b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/pro-bounds-constant-array-index.rst index 4eddeb489a1db..c830608c829f0 100644 --- a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/pro-bounds-constant-array-index.rst +++ b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/pro-bounds-constant-array-index.rst @@ -22,8 +22,3 @@ Options The check can generate fixes after this option has been set to the name of the include file that contains ``gsl::at()``, e.g. `"gsl/gsl.h"`. Default is an empty string. - -.. option:: IncludeStyle - - A string specifying which include-style is used, `llvm` or `google`. Default - is `llvm`. diff --git a/clang-tools-extra/docs/clang-tidy/checks/misc/uniqueptr-reset-release.rst b/clang-tools-extra/docs/clang-tidy/checks/misc/uniqueptr-reset-release.rst index 8d48fa192e69f..858fbe78fdfaa 100644 --- a/clang-tools-extra/docs/clang-tidy/checks/misc/uniqueptr-reset-release.rst +++ b/clang-tools-extra/docs/clang-tidy/checks/misc/uniqueptr-reset-release.rst @@ -14,11 +14,3 @@ Example: If ``y`` is already rvalue, ``std::move()`` is not added. ``x`` and ``y`` can also be ``std::unique_ptr<Foo>*``. - -Options -------- - -.. option:: IncludeStyle - - A string specifying which include-style is used, `llvm` or `google`. Default - is `llvm`. diff --git a/clang-tools-extra/docs/clang-tidy/checks/modernize/loop-convert.rst b/clang-tools-extra/docs/clang-tidy/checks/modernize/loop-convert.rst index 87790db99f4c7..24b76ab7ab934 100644 --- a/clang-tools-extra/docs/clang-tidy/checks/modernize/loop-convert.rst +++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/loop-convert.rst @@ -171,11 +171,6 @@ Options system include. Default value is an empty string. -.. option:: IncludeStyle - - A string specifying which include-style is used, `llvm` or `google`. Default - is `llvm`. - Limitations ----------- diff --git a/clang-tools-extra/docs/clang-tidy/checks/modernize/make-shared.rst b/clang-tools-extra/docs/clang-tidy/checks/modernize/make-shared.rst index cd953e7ee394d..af2dcb80501f2 100644 --- a/clang-tools-extra/docs/clang-tidy/checks/modernize/make-shared.rst +++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/make-shared.rst @@ -39,11 +39,6 @@ Options A string specifying the corresponding header of make-shared-ptr function. Default is `<memory>`. -.. option:: IncludeStyle - - A string specifying which include-style is used, `llvm` or `google`. Default - is `llvm`. - .. option:: IgnoreMacros If set to `true`, the check will not give warnings inside macros. Default diff --git a/clang-tools-extra/docs/clang-tidy/checks/modernize/make-unique.rst b/clang-tools-extra/docs/clang-tidy/checks/modernize/make-unique.rst index 1aaa8701cd0f1..cbd6d3ae8f48c 100644 --- a/clang-tools-extra/docs/clang-tidy/checks/modernize/make-unique.rst +++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/make-unique.rst @@ -39,11 +39,6 @@ Options A string specifying the corresponding header of make-unique-ptr function. Default is `<memory>`. -.. option:: IncludeStyle - - A string specifying which include-style is used, `llvm` or `google`. Default - is `llvm`. - .. option:: IgnoreMacros If set to `true`, the check will not give warnings inside macros. Default diff --git a/clang-tools-extra/docs/clang-tidy/checks/modernize/min-max-use-initializer-list.rst b/clang-tools-extra/docs/clang-tidy/checks/modernize/min-max-use-initializer-list.rst index 157c447ee4d98..6e7d5bdb695a1 100644 --- a/clang-tools-extra/docs/clang-tidy/checks/modernize/min-max-use-initializer-list.rst +++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/min-max-use-initializer-list.rst @@ -35,11 +35,6 @@ non-trivial types: Options ======= -.. option:: IncludeStyle - - A string specifying which include-style is used, `llvm` or `google`. Default - is `llvm`. - .. option:: IgnoreNonTrivialTypes A boolean specifying whether to ignore non-trivial types. Default is `true`. diff --git a/clang-tools-extra/docs/clang-tidy/checks/modernize/pass-by-value.rst b/clang-tools-extra/docs/clang-tidy/checks/modernize/pass-by-value.rst index 0f5758dc097e6..4a09523dc8190 100644 --- a/clang-tools-extra/docs/clang-tidy/checks/modernize/pass-by-value.rst +++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/pass-by-value.rst @@ -155,11 +155,6 @@ Example: Options ------- -.. option:: IncludeStyle - - A string specifying which include-style is used, `llvm` or `google`. Default - is `llvm`. - .. option:: ValuesOnly When `true`, the check only warns about copied parameters that are already diff --git a/clang-tools-extra/docs/clang-tidy/checks/modernize/replace-auto-ptr.rst b/clang-tools-extra/docs/clang-tidy/checks/modernize/replace-auto-ptr.rst index 8a8c30e6c15a3..dc3e31d3ae8a1 100644 --- a/clang-tools-extra/docs/clang-tidy/checks/modernize/replace-auto-ptr.rst +++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/replace-auto-ptr.rst @@ -71,11 +71,3 @@ Limitations } // only 'f<int>()' (or similar) will trigger the replacement. - -Options -------- - -.. option:: IncludeStyle - - A string specifying which include-style is used, `llvm` or `google`. Default - is `llvm`. diff --git a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-integer-sign-comparison.rst b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-integer-sign-comparison.rst index 903e791499f92..d04c6850d7800 100644 --- a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-integer-sign-comparison.rst +++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-integer-sign-comparison.rst @@ -30,11 +30,6 @@ becomes Options ------- -.. option:: IncludeStyle - - A string specifying which include-style is used, `llvm` or `google`. - Default is `llvm`. - .. option:: EnableQtSupport Makes C++17 ``q20::cmp_*`` alternative available for Qt-based diff --git a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-ranges.rst b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-ranges.rst index eb90debb3804b..ea7ca0ac05abe 100644 --- a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-ranges.rst +++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-ranges.rst @@ -128,11 +128,6 @@ Transforms to: Options ------- -.. option:: IncludeStyle - - A string specifying which include-style is used, `llvm` or `google`. Default - is `llvm`. - .. option:: UseReversePipe When `true` (default `false`), fixes which involve reverse ranges will use the diff --git a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-std-numbers.rst b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-std-numbers.rst index 207e9c00e74ba..13e5fedfc648f 100644 --- a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-std-numbers.rst +++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-std-numbers.rst @@ -67,8 +67,3 @@ Options match a constant. A literal matches a constant if ``abs(literal - constant) < DiffThreshold`` evaluates to ``true``. Default is `0.001`. - -.. option:: IncludeStyle - - A string specifying which include-style is used, `llvm` or `google`. Default - is `llvm`. diff --git a/clang-tools-extra/docs/clang-tidy/checks/performance/unnecessary-value-param.rst b/clang-tools-extra/docs/clang-tidy/checks/performance/unnecessary-value-param.rst index cd25d7d94d99b..d5e57ed6e4a81 100644 --- a/clang-tools-extra/docs/clang-tidy/checks/performance/unnecessary-value-param.rst +++ b/clang-tools-extra/docs/clang-tidy/checks/performance/unnecessary-value-param.rst @@ -61,11 +61,6 @@ depends on function signatures. Options ------- -.. option:: IncludeStyle - - A string specifying which include-style is used, `llvm` or `google`. Default - is `llvm`. - .. option:: AllowedTypes A semicolon-separated list of names of types allowed to be passed by value. diff --git a/clang-tools-extra/test/clang-tidy/infrastructure/dump-config-invalid.cpp b/clang-tools-extra/test/clang-tidy/infrastructure/dump-config-invalid.cpp index 4737b49bffe44..b3d7a8d7cf200 100644 --- a/clang-tools-extra/test/clang-tidy/infrastructure/dump-config-invalid.cpp +++ b/clang-tools-extra/test/clang-tidy/infrastructure/dump-config-invalid.cpp @@ -1,6 +1,6 @@ -// RUN: clang-tidy --checks="-*,modernize-make-shared" \ +// RUN: clang-tidy --checks="-*,modernize-loop-convert" \ // RUN: --config="CheckOptions: { \ -// RUN: modernize-make-shared.IncludeStyle: '0' }" \ +// RUN: modernize-loop-convert.NamingStyle: '0' }" \ // RUN: --dump-config -- | FileCheck %s -// CHECK: modernize-make-shared.IncludeStyle: llvm +// CHECK: modernize-loop-convert.NamingStyle: CamelCase diff --git a/clang-tools-extra/unittests/clang-tidy/IncludeInserterTest.cpp b/clang-tools-extra/unittests/clang-tidy/IncludeInserterTest.cpp index d01ba9814b8a1..9a8974f79ab0e 100644 --- a/clang-tools-extra/unittests/clang-tidy/IncludeInserterTest.cpp +++ b/clang-tools-extra/unittests/clang-tidy/IncludeInserterTest.cpp @@ -20,7 +20,7 @@ // to native paths; thus, the virtual file is not found. // This needs to be fixed in the FileManager before we can make // clang-tidy tests work. -#if !defined(_WIN32) +#if 0 // Temporary hack namespace clang { namespace tidy { diff --git a/llvm/utils/gn/secondary/clang-tools-extra/clang-tidy/utils/BUILD.gn b/llvm/utils/gn/secondary/clang-tools-extra/clang-tidy/utils/BUILD.gn index 379424d0f4780..863ff78b640ae 100644 --- a/llvm/utils/gn/secondary/clang-tools-extra/clang-tidy/utils/BUILD.gn +++ b/llvm/utils/gn/secondary/clang-tools-extra/clang-tidy/utils/BUILD.gn @@ -24,7 +24,6 @@ static_library("utils") { "FormatStringConverter.cpp", "HeaderGuard.cpp", "IncludeInserter.cpp", - "IncludeSorter.cpp", "LexerUtils.cpp", "Matchers.cpp", "NamespaceAliaser.cpp", >From b434f29239a67e37b0e83f03a5be9e3b8a43ed0d Mon Sep 17 00:00:00 2001 From: Victor Chernyakin <[email protected]> Date: Wed, 11 Mar 2026 06:52:49 -0700 Subject: [PATCH 2/2] Add TODO release note --- clang-tools-extra/docs/ReleaseNotes.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index 6995e02247861..f386a9730aee0 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -49,6 +49,8 @@ Major New Features Potentially Breaking Changes ---------------------------- +- TODO: removed `IncludeStyle` option. + Improvements to clangd ---------------------- _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
