-
Notifications
You must be signed in to change notification settings - Fork 12.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Modules] textual headers in submodules never resolve their use
s
#69651
Conversation
Somewhat indirectly caused by https://reviews.llvm.org/D132779 |
@llvm/pr-subscribers-clang @llvm/pr-subscribers-clang-modules Author: Ian Anderson (ian-twilightcoder) ChangesWhen an include from a textual header is resolved, the textual header's submodule is used as the requesting module. The submodule's uses are resolved, but that doesn't work because only top level modules have uses, and only the top level module uses are used for checking uses in Module::directlyUses. ModuleMap::resolveUses to resolve the top level module instead of the submodule. Full diff: https://github.com/llvm/llvm-project/pull/69651.diff 5 Files Affected:
diff --git a/clang/lib/Lex/ModuleMap.cpp b/clang/lib/Lex/ModuleMap.cpp
index f65a5f145c04395..259c97796ae19f2 100644
--- a/clang/lib/Lex/ModuleMap.cpp
+++ b/clang/lib/Lex/ModuleMap.cpp
@@ -1398,16 +1398,17 @@ bool ModuleMap::resolveExports(Module *Mod, bool Complain) {
}
bool ModuleMap::resolveUses(Module *Mod, bool Complain) {
- auto Unresolved = std::move(Mod->UnresolvedDirectUses);
- Mod->UnresolvedDirectUses.clear();
+ auto *Top = Mod->getTopLevelModule();
+ auto Unresolved = std::move(Top->UnresolvedDirectUses);
+ Top->UnresolvedDirectUses.clear();
for (auto &UDU : Unresolved) {
- Module *DirectUse = resolveModuleId(UDU, Mod, Complain);
+ Module *DirectUse = resolveModuleId(UDU, Top, Complain);
if (DirectUse)
- Mod->DirectUses.push_back(DirectUse);
+ Top->DirectUses.push_back(DirectUse);
else
- Mod->UnresolvedDirectUses.push_back(UDU);
+ Top->UnresolvedDirectUses.push_back(UDU);
}
- return !Mod->UnresolvedDirectUses.empty();
+ return !Top->UnresolvedDirectUses.empty();
}
bool ModuleMap::resolveConflicts(Module *Mod, bool Complain) {
diff --git a/clang/test/Modules/Inputs/no-undeclared-includes/assert.h b/clang/test/Modules/Inputs/no-undeclared-includes/assert.h
new file mode 100644
index 000000000000000..6ca1ffb2ad7ea6e
--- /dev/null
+++ b/clang/test/Modules/Inputs/no-undeclared-includes/assert.h
@@ -0,0 +1 @@
+#include <base.h>
diff --git a/clang/test/Modules/Inputs/no-undeclared-includes/base.h b/clang/test/Modules/Inputs/no-undeclared-includes/base.h
new file mode 100644
index 000000000000000..e559063bef43311
--- /dev/null
+++ b/clang/test/Modules/Inputs/no-undeclared-includes/base.h
@@ -0,0 +1,6 @@
+#ifndef base_h
+#define base_h
+
+
+
+#endif /* base_h */
diff --git a/clang/test/Modules/Inputs/no-undeclared-includes/module.modulemap b/clang/test/Modules/Inputs/no-undeclared-includes/module.modulemap
new file mode 100644
index 000000000000000..23d04305b3becbd
--- /dev/null
+++ b/clang/test/Modules/Inputs/no-undeclared-includes/module.modulemap
@@ -0,0 +1,11 @@
+module cstd [system] [no_undeclared_includes] {
+ use base
+ module assert {
+ textual header "assert.h"
+ }
+}
+
+module base [system] {
+ header "base.h"
+ export *
+}
diff --git a/clang/test/Modules/no-undeclared-includes.c b/clang/test/Modules/no-undeclared-includes.c
new file mode 100644
index 000000000000000..613418ef0041328
--- /dev/null
+++ b/clang/test/Modules/no-undeclared-includes.c
@@ -0,0 +1,5 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -fmodules-cache-path=%t -fmodules -fimplicit-module-maps -I %S/Inputs/no-undeclared-includes %s -verify
+
+// expected-no-diagnostics
+#include <assert.h>
|
When an include from a textual header is resolved, the textual header's submodule is used as the requesting module. The submodule's uses are resolved, but that doesn't work because only top level modules have uses, and only the top level module uses are used for checking uses in Module::directlyUses. ModuleMap::resolveUses to resolve the top level module instead of the submodule.
1f6f902
to
7b88bf3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. The rest of clang reasons about this at the top level module, so so should this.
… never resolve their `use`s llvm#69651 rdar://117227965
…lvm#69651) When an include from a textual header is resolved, the textual header's submodule is used as the requesting module. The submodule's uses are resolved, but that doesn't work because only top level modules have uses, and only the top level module uses are used for checking uses in Module::directlyUses. ModuleMap::resolveUses to resolve the top level module instead of the submodule.
…lvm#69651) When an include from a textual header is resolved, the textual header's submodule is used as the requesting module. The submodule's uses are resolved, but that doesn't work because only top level modules have uses, and only the top level module uses are used for checking uses in Module::directlyUses. ModuleMap::resolveUses to resolve the top level module instead of the submodule.
When an include from a textual header is resolved, the textual header's submodule is used as the requesting module. The submodule's uses are resolved, but that doesn't work because only top level modules have uses, and only the top level module uses are used for checking uses in Module::directlyUses. ModuleMap::resolveUses to resolve the top level module instead of the submodule.