diff options
Diffstat (limited to 'clang')
7 files changed, 38 insertions, 0 deletions
diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp index f57246bec09..4199cbe0f66 100644 --- a/clang/lib/Frontend/CompilerInstance.cpp +++ b/clang/lib/Frontend/CompilerInstance.cpp @@ -1188,6 +1188,19 @@ compileModuleImpl(CompilerInstance &ImportingInstance, SourceLocation ImportLoc, return !Instance.getDiagnostics().hasErrorOccurred(); } +static const FileEntry *getPublicModuleMap(const FileEntry *File, + FileManager &FileMgr) { + StringRef Filename = llvm::sys::path::filename(File->getName()); + SmallString<128> PublicFilename(File->getDir()->getName()); + if (Filename == "module_private.map") + llvm::sys::path::append(PublicFilename, "module.map"); + else if (Filename == "module.private.modulemap") + llvm::sys::path::append(PublicFilename, "module.modulemap"); + else + return nullptr; + return FileMgr.getFile(PublicFilename); +} + /// \brief Compile a module file for the given module, using the options /// provided by the importing compiler instance. Returns true if the module /// was built without errors. @@ -1204,6 +1217,13 @@ static bool compileModuleImpl(CompilerInstance &ImportingInstance, bool Result; if (const FileEntry *ModuleMapFile = ModMap.getContainingModuleMapFile(Module)) { + // Canonicalize compilation to start with the public module map. This is + // vital for submodules declarations in the private module maps to be + // correctly parsed when depending on a top level module in the public one. + if (const FileEntry *PublicMMFile = getPublicModuleMap( + ModuleMapFile, ImportingInstance.getFileManager())) + ModuleMapFile = PublicMMFile; + // Use the module map where this module resides. Result = compileModuleImpl( ImportingInstance, ImportLoc, Module->getTopLevelModuleName(), diff --git a/clang/test/Modules/Inputs/submodule-in-private-mmap/A.framework/Headers/A.h b/clang/test/Modules/Inputs/submodule-in-private-mmap/A.framework/Headers/A.h new file mode 100644 index 00000000000..975f1f0437b --- /dev/null +++ b/clang/test/Modules/Inputs/submodule-in-private-mmap/A.framework/Headers/A.h @@ -0,0 +1 @@ +// A.h diff --git a/clang/test/Modules/Inputs/submodule-in-private-mmap/A.framework/Headers/SomeSub.h b/clang/test/Modules/Inputs/submodule-in-private-mmap/A.framework/Headers/SomeSub.h new file mode 100644 index 00000000000..e69de29bb2d --- /dev/null +++ b/clang/test/Modules/Inputs/submodule-in-private-mmap/A.framework/Headers/SomeSub.h diff --git a/clang/test/Modules/Inputs/submodule-in-private-mmap/A.framework/Modules/module.modulemap b/clang/test/Modules/Inputs/submodule-in-private-mmap/A.framework/Modules/module.modulemap new file mode 100644 index 00000000000..afa48392e94 --- /dev/null +++ b/clang/test/Modules/Inputs/submodule-in-private-mmap/A.framework/Modules/module.modulemap @@ -0,0 +1,3 @@ +framework module A { + header "A.h" +} diff --git a/clang/test/Modules/Inputs/submodule-in-private-mmap/A.framework/Modules/module.private.modulemap b/clang/test/Modules/Inputs/submodule-in-private-mmap/A.framework/Modules/module.private.modulemap new file mode 100644 index 00000000000..1dbd9fb8096 --- /dev/null +++ b/clang/test/Modules/Inputs/submodule-in-private-mmap/A.framework/Modules/module.private.modulemap @@ -0,0 +1,7 @@ +framework module A_Private { + header "APrivate.h" +} + +module A.SomeSub { + header "SomeSub.h" +} diff --git a/clang/test/Modules/Inputs/submodule-in-private-mmap/A.framework/PrivateHeaders/APrivate.h b/clang/test/Modules/Inputs/submodule-in-private-mmap/A.framework/PrivateHeaders/APrivate.h new file mode 100644 index 00000000000..e69de29bb2d --- /dev/null +++ b/clang/test/Modules/Inputs/submodule-in-private-mmap/A.framework/PrivateHeaders/APrivate.h diff --git a/clang/test/Modules/submodule-in-private-mmap.m b/clang/test/Modules/submodule-in-private-mmap.m new file mode 100644 index 00000000000..50e50108757 --- /dev/null +++ b/clang/test/Modules/submodule-in-private-mmap.m @@ -0,0 +1,7 @@ +// RUN: rm -rf %t +// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -F%S/Inputs/submodule-in-private-mmap -fsyntax-only %s -Wno-private-module -verify + +// expected-no-diagnostics + +@import A.Private; +@import A.SomeSub; |