Author: Ian Anderson Date: 2023-10-20T13:23:34-07:00 New Revision: 09ec0004eee2d9929d25cf519956cc470ffb33dd
URL: https://github.com/llvm/llvm-project/commit/09ec0004eee2d9929d25cf519956cc470ffb33dd DIFF: https://github.com/llvm/llvm-project/commit/09ec0004eee2d9929d25cf519956cc470ffb33dd.diff LOG: [Modules] textual headers in submodules never resolve their `use`s (#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. Added: clang/test/Modules/no-undeclared-includes.c Modified: clang/lib/Lex/ModuleMap.cpp Removed: ################################################################################ diff --git a/clang/lib/Lex/ModuleMap.cpp b/clang/lib/Lex/ModuleMap.cpp index 7fd92bff8048429..eb7cab54386c480 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/no-undeclared-includes.c b/clang/test/Modules/no-undeclared-includes.c new file mode 100644 index 000000000000000..83a654f6ed77539 --- /dev/null +++ b/clang/test/Modules/no-undeclared-includes.c @@ -0,0 +1,31 @@ +// RUN: rm -rf %t +// RUN: split-file %s %t +// RUN: %clang_cc1 -fmodules-cache-path=%t -fmodules -fimplicit-module-maps -I %t %t/no-undeclared-includes.c -verify + +//--- no-undeclared-includes.c +// expected-no-diagnostics +#include <assert.h> + +//--- assert.h +#include <base.h> + +//--- base.h +#ifndef base_h +#define base_h + + + +#endif /* base_h */ + +//--- module.modulemap +module cstd [system] [no_undeclared_includes] { + use base + module assert { + textual header "assert.h" + } +} + +module base [system] { + header "base.h" + export * +} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits