Index: clang/include/clang/Lex/ModuleMap.h =================================================================== --- clang/include/clang/Lex/ModuleMap.h +++ clang/include/clang/Lex/ModuleMap.h @@ -328,10 +328,9 @@ /// \param NeedsFramework If M is not a framework but a missing header would /// be found in case M was, set it to true. False otherwise. /// \return The resolved file, if any. - const FileEntry *findHeader(Module *M, - const Module::UnresolvedHeaderDirective &Header, - SmallVectorImpl &RelativePathName, - bool &NeedsFramework); + Optional + findHeader(Module *M, const Module::UnresolvedHeaderDirective &Header, + SmallVectorImpl &RelativePathName, bool &NeedsFramework); /// Resolve the given header directive. /// Index: clang/lib/Lex/ModuleMap.cpp =================================================================== --- clang/lib/Lex/ModuleMap.cpp +++ clang/lib/Lex/ModuleMap.cpp @@ -171,23 +171,23 @@ llvm::sys::path::append(Path, "Frameworks", Paths[I-1] + ".framework"); } -const FileEntry *ModuleMap::findHeader( +Optional ModuleMap::findHeader( Module *M, const Module::UnresolvedHeaderDirective &Header, SmallVectorImpl &RelativePathName, bool &NeedsFramework) { // Search for the header file within the module's home directory. auto *Directory = M->Directory; SmallString<128> FullPathName(Directory->getName()); - auto GetFile = [&](StringRef Filename) -> const FileEntry * { - auto File = SourceMgr.getFileManager().getFile(Filename); - if (!File || - (Header.Size && (*File)->getSize() != *Header.Size) || - (Header.ModTime && (*File)->getModificationTime() != *Header.ModTime)) - return nullptr; + auto GetFile = [&](StringRef Filename) -> Optional { + auto File = + expectedToOptional(SourceMgr.getFileManager().getFileRef(Filename)); + if (!File || (Header.Size && File->getSize() != *Header.Size) || + (Header.ModTime && File->getModificationTime() != *Header.ModTime)) + return None; return *File; }; - auto GetFrameworkFile = [&]() -> const FileEntry * { + auto GetFrameworkFile = [&]() -> Optional { unsigned FullPathLength = FullPathName.size(); appendSubframeworkPaths(M, RelativePathName); unsigned RelativePathLength = RelativePathName.size(); @@ -195,7 +195,7 @@ // Check whether this file is in the public headers. llvm::sys::path::append(RelativePathName, "Headers", Header.FileName); llvm::sys::path::append(FullPathName, RelativePathName); - if (auto *File = GetFile(FullPathName)) + if (auto File = GetFile(FullPathName)) return File; // Check whether this file is in the private headers. @@ -227,7 +227,7 @@ // Lookup for normal headers. llvm::sys::path::append(RelativePathName, Header.FileName); llvm::sys::path::append(FullPathName, RelativePathName); - auto *NormalHdrFile = GetFile(FullPathName); + auto NormalHdrFile = GetFile(FullPathName); if (!NormalHdrFile && Directory->getName().endswith(".framework")) { // The lack of 'framework' keyword in a module declaration it's a simple @@ -241,7 +241,7 @@ << Header.FileName << M->getFullModuleName(); NeedsFramework = true; } - return nullptr; + return None; } return NormalHdrFile; @@ -251,18 +251,18 @@ const Module::UnresolvedHeaderDirective &Header, bool &NeedsFramework) { SmallString<128> RelativePathName; - if (const FileEntry *File = + if (Optional File = findHeader(Mod, Header, RelativePathName, NeedsFramework)) { if (Header.IsUmbrella) { - const DirectoryEntry *UmbrellaDir = File->getDir(); + const DirectoryEntry *UmbrellaDir = &File->getDir().getDirEntry(); if (Module *UmbrellaMod = UmbrellaDirs[UmbrellaDir]) Diags.Report(Header.FileNameLoc, diag::err_mmap_umbrella_clash) << UmbrellaMod->getFullModuleName(); else // Record this umbrella header. - setUmbrellaHeader(Mod, File, RelativePathName.str()); + setUmbrellaHeader(Mod, *File, RelativePathName.str()); } else { - Module::Header H = {std::string(RelativePathName.str()), File}; + Module::Header H = {std::string(RelativePathName.str()), *File}; if (Header.Kind == Module::HK_Excluded) excludeHeader(Mod, H); else