Skip to content

Commit

Permalink
[Modules] textual headers in submodules never resolve their uses
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ian-twilightcoder committed Oct 19, 2023
1 parent d173ce4 commit 7b88bf3
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 6 deletions.
13 changes: 7 additions & 6 deletions clang/lib/Lex/ModuleMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
31 changes: 31 additions & 0 deletions clang/test/Modules/no-undeclared-includes.c
Original file line number Diff line number Diff line change
@@ -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 *
}

0 comments on commit 7b88bf3

Please sign in to comment.