aboutsummaryrefslogtreecommitdiff
path: root/clang
diff options
context:
space:
mode:
authorChuanqi Xu <yedeng.yd@linux.alibaba.com>2023-09-07 17:10:07 +0800
committerChuanqi Xu <yedeng.yd@linux.alibaba.com>2023-09-07 17:13:16 +0800
commit869111ccf2d3916bf24a31bdb367d7e567483ff0 (patch)
treeb58d9fcd080657ec57c3e774430b14be2aa00a3c /clang
parent31ded495271e5869d619da851a351c9f6f05b2d4 (diff)
downloadllvm-869111ccf2d3916bf24a31bdb367d7e567483ff0.zip
llvm-869111ccf2d3916bf24a31bdb367d7e567483ff0.tar.gz
llvm-869111ccf2d3916bf24a31bdb367d7e567483ff0.tar.bz2
[NFC] [C++20] [Modules] Refactor the warning to '-fmodule-file=<BMIPath>' for C++20 modules
Previous implementation of the warning to use `-fmodule-file=<BMIPath>` for C++20 Modules is not straightforward and it is problematic in case we read the BMIPath by writing tools based clang components. This patch refactors it with a simple and direct style.
Diffstat (limited to 'clang')
-rw-r--r--clang/include/clang/Basic/DiagnosticFrontendKinds.td5
-rw-r--r--clang/include/clang/Basic/DiagnosticSerializationKinds.td5
-rw-r--r--clang/include/clang/Frontend/CompilerInstance.h8
-rw-r--r--clang/include/clang/Serialization/ASTReader.h11
-rw-r--r--clang/lib/Frontend/CompilerInstance.cpp6
-rw-r--r--clang/lib/Frontend/FrontendAction.cpp10
-rw-r--r--clang/lib/Serialization/ASTReader.cpp15
7 files changed, 40 insertions, 20 deletions
diff --git a/clang/include/clang/Basic/DiagnosticFrontendKinds.td b/clang/include/clang/Basic/DiagnosticFrontendKinds.td
index c950a2d..715e0c0d 100644
--- a/clang/include/clang/Basic/DiagnosticFrontendKinds.td
+++ b/clang/include/clang/Basic/DiagnosticFrontendKinds.td
@@ -261,6 +261,11 @@ def err_test_module_file_extension_version : Error<
"test module file extension '%0' has different version (%1.%2) than expected "
"(%3.%4)">;
+def warn_eagerly_load_for_standard_cplusplus_modules : Warning<
+ "the form '-fmodule-file=<BMI-path>' is deprecated for standard C++ named modules;"
+ "consider to use '-fmodule-file=<module-name>=<BMI-path>' instead">,
+ InGroup<DiagGroup<"eager-load-cxx-named-modules">>;
+
def err_missing_vfs_overlay_file : Error<
"virtual filesystem overlay file '%0' not found">, DefaultFatal;
def err_invalid_vfs_overlay : Error<
diff --git a/clang/include/clang/Basic/DiagnosticSerializationKinds.td b/clang/include/clang/Basic/DiagnosticSerializationKinds.td
index 5197aa1..a1ae23a 100644
--- a/clang/include/clang/Basic/DiagnosticSerializationKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSerializationKinds.td
@@ -129,11 +129,6 @@ def warn_module_system_bit_conflict : Warning<
"as a non-system module; any difference in diagnostic options will be ignored">,
InGroup<ModuleConflict>;
-def warn_eagerly_load_for_standard_cplusplus_modules : Warning<
- "the form '-fmodule-file=<BMI-path>' is deprecated for standard C++ named modules;"
- "consider to use '-fmodule-file=<module-name>=<BMI-path>' instead">,
- InGroup<DiagGroup<"eager-load-cxx-named-modules">>;
-
def warn_reading_std_cxx_module_by_implicit_paths : Warning<
"it is deprecated to read module '%0' implicitly; it is going to be removed in clang 18; "
"consider to specify the dependencies explicitly">,
diff --git a/clang/include/clang/Frontend/CompilerInstance.h b/clang/include/clang/Frontend/CompilerInstance.h
index 1255d2c..d26a452 100644
--- a/clang/include/clang/Frontend/CompilerInstance.h
+++ b/clang/include/clang/Frontend/CompilerInstance.h
@@ -40,6 +40,11 @@ class TimerGroup;
namespace clang {
class ASTContext;
class ASTReader;
+
+namespace serialization {
+class ModuleFile;
+}
+
class CodeCompleteConsumer;
class DiagnosticsEngine;
class DiagnosticConsumer;
@@ -794,7 +799,8 @@ public:
void createASTReader();
- bool loadModuleFile(StringRef FileName);
+ bool loadModuleFile(StringRef FileName,
+ serialization::ModuleFile *&LoadedModuleFile);
private:
/// Find a module, potentially compiling it, before reading its AST. This is
diff --git a/clang/include/clang/Serialization/ASTReader.h b/clang/include/clang/Serialization/ASTReader.h
index 2d114fc..dc1eb21 100644
--- a/clang/include/clang/Serialization/ASTReader.h
+++ b/clang/include/clang/Serialization/ASTReader.h
@@ -1632,9 +1632,18 @@ public:
/// \param ClientLoadCapabilities The set of client load-failure
/// capabilities, represented as a bitset of the enumerators of
/// LoadFailureCapabilities.
+ ///
+ /// \param LoadedModuleFile The optional out-parameter refers to the new
+ /// loaded modules. In case the module specified by FileName is already
+ /// loaded, the module file pointer referred by NewLoadedModuleFile wouldn't
+ /// change. Otherwise if the AST file get loaded successfully,
+ /// NewLoadedModuleFile would refer to the address of the new loaded top level
+ /// module. The state of NewLoadedModuleFile is unspecified if the AST file
+ /// isn't loaded successfully.
ASTReadResult ReadAST(StringRef FileName, ModuleKind Type,
SourceLocation ImportLoc,
- unsigned ClientLoadCapabilities);
+ unsigned ClientLoadCapabilities,
+ ModuleFile **NewLoadedModuleFile = nullptr);
/// Make the entities in the given module and any of its (non-explicit)
/// submodules visible to name lookup.
diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp
index e500675..49c1d8e 100644
--- a/clang/lib/Frontend/CompilerInstance.cpp
+++ b/clang/lib/Frontend/CompilerInstance.cpp
@@ -1717,7 +1717,8 @@ void CompilerInstance::createASTReader() {
Listener->attachToASTReader(*TheASTReader);
}
-bool CompilerInstance::loadModuleFile(StringRef FileName) {
+bool CompilerInstance::loadModuleFile(
+ StringRef FileName, serialization::ModuleFile *&LoadedModuleFile) {
llvm::Timer Timer;
if (FrontendTimerGroup)
Timer.init("preloading." + FileName.str(), "Preloading " + FileName.str(),
@@ -1743,7 +1744,8 @@ bool CompilerInstance::loadModuleFile(StringRef FileName) {
// Try to load the module file.
switch (TheASTReader->ReadAST(
FileName, serialization::MK_ExplicitModule, SourceLocation(),
- ConfigMismatchIsRecoverable ? ASTReader::ARR_ConfigurationMismatch : 0)) {
+ ConfigMismatchIsRecoverable ? ASTReader::ARR_ConfigurationMismatch : 0,
+ &LoadedModuleFile)) {
case ASTReader::Success:
// We successfully loaded the module file; remember the set of provided
// modules so that we don't try to load implicit modules for them.
diff --git a/clang/lib/Frontend/FrontendAction.cpp b/clang/lib/Frontend/FrontendAction.cpp
index 2da25be..e016b94 100644
--- a/clang/lib/Frontend/FrontendAction.cpp
+++ b/clang/lib/Frontend/FrontendAction.cpp
@@ -1023,10 +1023,16 @@ bool FrontendAction::BeginSourceFile(CompilerInstance &CI,
}
// If we were asked to load any module files, do so now.
- for (const auto &ModuleFile : CI.getFrontendOpts().ModuleFiles)
- if (!CI.loadModuleFile(ModuleFile))
+ for (const auto &ModuleFile : CI.getFrontendOpts().ModuleFiles) {
+ serialization::ModuleFile *Loaded = nullptr;
+ if (!CI.loadModuleFile(ModuleFile, Loaded))
return false;
+ if (Loaded && Loaded->StandardCXXModule)
+ CI.getDiagnostics().Report(
+ diag::warn_eagerly_load_for_standard_cplusplus_modules);
+ }
+
// If there is a layout overrides file, attach an external AST source that
// provides the layouts from that file.
if (!CI.getFrontendOpts().OverrideRecordLayoutsFile.empty() &&
diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp
index faeea66..8ece979 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -4311,10 +4311,10 @@ static bool SkipCursorToBlock(BitstreamCursor &Cursor, unsigned BlockID) {
}
}
-ASTReader::ASTReadResult ASTReader::ReadAST(StringRef FileName,
- ModuleKind Type,
+ASTReader::ASTReadResult ASTReader::ReadAST(StringRef FileName, ModuleKind Type,
SourceLocation ImportLoc,
- unsigned ClientLoadCapabilities) {
+ unsigned ClientLoadCapabilities,
+ ModuleFile **NewLoadedModuleFile) {
llvm::TimeTraceScope scope("ReadAST", FileName);
llvm::SaveAndRestore SetCurImportLocRAII(CurrentImportLoc, ImportLoc);
@@ -4344,6 +4344,9 @@ ASTReader::ASTReadResult ASTReader::ReadAST(StringRef FileName,
return ReadResult;
}
+ if (NewLoadedModuleFile && !Loaded.empty())
+ *NewLoadedModuleFile = Loaded.back().Mod;
+
// Here comes stuff that we only do once the entire chain is loaded. Do *not*
// remove modules from this point. Various fields are updated during reading
// the AST block and removing the modules would result in dangling pointers.
@@ -5709,12 +5712,6 @@ llvm::Error ASTReader::ReadSubmoduleBlock(ModuleFile &F,
if (DeserializationListener)
DeserializationListener->ModuleRead(GlobalID, CurrentModule);
- // If we're loading a module before we initialize the sema, it implies
- // we're performing eagerly loading.
- if (!getSema() && CurrentModule->isModulePurview() &&
- !getContext().getLangOpts().isCompilingModule())
- Diag(clang::diag::warn_eagerly_load_for_standard_cplusplus_modules);
-
SubmodulesLoaded[GlobalIndex] = CurrentModule;
// Clear out data that will be replaced by what is in the module file.