diff --git a/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h b/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h --- a/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h +++ b/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h @@ -71,7 +71,7 @@ /// Initializes \c ClangTidyContext instance. ClangTidyContext(std::unique_ptr OptionsProvider, bool AllowEnablingAnalyzerAlphaCheckers = false, - bool DisableModuleHeadersParsing = false); + bool EnableModuleHeadersParsing = false); /// Sets the DiagnosticsEngine that diag() will emit diagnostics to. // FIXME: this is required initialization, and should be a constructor param. // Fix the context -> diag engine -> consumer -> context initialization cycle. @@ -200,7 +200,7 @@ } bool canEnableModuleHeadersParsing() const { - return !DisableModuleHeadersParsing; + return EnableModuleHeadersParsing; } void setSelfContainedDiags(bool Value) { SelfContainedDiags = Value; } @@ -250,7 +250,7 @@ std::string ProfilePrefix; bool AllowEnablingAnalyzerAlphaCheckers; - bool DisableModuleHeadersParsing; + bool EnableModuleHeadersParsing; bool SelfContainedDiags; diff --git a/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp b/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp --- a/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp +++ b/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp @@ -161,11 +161,11 @@ ClangTidyContext::ClangTidyContext( std::unique_ptr OptionsProvider, - bool AllowEnablingAnalyzerAlphaCheckers, bool DisableModuleHeadersParsing) + bool AllowEnablingAnalyzerAlphaCheckers, bool EnableModuleHeadersParsing) : DiagEngine(nullptr), OptionsProvider(std::move(OptionsProvider)), Profile(false), AllowEnablingAnalyzerAlphaCheckers(AllowEnablingAnalyzerAlphaCheckers), - DisableModuleHeadersParsing(DisableModuleHeadersParsing), + EnableModuleHeadersParsing(EnableModuleHeadersParsing), 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. diff --git a/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp b/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp --- a/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp +++ b/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp @@ -264,9 +264,9 @@ cl::cat(ClangTidyCategory)); static cl::opt - DisableModuleHeadersParsing("experimental-disable-module-headers-parsing", - cl::init(false), cl::Hidden, - cl::cat(ClangTidyCategory)); + EnableModuleHeadersParsing("experimental-enable-module-headers-parsing", + cl::init(false), cl::Hidden, + cl::cat(ClangTidyCategory)); static cl::opt ExportFixes("export-fixes", desc(R"( YAML file to store suggested fixes in. The @@ -665,7 +665,7 @@ ClangTidyContext Context(std::move(OwningOptionsProvider), AllowEnablingAnalyzerAlphaCheckers, - DisableModuleHeadersParsing); + EnableModuleHeadersParsing); std::vector Errors = runClangTidy(Context, OptionsParser->getCompilations(), PathList, BaseFS, FixNotes, EnableCheckProfile, ProfilePrefix); diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -111,6 +111,20 @@ be promoted to errors. For custom error promotion, use `-Werror=` on the compiler command-line, irrespective of `Checks` (`--checks=`) settings. +- Preprocessor-level module header parsing is now disabled by default due to + the problems it caused in C++20 and above, leading to performance and code + parsing issues regardless of whether modules were used or not. This change + will impact only the following checks: + :doc:`modernize-replace-disallow-copy-and-assign-macro + `, + :doc:`bugprone-reserved-identifier + `, and + :doc:`readability-identifier-naming + `. Those checks will no + longer see macros defined in modules. Users can still enable this + functionality using the hidden command line option + `--experimental-enable-module-headers-parsing`. + New checks ^^^^^^^^^^ diff --git a/clang-tools-extra/test/clang-tidy/infrastructure/expand-modular-headers-ppcallbacks.cpp b/clang-tools-extra/test/clang-tidy/infrastructure/expand-modular-headers-ppcallbacks.cpp --- a/clang-tools-extra/test/clang-tidy/infrastructure/expand-modular-headers-ppcallbacks.cpp +++ b/clang-tools-extra/test/clang-tidy/infrastructure/expand-modular-headers-ppcallbacks.cpp @@ -5,7 +5,7 @@ // RUN: %check_clang_tidy -std=c++11 %s readability-identifier-naming %t/without-modules -- \ // RUN: -config="CheckOptions: [{ \ // RUN: key: readability-identifier-naming.MacroDefinitionCase, value: UPPER_CASE }]" \ -// RUN: -header-filter=.* \ +// RUN: -header-filter=.* --experimental-enable-module-headers-parsing \ // RUN: -- -I %t/ // // RUN: rm -rf %t @@ -14,7 +14,7 @@ // RUN: %check_clang_tidy -std=c++17 %s readability-identifier-naming %t/without-modules -- \ // RUN: -config="CheckOptions: [{ \ // RUN: key: readability-identifier-naming.MacroDefinitionCase, value: UPPER_CASE }]" \ -// RUN: -header-filter=.* \ +// RUN: -header-filter=.* --experimental-enable-module-headers-parsing \ // RUN: -- -I %t/ // // Run clang-tidy on a file with modular includes: @@ -25,7 +25,7 @@ // RUN: %check_clang_tidy -std=c++11 %s readability-identifier-naming %t/with-modules -- \ // RUN: -config="CheckOptions: [{ \ // RUN: key: readability-identifier-naming.MacroDefinitionCase, value: UPPER_CASE }]" \ -// RUN: -header-filter=.* \ +// RUN: -header-filter=.* --experimental-enable-module-headers-parsing \ // RUN: -- -I %t/ \ // RUN: -fmodules -fimplicit-modules -fno-implicit-module-maps \ // RUN: -fmodule-map-file=%t/module.modulemap \ @@ -37,7 +37,7 @@ // RUN: %check_clang_tidy -std=c++17 %s readability-identifier-naming %t/with-modules -- \ // RUN: -config="CheckOptions: [{ \ // RUN: key: readability-identifier-naming.MacroDefinitionCase, value: UPPER_CASE }]" \ -// RUN: -header-filter=.* \ +// RUN: -header-filter=.* --experimental-enable-module-headers-parsing \ // RUN: -- -I %t/ \ // RUN: -fmodules -fimplicit-modules -fno-implicit-module-maps \ // RUN: -fmodule-map-file=%t/module.modulemap \