[PATCH] D156024: [clang-tidy] Add --disable-modular-headers-expansion option
Piotr Zegar via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sat Jul 22 04:49:52 PDT 2023
PiotrZSL created this revision.
Herald added subscribers: carlosgalvezp, xazax.hun.
Herald added a reviewer: njames93.
Herald added a project: All.
PiotrZSL requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.
Experimental option: Disable modular header expansion
in C++20 and above. This option serves as a workaround
for addressing known issues #50087 and #62447.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D156024
Files:
clang-tools-extra/clang-tidy/ClangTidy.cpp
clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h
clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
Index: clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
===================================================================
--- clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
+++ clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
@@ -263,6 +263,16 @@
cl::init(false), cl::Hidden,
cl::cat(ClangTidyCategory));
+static cl::opt<bool>
+ DisableModularHeadersExpansion("disable-modular-headers-expansion", desc(R"(
+Experimental option: Disable modular header
+expansion in C++20 and above. This option
+serves as a workaround for addressing known
+issues #50087 and #62447.
+)"),
+ cl::init(false), cl::Hidden,
+ cl::cat(ClangTidyCategory));
+
static cl::opt<std::string> ExportFixes("export-fixes", desc(R"(
YAML file to store suggested fixes in. The
stored fixes can be applied to the input source
@@ -659,7 +669,8 @@
llvm::InitializeAllAsmParsers();
ClangTidyContext Context(std::move(OwningOptionsProvider),
- AllowEnablingAnalyzerAlphaCheckers);
+ AllowEnablingAnalyzerAlphaCheckers,
+ DisableModularHeadersExpansion);
std::vector<ClangTidyError> Errors =
runClangTidy(Context, OptionsParser->getCompilations(), PathList, BaseFS,
FixNotes, EnableCheckProfile, ProfilePrefix);
Index: clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h
===================================================================
--- clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h
+++ clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h
@@ -70,7 +70,8 @@
public:
/// Initializes \c ClangTidyContext instance.
ClangTidyContext(std::unique_ptr<ClangTidyOptionsProvider> OptionsProvider,
- bool AllowEnablingAnalyzerAlphaCheckers = false);
+ bool AllowEnablingAnalyzerAlphaCheckers = false,
+ bool DisableModularHeadersExpansion = 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.
@@ -198,6 +199,10 @@
return AllowEnablingAnalyzerAlphaCheckers;
}
+ bool canEnableModularHeadersExpansion() const {
+ return !DisableModularHeadersExpansion;
+ }
+
void setSelfContainedDiags(bool Value) { SelfContainedDiags = Value; }
bool areDiagsSelfContained() const { return SelfContainedDiags; }
@@ -245,6 +250,7 @@
std::string ProfilePrefix;
bool AllowEnablingAnalyzerAlphaCheckers;
+ bool DisableModularHeadersExpansion;
bool SelfContainedDiags;
Index: clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
===================================================================
--- clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
+++ clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
@@ -161,10 +161,12 @@
ClangTidyContext::ClangTidyContext(
std::unique_ptr<ClangTidyOptionsProvider> OptionsProvider,
- bool AllowEnablingAnalyzerAlphaCheckers)
+ bool AllowEnablingAnalyzerAlphaCheckers,
+ bool DisableModularHeadersExpansion)
: DiagEngine(nullptr), OptionsProvider(std::move(OptionsProvider)),
Profile(false),
AllowEnablingAnalyzerAlphaCheckers(AllowEnablingAnalyzerAlphaCheckers),
+ DisableModularHeadersExpansion(DisableModularHeadersExpansion),
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.
Index: clang-tools-extra/clang-tidy/ClangTidy.cpp
===================================================================
--- clang-tools-extra/clang-tidy/ClangTidy.cpp
+++ clang-tools-extra/clang-tidy/ClangTidy.cpp
@@ -418,7 +418,7 @@
Preprocessor *PP = &Compiler.getPreprocessor();
Preprocessor *ModuleExpanderPP = PP;
- if (Context.getLangOpts().Modules && OverlayFS != nullptr) {
+ if (Context.canEnableModularHeadersExpansion() && Context.getLangOpts().Modules && OverlayFS != nullptr) {
auto ModuleExpander = std::make_unique<ExpandModularHeadersPPCallbacks>(
&Compiler, OverlayFS);
ModuleExpanderPP = ModuleExpander->getPreprocessor();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D156024.543172.patch
Type: text/x-patch
Size: 4435 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230722/7f81b5d4/attachment.bin>
More information about the cfe-commits
mailing list