aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVolodymyr Sapsai <vsapsai@apple.com>2020-07-23 12:47:16 -0700
committerVolodymyr Sapsai <vsapsai@apple.com>2020-08-25 16:31:27 -0700
commit8839e278ffcadc62b333423de07756488cae980f (patch)
treecfdb775198f1343299604b8ea0486f9ad07cb0e5
parent1e13372bc808eb72ca4b96285b9ba9a987a39965 (diff)
downloadllvm-8839e278ffcadc62b333423de07756488cae980f.zip
llvm-8839e278ffcadc62b333423de07756488cae980f.tar.gz
llvm-8839e278ffcadc62b333423de07756488cae980f.tar.bz2
[Modules] Improve error message when cannot find parent module for submodule definition.
Before the change the diagnostic for module unknown.submodule {} was "error: expected module name" which is incorrect and misleading because both "unknown" and "submodule" are valid module names. We already have a better error message when a parent module is a submodule itself and is missing. Make the error for a missing top-level module more like the one for a submodule. rdar://problem/64424407 Reviewed By: bruno Differential Revision: https://reviews.llvm.org/D84458
-rw-r--r--clang/include/clang/Basic/DiagnosticLexKinds.td3
-rw-r--r--clang/lib/Lex/ModuleMap.cpp16
-rw-r--r--clang/test/Modules/diagnostics.modulemap6
3 files changed, 16 insertions, 9 deletions
diff --git a/clang/include/clang/Basic/DiagnosticLexKinds.td b/clang/include/clang/Basic/DiagnosticLexKinds.td
index 9cb06cf..77d2e26 100644
--- a/clang/include/clang/Basic/DiagnosticLexKinds.td
+++ b/clang/include/clang/Basic/DiagnosticLexKinds.td
@@ -695,6 +695,9 @@ def err_mmap_missing_module_unqualified : Error<
"no module named '%0' visible from '%1'">;
def err_mmap_missing_module_qualified : Error<
"no module named '%0' in '%1'">;
+def err_mmap_missing_parent_module: Error<
+ "no module named '%0' %select{found|in '%2'}1, "
+ "parent module must be defined before the submodule">;
def err_mmap_top_level_inferred_submodule : Error<
"only submodules and framework modules may be inferred with wildcard syntax">;
def err_mmap_inferred_no_umbrella : Error<
diff --git a/clang/lib/Lex/ModuleMap.cpp b/clang/lib/Lex/ModuleMap.cpp
index bcdc5b8..12da5a8 100644
--- a/clang/lib/Lex/ModuleMap.cpp
+++ b/clang/lib/Lex/ModuleMap.cpp
@@ -1903,18 +1903,16 @@ void ModuleMapParser::parseModuleDecl() {
continue;
}
- if (ActiveModule) {
- Diags.Report(Id[I].second, diag::err_mmap_missing_module_qualified)
- << Id[I].first
- << ActiveModule->getTopLevelModule()->getFullModuleName();
- } else {
- Diags.Report(Id[I].second, diag::err_mmap_expected_module_name);
- }
+ Diags.Report(Id[I].second, diag::err_mmap_missing_parent_module)
+ << Id[I].first << (ActiveModule != nullptr)
+ << (ActiveModule
+ ? ActiveModule->getTopLevelModule()->getFullModuleName()
+ : "");
HadError = true;
- return;
}
- if (ModuleMapFile != Map.getContainingModuleMapFile(TopLevelModule)) {
+ if (TopLevelModule &&
+ ModuleMapFile != Map.getContainingModuleMapFile(TopLevelModule)) {
assert(ModuleMapFile != Map.getModuleMapFileForUniquing(TopLevelModule) &&
"submodule defined in same file as 'module *' that allowed its "
"top-level module");
diff --git a/clang/test/Modules/diagnostics.modulemap b/clang/test/Modules/diagnostics.modulemap
index 01aa0b6..c12fef5 100644
--- a/clang/test/Modules/diagnostics.modulemap
+++ b/clang/test/Modules/diagnostics.modulemap
@@ -28,3 +28,9 @@ module header_attr {
header "quux.h" { size 1 mtime 2 }
header "no_attrs.h" {}
}
+
+// CHECK: diagnostics.modulemap:[[@LINE+1]]:8: error: no module named 'unknown' found, parent module must be defined before the submodule
+module unknown.submodule {}
+module known_top_level {}
+// CHECK: diagnostics.modulemap:[[@LINE+1]]:24: error: no module named 'unknown' in 'known_top_level', parent module must be defined before the submodule
+module known_top_level.unknown.submodule {}