[clang] [clang][modules] Diagnose headers owned by multiple modules (PR #188538)
Michael Spencer via cfe-commits
cfe-commits at lists.llvm.org
Thu Apr 9 13:59:56 PDT 2026
================
@@ -486,21 +487,24 @@ void ModuleMap::diagnoseHeaderInclusion(Module *RequestingModule,
bool RequestingModuleIsModuleInterface,
SourceLocation FilenameLoc,
StringRef Filename, FileEntryRef File) {
- // No errors for indirect modules. This may be a bit of a problem for modules
- // with no source files.
- if (getTopLevelOrNull(RequestingModule) != getTopLevelOrNull(SourceModule))
- return;
-
if (RequestingModule) {
resolveUses(RequestingModule, /*Complain=*/false);
resolveHeaderDirectives(RequestingModule, /*File=*/std::nullopt);
}
+ HeadersMap::iterator Known = findKnownHeader(File);
+
+ diagnoseDuplicateHeaderOwnership(FilenameLoc, Filename, File, Known);
----------------
Bigcheese wrote:
I tested this out and yes we can get duplicate diagnostics, but you also get diagnostics that would be otherwise hidden. I'm adding a test of a real case we have that requires this to be detected.
Note that this still only triggers one time per header per `CompilerInstance`.
https://github.com/llvm/llvm-project/pull/188538
More information about the cfe-commits
mailing list