Skip to content

Commit be01456

Browse files
committed
[clang][modules][deps] Parse "FW_Private" module map even after loading "FW" PCM
When Clang loads a PCM that depends on another PCM describing framework module "FW", `ModuleMap` registers "FW" as known, without seeing the module map that defines it (or the adjacent "FW_Private" module map). Later, when looking at a header from "FW_Private", `ModuleMap` returns early due to having knowledge about "FW" and never associates that header with "FW_Private", leading to it being treated as textual. This behavior is caused by D150292, where the scanner stops calling `HeaderSearch::lookupModule()` eagerly for every loaded PCM. This patch skips an early check when trying to figure out the framework module for a header, which ensures the "FW" and (most importantly) "FW_Private" module maps can be parsed even after loading "FW" from a PCM. Note that the `HeaderSearch::loadModuleMapFile()` function we not call unconditionally has caching behavior of its own, meaning it will avoid parsing module map file repeatedly. Depends on D150320. Reviewed By: benlangmuir Differential Revision: https://reviews.llvm.org/D150478
1 parent 227f719 commit be01456

File tree

3 files changed

+28
-4
lines changed

3 files changed

+28
-4
lines changed

clang/include/clang/Driver/Options.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2588,6 +2588,10 @@ defm modules_search_all : BoolFOption<"modules-search-all",
25882588
defm implicit_modules : BoolFOption<"implicit-modules",
25892589
LangOpts<"ImplicitModules">, DefaultTrue,
25902590
NegFlag<SetFalse, [CC1Option]>, PosFlag<SetTrue>, BothFlags<[NoXarchOption,CoreOption]>>;
2591+
def fno_modules_check_relocated : Joined<["-"], "fno-modules-check-relocated">,
2592+
Group<f_Group>, Flags<[CC1Option]>,
2593+
HelpText<"Skip checks for relocated modules when loading PCM files">,
2594+
MarshallingInfoNegativeFlag<PreprocessorOpts<"ModulesCheckRelocated">>;
25912595
def fretain_comments_from_system_headers : Flag<["-"], "fretain-comments-from-system-headers">, Group<f_Group>, Flags<[CC1Option]>,
25922596
MarshallingInfoFlag<LangOpts<"RetainCommentsFromSystemHeaders">>;
25932597
def fmodule_header : Flag <["-"], "fmodule-header">, Group<f_Group>,

clang/lib/Lex/HeaderSearch.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1783,9 +1783,6 @@ HeaderSearch::lookupModuleMapFile(DirectoryEntryRef Dir, bool IsFramework) {
17831783

17841784
Module *HeaderSearch::loadFrameworkModule(StringRef Name, DirectoryEntryRef Dir,
17851785
bool IsSystem) {
1786-
if (Module *Module = ModMap.findModule(Name))
1787-
return Module;
1788-
17891786
// Try to load a module map file.
17901787
switch (loadModuleMapFile(Dir, IsSystem, /*IsFramework*/true)) {
17911788
case LMM_InvalidModuleMap:
@@ -1794,10 +1791,10 @@ Module *HeaderSearch::loadFrameworkModule(StringRef Name, DirectoryEntryRef Dir,
17941791
ModMap.inferFrameworkModule(Dir, IsSystem, /*Parent=*/nullptr);
17951792
break;
17961793

1797-
case LMM_AlreadyLoaded:
17981794
case LMM_NoDirectory:
17991795
return nullptr;
18001796

1797+
case LMM_AlreadyLoaded:
18011798
case LMM_NewlyLoaded:
18021799
break;
18031800
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// RUN: rm -rf %t
2+
// RUN: split-file %s %t
3+
4+
//--- frameworks1/FW1.framework/Modules/module.modulemap
5+
framework module FW1 { header "FW1.h" }
6+
//--- frameworks1/FW1.framework/Headers/FW1.h
7+
#import <FW2/FW2.h>
8+
9+
//--- frameworks2/FW2.framework/Modules/module.modulemap
10+
framework module FW2 { header "FW2.h" }
11+
//--- frameworks2/FW2.framework/Modules/module.private.modulemap
12+
framework module FW2_Private { header "FW2_Private.h" }
13+
//--- frameworks2/FW2.framework/Headers/FW2.h
14+
//--- frameworks2/FW2.framework/PrivateHeaders/FW2_Private.h
15+
16+
//--- tu.c
17+
#import <FW1/FW1.h> // expected-remark{{importing module 'FW1'}} \
18+
// expected-remark{{importing module 'FW2'}}
19+
#import <FW2/FW2_Private.h> // expected-remark{{importing module 'FW2_Private'}}
20+
21+
// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t/cache -fimplicit-module-maps \
22+
// RUN: -F %t/frameworks1 -F %t/frameworks2 -fsyntax-only %t/tu.c \
23+
// RUN: -fno-modules-check-relocated -Rmodule-import -verify

0 commit comments

Comments
 (0)