Author: bruno Date: Tue May 1 19:25:03 2018 New Revision: 331322 URL: http://llvm.org/viewvc/llvm-project?rev=331322&view=rev Log: [Modules] Allow @import to reach submodules in private module maps
A @import targeting a top level module from a private module map file (@import Foo_Private), would fail if there's any submodule declaration around (module Foo.SomeSub) in the same private module map. This happens because compileModuleImpl, when building Foo_Private, will start with the private module map and will not parse the public one, which leads to unsuccessful parsing of Foo.SomeSub, since top level Foo was never parsed. Declaring other submodules in the private module map is not common and should usually be avoided, but it shouldn't fail to build. Canonicalize compileModuleImpl to always look at the public module first, so that all necessary information is available when parsing the private one. rdar://problem/39822328 Added: cfe/trunk/test/Modules/Inputs/submodule-in-private-mmap/ cfe/trunk/test/Modules/Inputs/submodule-in-private-mmap/A.framework/ cfe/trunk/test/Modules/Inputs/submodule-in-private-mmap/A.framework/Headers/ cfe/trunk/test/Modules/Inputs/submodule-in-private-mmap/A.framework/Headers/A.h cfe/trunk/test/Modules/Inputs/submodule-in-private-mmap/A.framework/Headers/SomeSub.h cfe/trunk/test/Modules/Inputs/submodule-in-private-mmap/A.framework/Modules/ cfe/trunk/test/Modules/Inputs/submodule-in-private-mmap/A.framework/Modules/module.modulemap cfe/trunk/test/Modules/Inputs/submodule-in-private-mmap/A.framework/Modules/module.private.modulemap cfe/trunk/test/Modules/Inputs/submodule-in-private-mmap/A.framework/PrivateHeaders/ cfe/trunk/test/Modules/Inputs/submodule-in-private-mmap/A.framework/PrivateHeaders/APrivate.h cfe/trunk/test/Modules/submodule-in-private-mmap.m Modified: cfe/trunk/lib/Frontend/CompilerInstance.cpp Modified: cfe/trunk/lib/Frontend/CompilerInstance.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInstance.cpp?rev=331322&r1=331321&r2=331322&view=diff ============================================================================== --- cfe/trunk/lib/Frontend/CompilerInstance.cpp (original) +++ cfe/trunk/lib/Frontend/CompilerInstance.cpp Tue May 1 19:25:03 2018 @@ -1188,6 +1188,19 @@ compileModuleImpl(CompilerInstance &Impo 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(CompilerIn 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(), Added: cfe/trunk/test/Modules/Inputs/submodule-in-private-mmap/A.framework/Headers/A.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/submodule-in-private-mmap/A.framework/Headers/A.h?rev=331322&view=auto ============================================================================== --- cfe/trunk/test/Modules/Inputs/submodule-in-private-mmap/A.framework/Headers/A.h (added) +++ cfe/trunk/test/Modules/Inputs/submodule-in-private-mmap/A.framework/Headers/A.h Tue May 1 19:25:03 2018 @@ -0,0 +1 @@ +// A.h Added: cfe/trunk/test/Modules/Inputs/submodule-in-private-mmap/A.framework/Headers/SomeSub.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/submodule-in-private-mmap/A.framework/Headers/SomeSub.h?rev=331322&view=auto ============================================================================== (empty) Added: cfe/trunk/test/Modules/Inputs/submodule-in-private-mmap/A.framework/Modules/module.modulemap URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/submodule-in-private-mmap/A.framework/Modules/module.modulemap?rev=331322&view=auto ============================================================================== --- cfe/trunk/test/Modules/Inputs/submodule-in-private-mmap/A.framework/Modules/module.modulemap (added) +++ cfe/trunk/test/Modules/Inputs/submodule-in-private-mmap/A.framework/Modules/module.modulemap Tue May 1 19:25:03 2018 @@ -0,0 +1,3 @@ +framework module A { + header "A.h" +} Added: cfe/trunk/test/Modules/Inputs/submodule-in-private-mmap/A.framework/Modules/module.private.modulemap URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/submodule-in-private-mmap/A.framework/Modules/module.private.modulemap?rev=331322&view=auto ============================================================================== --- cfe/trunk/test/Modules/Inputs/submodule-in-private-mmap/A.framework/Modules/module.private.modulemap (added) +++ cfe/trunk/test/Modules/Inputs/submodule-in-private-mmap/A.framework/Modules/module.private.modulemap Tue May 1 19:25:03 2018 @@ -0,0 +1,7 @@ +framework module A_Private { + header "APrivate.h" +} + +module A.SomeSub { + header "SomeSub.h" +} Added: cfe/trunk/test/Modules/Inputs/submodule-in-private-mmap/A.framework/PrivateHeaders/APrivate.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/submodule-in-private-mmap/A.framework/PrivateHeaders/APrivate.h?rev=331322&view=auto ============================================================================== (empty) Added: cfe/trunk/test/Modules/submodule-in-private-mmap.m URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/submodule-in-private-mmap.m?rev=331322&view=auto ============================================================================== --- cfe/trunk/test/Modules/submodule-in-private-mmap.m (added) +++ cfe/trunk/test/Modules/submodule-in-private-mmap.m Tue May 1 19:25:03 2018 @@ -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; _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits