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 @@ -470,7 +470,7 @@ Optional LookupFile( StringRef Filename, SourceLocation IncludeLoc, bool isAngled, ConstSearchDirIterator FromDir, ConstSearchDirIterator *CurDir, - ArrayRef> Includers, + ArrayRef> Includers, SmallVectorImpl *SearchPath, SmallVectorImpl *RelativePath, Module *RequestingModule, ModuleMap::KnownHeader *SuggestedModule, bool *IsMapped, bool *IsFrameworkFound, bool SkipCache = false, diff --git a/clang/lib/Frontend/FrontendAction.cpp b/clang/lib/Frontend/FrontendAction.cpp --- a/clang/lib/Frontend/FrontendAction.cpp +++ b/clang/lib/Frontend/FrontendAction.cpp @@ -808,11 +808,9 @@ "trying to build a header unit without a Pre-processor?"); HeaderSearch &HS = CI.getPreprocessor().getHeaderSearchInfo(); // Relative searches begin from CWD. - const DirectoryEntry *Dir = nullptr; - if (auto DirOrErr = CI.getFileManager().getDirectory(".")) - Dir = *DirOrErr; - SmallVector, 1> CWD; - CWD.push_back({nullptr, Dir}); + auto Dir = CI.getFileManager().getOptionalDirectoryRef("."); + SmallVector, 1> CWD; + CWD.push_back({nullptr, *Dir}); Optional FE = HS.LookupFile(FileName, SourceLocation(), /*Angled*/ Input.getKind().getHeaderUnitKind() == 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 @@ -836,7 +836,7 @@ Optional HeaderSearch::LookupFile( StringRef Filename, SourceLocation IncludeLoc, bool isAngled, ConstSearchDirIterator FromDir, ConstSearchDirIterator *CurDirArg, - ArrayRef> Includers, + ArrayRef> Includers, SmallVectorImpl *SearchPath, SmallVectorImpl *RelativePath, Module *RequestingModule, ModuleMap::KnownHeader *SuggestedModule, bool *IsMapped, bool *IsFrameworkFound, bool SkipCache, @@ -890,7 +890,7 @@ // Concatenate the requested file onto the directory. // FIXME: Portability. Filename concatenation should be in sys::Path. - TmpDir = IncluderAndDir.second->getName(); + TmpDir = IncluderAndDir.second.getName(); TmpDir.push_back('/'); TmpDir.append(Filename.begin(), Filename.end()); @@ -929,7 +929,7 @@ ToHFI.Framework = Framework; if (SearchPath) { - StringRef SearchPathRef(IncluderAndDir.second->getName()); + StringRef SearchPathRef(IncluderAndDir.second.getName()); SearchPath->clear(); SearchPath->append(SearchPathRef.begin(), SearchPathRef.end()); } @@ -939,7 +939,7 @@ } if (First) { diagnoseFrameworkInclude(Diags, IncludeLoc, - IncluderAndDir.second->getName(), Filename, + IncluderAndDir.second.getName(), Filename, &FE->getFileEntry()); return FE; } @@ -1081,7 +1081,7 @@ bool FoundByHeaderMap = !IsMapped ? false : *IsMapped; if (!Includers.empty()) diagnoseFrameworkInclude( - Diags, IncludeLoc, Includers.front().second->getName(), Filename, + Diags, IncludeLoc, Includers.front().second.getName(), Filename, &File->getFileEntry(), isAngled, FoundByHeaderMap); // Remember this location for the next lookup we do. diff --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp --- a/clang/lib/Lex/PPDirectives.cpp +++ b/clang/lib/Lex/PPDirectives.cpp @@ -888,12 +888,11 @@ // If the header lookup mechanism may be relative to the current inclusion // stack, record the parent #includes. - SmallVector, 16> - Includers; + SmallVector, 16> Includers; bool BuildSystemModule = false; if (!FromDir && !FromFile) { FileID FID = getCurrentFileLexer()->getFileID(); - const FileEntry *FileEnt = SourceMgr.getFileEntryForID(FID); + Optional FileEnt = SourceMgr.getFileEntryRefForID(FID); // If there is no file entry associated with this file, it must be the // predefines buffer or the module includes buffer. Any other file is not @@ -911,11 +910,13 @@ if (FID == SourceMgr.getMainFileID() && MainFileDir) { Includers.push_back(std::make_pair(nullptr, *MainFileDir)); BuildSystemModule = getCurrentModule()->IsSystem; - } else if ((FileEnt = - SourceMgr.getFileEntryForID(SourceMgr.getMainFileID()))) - Includers.push_back(std::make_pair(FileEnt, *FileMgr.getDirectory("."))); + } else if ((FileEnt = SourceMgr.getFileEntryRefForID( + SourceMgr.getMainFileID()))) { + auto CWD = FileMgr.getOptionalDirectoryRef("."); + Includers.push_back(std::make_pair(*FileEnt, *CWD)); + } } else { - Includers.push_back(std::make_pair(FileEnt, FileEnt->getDir())); + Includers.push_back(std::make_pair(*FileEnt, FileEnt->getDir())); } // MSVC searches the current include stack from top to bottom for @@ -925,7 +926,7 @@ for (IncludeStackInfo &ISEntry : llvm::reverse(IncludeMacroStack)) { if (IsFileLexer(ISEntry)) if ((FileEnt = ISEntry.ThePPLexer->getFileEntry())) - Includers.push_back(std::make_pair(FileEnt, FileEnt->getDir())); + Includers.push_back(std::make_pair(*FileEnt, FileEnt->getDir())); } } }