This is an archive of the discontinued LLVM Phabricator instance.

[clang][deps] Report module map describing compiled module
ClosedPublic

Authored by jansvoboda11 on Sep 19 2022, 1:51 PM.

Details

Summary

This patch fixes compilation failure with explicit modules caused by scanner not reporting the module map describing the module whose implementation is being compiled.

Below is a breakdown of the attached test case. Note the VFS that makes frameworks "A" and "B" share the same header "shared/H.h".

In non-modular build, Clang skips the last import, since the "shared/H.h" header has already been included.

During scan (or implicit build), the compiler handles "tu.m" as follows:

  • @import B imports module "B", as expected,
  • #import <A/H.h> is resolved textually (due to -fmodule-name=A) to "shared/H.h" (due to the VFS remapping),
  • #import <B/H.h> is resolved to import module "A_Private", since the header "shared/H.h" is already known to be part of that module, and the import is skipped.

In the end, the only modular dependency of the TU is "B".

In explicit modular build without -fmodule-name=A, TU does depend on module "A_Private" properly, not just textually. Clang therefore builds & loads its PCM, and knows to ignore the last import, since "shared/H.h" is known to be part of "A_Private".

But with current scanner behavior and -fmodule-name=A present, the last import fails during explicit build. Clang doesn't know about "A_Private" (it's included textually) and tries to import "B_Private" instead, which it doesn't know about either (the scanner correctly didn't report it as dependency). This is fixed by reporting the module map describing "A" and matching the semantics of implicit build.

Diff Detail

Event Timeline

jansvoboda11 created this revision.Sep 19 2022, 1:51 PM
Herald added a project: Restricted Project. · View Herald TranscriptSep 19 2022, 1:51 PM
Herald added a subscriber: ributzka. · View Herald Transcript
jansvoboda11 requested review of this revision.Sep 19 2022, 1:51 PM
Herald added a project: Restricted Project. · View Herald TranscriptSep 19 2022, 1:51 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
benlangmuir added inline comments.Sep 19 2022, 4:45 PM
clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
194

I think this should move inside the if below for needsModules.

We are checking the result of getModuleMapFileForUniquing for nullptr in ModuleDepCollector.cpp -- should we be doing the same here? I find it hard to guess when it might be null, but there's no asserts that it won't be anywhere that I can find.

Implement suggestions

jansvoboda11 marked an inline comment as done.Sep 20 2022, 9:22 AM
This revision is now accepted and ready to land.Sep 21 2022, 1:18 PM
Herald added a project: Restricted Project. · View Herald TranscriptSep 22 2022, 12:06 PM
Herald added subscribers: Restricted Project, Enna1. · View Herald Transcript

Thanks for reporting this and sorry for the breakage. Should be fixed in 8df1f3bc19d7.

Thanks for reporting this and sorry for the breakage. Should be fixed in 8df1f3bc19d7.

thanks for the quick turnaround

clang/test/ClangScanDeps/modules-header-sharing.m