diff --git a/clang/include/clang/Lex/HeaderSearch.h b/clang/include/clang/Lex/HeaderSearch.h --- a/clang/include/clang/Lex/HeaderSearch.h +++ b/clang/include/clang/Lex/HeaderSearch.h @@ -638,7 +638,7 @@ /// Try to find a module map file in the given directory, returning /// \c nullopt if none is found. - OptionalFileEntryRef lookupModuleMapFile(const DirectoryEntry *Dir, + OptionalFileEntryRef lookupModuleMapFile(DirectoryEntryRef Dir, bool IsFramework); /// Determine whether there is a module map that may map the header diff --git a/clang/include/clang/Lex/ModuleMap.h b/clang/include/clang/Lex/ModuleMap.h --- a/clang/include/clang/Lex/ModuleMap.h +++ b/clang/include/clang/Lex/ModuleMap.h @@ -487,11 +487,11 @@ /// Determine whether the given header is part of a module /// marked 'unavailable'. - bool isHeaderInUnavailableModule(const FileEntry *Header) const; + bool isHeaderInUnavailableModule(FileEntryRef Header) const; /// Determine whether the given header is unavailable as part /// of the specified module. - bool isHeaderUnavailableInModule(const FileEntry *Header, + bool isHeaderUnavailableInModule(FileEntryRef Header, const Module *RequestingModule) const; /// Retrieve a module with the given name. diff --git a/clang/lib/Lex/HeaderSearch.cpp b/clang/lib/Lex/HeaderSearch.cpp --- a/clang/lib/Lex/HeaderSearch.cpp +++ b/clang/lib/Lex/HeaderSearch.cpp @@ -1751,12 +1751,12 @@ } OptionalFileEntryRef -HeaderSearch::lookupModuleMapFile(const DirectoryEntry *Dir, bool IsFramework) { +HeaderSearch::lookupModuleMapFile(DirectoryEntryRef Dir, bool IsFramework) { if (!HSOpts->ImplicitModuleMaps) return std::nullopt; // For frameworks, the preferred spelling is Modules/module.modulemap, but // module.map at the framework root is also accepted. - SmallString<128> ModuleMapFileName(Dir->getName()); + SmallString<128> ModuleMapFileName(Dir.getName()); if (IsFramework) llvm::sys::path::append(ModuleMapFileName, "Modules"); llvm::sys::path::append(ModuleMapFileName, "module.modulemap"); @@ -1764,7 +1764,7 @@ return *F; // Continue to allow module.map - ModuleMapFileName = Dir->getName(); + ModuleMapFileName = Dir.getName(); llvm::sys::path::append(ModuleMapFileName, "module.map"); if (auto F = FileMgr.getOptionalFileRef(ModuleMapFileName)) return *F; @@ -1772,7 +1772,7 @@ // For frameworks, allow to have a private module map with a preferred // spelling when a public module map is absent. if (IsFramework) { - ModuleMapFileName = Dir->getName(); + ModuleMapFileName = Dir.getName(); llvm::sys::path::append(ModuleMapFileName, "Modules", "module.private.modulemap"); if (auto F = FileMgr.getOptionalFileRef(ModuleMapFileName)) diff --git a/clang/lib/Lex/ModuleMap.cpp b/clang/lib/Lex/ModuleMap.cpp --- a/clang/lib/Lex/ModuleMap.cpp +++ b/clang/lib/Lex/ModuleMap.cpp @@ -700,13 +700,12 @@ return It->second; } -bool ModuleMap::isHeaderInUnavailableModule(const FileEntry *Header) const { +bool ModuleMap::isHeaderInUnavailableModule(FileEntryRef Header) const { return isHeaderUnavailableInModule(Header, nullptr); } -bool -ModuleMap::isHeaderUnavailableInModule(const FileEntry *Header, - const Module *RequestingModule) const { +bool ModuleMap::isHeaderUnavailableInModule( + FileEntryRef Header, const Module *RequestingModule) const { resolveHeaderDirectives(Header); HeadersMap::const_iterator Known = Headers.find(Header); if (Known != Headers.end()) { @@ -734,8 +733,8 @@ return true; } - const DirectoryEntry *Dir = Header->getDir(); - SmallVector SkippedDirs; + OptionalDirectoryEntryRef Dir = Header.getDir(); + SmallVector SkippedDirs; StringRef DirName = Dir->getName(); auto IsUnavailable = [&](const Module *M) { @@ -746,8 +745,7 @@ // Keep walking up the directory hierarchy, looking for a directory with // an umbrella header. do { - llvm::DenseMap::const_iterator KnownDir - = UmbrellaDirs.find(Dir); + auto KnownDir = UmbrellaDirs.find(*Dir); if (KnownDir != UmbrellaDirs.end()) { Module *Found = KnownDir->second; if (IsUnavailable(Found)) @@ -761,11 +759,11 @@ UmbrellaModule = UmbrellaModule->Parent; if (UmbrellaModule->InferSubmodules) { - for (const DirectoryEntry *SkippedDir : llvm::reverse(SkippedDirs)) { + for (DirectoryEntryRef SkippedDir : llvm::reverse(SkippedDirs)) { // Find or create the module that corresponds to this directory name. SmallString<32> NameBuf; StringRef Name = sanitizeFilenameAsIdentifier( - llvm::sys::path::stem(SkippedDir->getName()), NameBuf); + llvm::sys::path::stem(SkippedDir.getName()), NameBuf); Found = lookupModuleQualified(Name, Found); if (!Found) return false; @@ -776,7 +774,7 @@ // Infer a submodule with the same name as this header file. SmallString<32> NameBuf; StringRef Name = sanitizeFilenameAsIdentifier( - llvm::sys::path::stem(Header->getName()), + llvm::sys::path::stem(Header.getName()), NameBuf); Found = lookupModuleQualified(Name, Found); if (!Found) @@ -786,7 +784,7 @@ return IsUnavailable(Found); } - SkippedDirs.push_back(Dir); + SkippedDirs.push_back(*Dir); // Retrieve our parent path. DirName = llvm::sys::path::parent_path(DirName); @@ -794,10 +792,7 @@ break; // Resolve the parent path to a directory entry. - if (auto DirEntry = SourceMgr.getFileManager().getDirectory(DirName)) - Dir = *DirEntry; - else - Dir = nullptr; + Dir = SourceMgr.getFileManager().getOptionalDirectoryRef(DirName); } while (Dir); return false; diff --git a/clang/test/Modules/crash-vfs-umbrella-frameworks.m b/clang/test/Modules/crash-vfs-umbrella-frameworks.m --- a/clang/test/Modules/crash-vfs-umbrella-frameworks.m +++ b/clang/test/Modules/crash-vfs-umbrella-frameworks.m @@ -24,15 +24,7 @@ // CHECK-NEXT: note: diagnostic msg: {{.*}}.cache // CHECKYAML: 'type': 'directory', -// CHECKYAML: 'name': "/[[PATH:.*]]/i/Frameworks/A.framework/Frameworks/B.framework/Headers", -// CHECKYAML-NEXT: 'contents': [ -// CHECKYAML-NEXT: { -// CHECKYAML-NEXT: 'type': 'file', -// CHECKYAML-NEXT: 'name': "B.h", -// CHECKYAML-NEXT: 'external-contents': "/[[PATH]]/i/Frameworks/B.framework/Headers/B.h" - -// CHECKYAML: 'type': 'directory', -// CHECKYAML: 'name': "/[[PATH]]/i/Frameworks/B.framework/Headers", +// CHECKYAML: 'name': "/[[PATH:.*]]/i/Frameworks/B.framework/Headers", // CHECKYAML-NEXT: 'contents': [ // CHECKYAML-NEXT: { // CHECKYAML-NEXT: 'type': 'file',