Skip to content

Commit 5cff5c0

Browse files
benlangmuirakyrtzi
authored andcommitted
[clang][modules] Handle explicit modules when checking for .Private -> _Private
While we eventually want to remove the mapping from .Private to _Private modules, until we do, ensure that it behaves the same for explicit modules. rdar://107449872 Differential Revision: https://reviews.llvm.org/D147477 (cherry picked from commit 8ec36e6)
1 parent 4f89fbe commit 5cff5c0

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

clang/lib/Frontend/CompilerInstance.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2081,8 +2081,12 @@ CompilerInstance::loadModule(SourceLocation ImportLoc,
20812081
PrivateModule, PP->getIdentifierInfo(Module->Name)->getTokenID());
20822082
PrivPath.push_back(std::make_pair(&II, Path[0].second));
20832083

2084+
std::string FileName;
2085+
// If there is a modulemap module or prebuilt module, load it.
20842086
if (PP->getHeaderSearchInfo().lookupModule(PrivateModule, ImportLoc, true,
2085-
!IsInclusionDirective))
2087+
!IsInclusionDirective) ||
2088+
selectModuleSource(nullptr, PrivateModule, FileName, BuiltModules,
2089+
PP->getHeaderSearchInfo()) != MS_ModuleNotFound)
20862090
Sub = loadModule(ImportLoc, PrivPath, Visibility, IsInclusionDirective);
20872091
if (Sub) {
20882092
MapPrivateSubModToTopLevel = true;
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Checks that the use of .Private to refer to _Private modules works with an
2+
// explicit module.
3+
4+
// RUN: rm -rf %t
5+
// RUN: split-file %s %t
6+
7+
// RUN: %clang_cc1 -x objective-c -fmodules -fno-implicit-modules -emit-module -fmodule-name=A %t/module.modulemap -o %t/A.pcm
8+
// RUN: %clang_cc1 -x objective-c -fmodules -fno-implicit-modules -emit-module -fmodule-name=A_Private %t/module.modulemap -o %t/A_Private.pcm
9+
10+
// Check lazily-loaded module
11+
// RUN: %clang_cc1 -x objective-c -verify -fmodules -fno-implicit-modules -fmodule-file=A=%t/A.pcm -fmodule-file=A_Private=%t/A_Private.pcm -fsyntax-only %t/tu.m
12+
13+
// Check eagerly-loaded module
14+
// RUN: %clang_cc1 -x objective-c -verify -fmodules -fno-implicit-modules -fmodule-file=%t/A.pcm -fmodule-file=%t/A_Private.pcm -fsyntax-only %t/tu.m
15+
16+
//--- module.modulemap
17+
module A { header "a.h" }
18+
module A_Private { header "priv.h" }
19+
20+
//--- a.h
21+
22+
//--- priv.h
23+
void priv(void);
24+
25+
//--- tu.m
26+
@import A.Private; // expected-warning{{no submodule named 'Private' in module 'A'; using top level 'A_Private'}}
27+
// expected-note@*:* {{defined here}}
28+
29+
void tu(void) {
30+
priv();
31+
}

0 commit comments

Comments
 (0)