This revision was landed with ongoing or failed builds. This revision was automatically updated to reflect the committed changes. Closed by commit rGd574e918dba3: [clang][lex] NFCI: Use DirectoryEntryRef in ModuleMap::parseModuleMapFile() (authored by jansvoboda11). Herald added a subscriber: ributzka.
Changed prior to commit: https://reviews.llvm.org/D127651?vs=436404&id=526778#toc Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D127651/new/ https://reviews.llvm.org/D127651 Files: clang-tools-extra/modularize/ModularizeUtilities.cpp clang/include/clang/Lex/ModuleMap.h clang/lib/Lex/ModuleMap.cpp
Index: clang/lib/Lex/ModuleMap.cpp =================================================================== --- clang/lib/Lex/ModuleMap.cpp +++ clang/lib/Lex/ModuleMap.cpp @@ -1518,7 +1518,7 @@ /// The directory that file names in this module map file should /// be resolved relative to. - const DirectoryEntry *Directory; + DirectoryEntryRef Directory; /// Whether this module map is in a system header directory. bool IsSystem; @@ -1584,7 +1584,7 @@ explicit ModuleMapParser(Lexer &L, SourceManager &SourceMgr, const TargetInfo *Target, DiagnosticsEngine &Diags, ModuleMap &Map, const FileEntry *ModuleMapFile, - const DirectoryEntry *Directory, bool IsSystem) + DirectoryEntryRef Directory, bool IsSystem) : L(L), SourceMgr(SourceMgr), Target(Target), Diags(Diags), Map(Map), ModuleMapFile(ModuleMapFile), Directory(Directory), IsSystem(IsSystem) { @@ -2254,16 +2254,16 @@ StringRef FileNameRef = FileName; SmallString<128> ModuleMapFileName; if (llvm::sys::path::is_relative(FileNameRef)) { - ModuleMapFileName += Directory->getName(); + ModuleMapFileName += Directory.getName(); llvm::sys::path::append(ModuleMapFileName, FileName); FileNameRef = ModuleMapFileName; } - if (auto File = SourceMgr.getFileManager().getFile(FileNameRef)) + if (auto File = SourceMgr.getFileManager().getOptionalFileRef(FileNameRef)) Map.parseModuleMapFile( *File, IsSystem, Map.HeaderInfo.getHeaderSearchOpts().ModuleMapFileHomeIsCwd ? Directory - : (*File)->getDir(), + : File->getDir(), FileID(), nullptr, ExternLoc); } @@ -2518,7 +2518,7 @@ Dir = SourceMgr.getFileManager().getOptionalDirectoryRef(DirName); } else { SmallString<128> PathName; - PathName = Directory->getName(); + PathName = Directory.getName(); llvm::sys::path::append(PathName, DirName); Dir = SourceMgr.getFileManager().getOptionalDirectoryRef(PathName); } @@ -3080,7 +3080,7 @@ } bool ModuleMap::parseModuleMapFile(const FileEntry *File, bool IsSystem, - const DirectoryEntry *Dir, FileID ID, + DirectoryEntryRef Dir, FileID ID, unsigned *Offset, SourceLocation ExternModuleLoc) { assert(Target && "Missing target information"); Index: clang/include/clang/Lex/ModuleMap.h =================================================================== --- clang/include/clang/Lex/ModuleMap.h +++ clang/include/clang/Lex/ModuleMap.h @@ -729,8 +729,8 @@ /// /// \returns true if an error occurred, false otherwise. bool parseModuleMapFile(const FileEntry *File, bool IsSystem, - const DirectoryEntry *HomeDir, - FileID ID = FileID(), unsigned *Offset = nullptr, + DirectoryEntryRef HomeDir, FileID ID = FileID(), + unsigned *Offset = nullptr, SourceLocation ExternModuleLoc = SourceLocation()); /// Dump the contents of the module map, for debugging purposes. Index: clang-tools-extra/modularize/ModularizeUtilities.cpp =================================================================== --- clang-tools-extra/modularize/ModularizeUtilities.cpp +++ clang-tools-extra/modularize/ModularizeUtilities.cpp @@ -258,34 +258,33 @@ std::error_code ModularizeUtilities::loadModuleMap( llvm::StringRef InputPath) { // Get file entry for module.modulemap file. - auto ModuleMapEntryOrErr = - SourceMgr->getFileManager().getFile(InputPath); + auto ModuleMapEntryOrErr = SourceMgr->getFileManager().getFileRef(InputPath); // return error if not found. if (!ModuleMapEntryOrErr) { llvm::errs() << "error: File \"" << InputPath << "\" not found.\n"; - return ModuleMapEntryOrErr.getError(); + return errorToErrorCode(ModuleMapEntryOrErr.takeError()); } - const FileEntry *ModuleMapEntry = *ModuleMapEntryOrErr; + FileEntryRef ModuleMapEntry = *ModuleMapEntryOrErr; // Because the module map parser uses a ForwardingDiagnosticConsumer, // which doesn't forward the BeginSourceFile call, we do it explicitly here. DC.BeginSourceFile(*LangOpts, nullptr); // Figure out the home directory for the module map file. - const DirectoryEntry *Dir = ModuleMapEntry->getDir(); - StringRef DirName(Dir->getName()); + DirectoryEntryRef Dir = ModuleMapEntry.getDir(); + StringRef DirName(Dir.getName()); if (llvm::sys::path::filename(DirName) == "Modules") { DirName = llvm::sys::path::parent_path(DirName); if (DirName.endswith(".framework")) { - if (auto DirEntry = FileMgr->getDirectory(DirName)) - Dir = *DirEntry; - else - Dir = nullptr; + auto FrameworkDirOrErr = FileMgr->getDirectoryRef(DirName); + if (!FrameworkDirOrErr) { + // This can happen if there's a race between the above check and the + // removal of the directory. + return errorToErrorCode(FrameworkDirOrErr.takeError()); + } + Dir = *FrameworkDirOrErr; } - // FIXME: This assert can fail if there's a race between the above check - // and the removal of the directory. - assert(Dir && "parent must exist"); } std::unique_ptr<ModuleMap> ModMap;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits