diff options
| author | Ben Langmuir <blangmuir@apple.com> | 2015-07-02 13:19:48 +0000 |
|---|---|---|
| committer | Ben Langmuir <blangmuir@apple.com> | 2015-07-02 13:19:48 +0000 |
| commit | a525400d37cf2920479862acafedc83e2d7c5fb6 (patch) | |
| tree | 490f393efa9e52609687560b83d2cd96d806b064 /clang/lib/Lex | |
| parent | 553a5b00412c34e2b9101a993a6e7368a03fca68 (diff) | |
| download | bcm5719-llvm-a525400d37cf2920479862acafedc83e2d7c5fb6.tar.gz bcm5719-llvm-a525400d37cf2920479862acafedc83e2d7c5fb6.zip | |
[Modules] Be consistent about finding a module for framework headers
We use findModuleForHeader() in several places, but in header search we
were not calling it when a framework module didn't show up with the
expected name, which would then lead to unexpected non-modular includes.
Now we will find the module unconditionally for frameworks. For regular
frameworks, we use the spelling of the module name from the module map
file, and for inferred ones we use the canonical directory name.
In the future we might want to lock down framework modules sufficiently
that these name mismatches cannot happen.
rdar://problem/20465870
llvm-svn: 241258
Diffstat (limited to 'clang/lib/Lex')
| -rw-r--r-- | clang/lib/Lex/HeaderSearch.cpp | 22 | ||||
| -rw-r--r-- | clang/lib/Lex/ModuleMap.cpp | 44 |
2 files changed, 30 insertions, 36 deletions
diff --git a/clang/lib/Lex/HeaderSearch.cpp b/clang/lib/Lex/HeaderSearch.cpp index 89120ff84d9..6c5c64bd266 100644 --- a/clang/lib/Lex/HeaderSearch.cpp +++ b/clang/lib/Lex/HeaderSearch.cpp @@ -532,9 +532,13 @@ const FileEntry *DirectoryLookup::DoFrameworkLookup( // Load this framework module. If that succeeds, find the suggested module // for this header, if any. bool IsSystem = getDirCharacteristic() != SrcMgr::C_User; - if (HS.loadFrameworkModule(ModuleName, TopFrameworkDir, IsSystem)) { - *SuggestedModule = HS.findModuleForHeader(FE); - } + HS.loadFrameworkModule(ModuleName, TopFrameworkDir, IsSystem); + + // FIXME: This can find a module not part of ModuleName, which is + // important so that we're consistent about whether this header + // corresponds to a module. Possibly we should lock down framework modules + // so that this is not possible. + *SuggestedModule = HS.findModuleForHeader(FE); } else { *SuggestedModule = HS.findModuleForHeader(FE); } @@ -1238,6 +1242,9 @@ Module *HeaderSearch::loadFrameworkModule(StringRef Name, // Try to load a module map file. switch (loadModuleMapFile(Dir, IsSystem, /*IsFramework*/true)) { case LMM_InvalidModuleMap: + // Try to infer a module map from the framework directory. + if (HSOpts->ImplicitModuleMaps) + ModMap.inferFrameworkModule(Dir, IsSystem, /*Parent=*/nullptr); break; case LMM_AlreadyLoaded: @@ -1245,15 +1252,10 @@ Module *HeaderSearch::loadFrameworkModule(StringRef Name, return nullptr; case LMM_NewlyLoaded: - return ModMap.findModule(Name); + break; } - - // Try to infer a module map from the framework directory. - if (HSOpts->ImplicitModuleMaps) - return ModMap.inferFrameworkModule(Name, Dir, IsSystem, /*Parent=*/nullptr); - - return nullptr; + return ModMap.findModule(Name); } diff --git a/clang/lib/Lex/ModuleMap.cpp b/clang/lib/Lex/ModuleMap.cpp index 306401c5e6f..e6fe38927e2 100644 --- a/clang/lib/Lex/ModuleMap.cpp +++ b/clang/lib/Lex/ModuleMap.cpp @@ -583,19 +583,28 @@ static void inferFrameworkLink(Module *Mod, const DirectoryEntry *FrameworkDir, } } -Module * -ModuleMap::inferFrameworkModule(StringRef ModuleName, - const DirectoryEntry *FrameworkDir, - bool IsSystem, - Module *Parent) { +Module *ModuleMap::inferFrameworkModule(const DirectoryEntry *FrameworkDir, + bool IsSystem, Module *Parent) { Attributes Attrs; Attrs.IsSystem = IsSystem; - return inferFrameworkModule(ModuleName, FrameworkDir, Attrs, Parent); + return inferFrameworkModule(FrameworkDir, Attrs, Parent); } -Module *ModuleMap::inferFrameworkModule(StringRef ModuleName, - const DirectoryEntry *FrameworkDir, +Module *ModuleMap::inferFrameworkModule(const DirectoryEntry *FrameworkDir, Attributes Attrs, Module *Parent) { + // Note: as an egregious but useful hack we use the real path here, because + // we might be looking at an embedded framework that symlinks out to a + // top-level framework, and we need to infer as if we were naming the + // top-level framework. + StringRef FrameworkDirName = + SourceMgr.getFileManager().getCanonicalName(FrameworkDir); + + // In case this is a case-insensitive filesystem, use the canonical + // directory name as the ModuleName, since modules are case-sensitive. + // FIXME: we should be able to give a fix-it hint for the correct spelling. + SmallString<32> ModuleNameStorage; + StringRef ModuleName = sanitizeFilenameAsIdentifier( + llvm::sys::path::stem(FrameworkDirName), ModuleNameStorage); // Check whether we've already found this module. if (Module *Mod = lookupModuleQualified(ModuleName, Parent)) @@ -608,20 +617,6 @@ Module *ModuleMap::inferFrameworkModule(StringRef ModuleName, const FileEntry *ModuleMapFile = nullptr; if (!Parent) { // Determine whether we're allowed to infer a module map. - - // Note: as an egregious but useful hack we use the real path here, because - // we might be looking at an embedded framework that symlinks out to a - // top-level framework, and we need to infer as if we were naming the - // top-level framework. - StringRef FrameworkDirName - = SourceMgr.getFileManager().getCanonicalName(FrameworkDir); - - // In case this is a case-insensitive filesystem, make sure the canonical - // directory name matches ModuleName exactly. Modules are case-sensitive. - // FIXME: we should be able to give a fix-it hint for the correct spelling. - if (llvm::sys::path::stem(FrameworkDirName) != ModuleName) - return nullptr; - bool canInfer = false; if (llvm::sys::path::has_parent_path(FrameworkDirName)) { // Figure out the parent path. @@ -747,10 +742,7 @@ Module *ModuleMap::inferFrameworkModule(StringRef ModuleName, continue; // FIXME: Do we want to warn about subframeworks without umbrella headers? - SmallString<32> NameBuf; - inferFrameworkModule(sanitizeFilenameAsIdentifier( - llvm::sys::path::stem(Dir->path()), NameBuf), - SubframeworkDir, Attrs, Result); + inferFrameworkModule(SubframeworkDir, Attrs, Result); } } |

