diff --git a/clang-tools-extra/clang-tidy/bugprone/SuspiciousIncludeCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/SuspiciousIncludeCheck.cpp --- a/clang-tools-extra/clang-tidy/bugprone/SuspiciousIncludeCheck.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/SuspiciousIncludeCheck.cpp @@ -93,10 +93,9 @@ llvm::sys::path::replace_extension(GuessedFileName, (HFE.size() ? "." : "") + HFE); - const DirectoryLookup *CurDir; Optional File = PP->LookupFile(DiagLoc, GuessedFileName, IsAngled, nullptr, nullptr, - CurDir, nullptr, nullptr, nullptr, nullptr, nullptr); + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr); if (File) { Check.diag(DiagLoc, "did you mean to include '%0'?", DiagnosticIDs::Note) << GuessedFileName; 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 @@ -408,7 +408,7 @@ /// found. Optional LookupFile( StringRef Filename, SourceLocation IncludeLoc, bool isAngled, - const DirectoryLookup *FromDir, const DirectoryLookup *&CurDir, + const DirectoryLookup *FromDir, const DirectoryLookup **CurDir, ArrayRef> Includers, SmallVectorImpl *SearchPath, SmallVectorImpl *RelativePath, Module *RequestingModule, ModuleMap::KnownHeader *SuggestedModule, diff --git a/clang/include/clang/Lex/Preprocessor.h b/clang/include/clang/Lex/Preprocessor.h --- a/clang/include/clang/Lex/Preprocessor.h +++ b/clang/include/clang/Lex/Preprocessor.h @@ -2051,7 +2051,7 @@ Optional LookupFile(SourceLocation FilenameLoc, StringRef Filename, bool isAngled, const DirectoryLookup *FromDir, const FileEntry *FromFile, - const DirectoryLookup *&CurDir, SmallVectorImpl *SearchPath, + const DirectoryLookup **CurDir, SmallVectorImpl *SearchPath, SmallVectorImpl *RelativePath, ModuleMap::KnownHeader *SuggestedModule, bool *IsMapped, bool *IsFrameworkFound, bool SkipCache = false); @@ -2300,7 +2300,7 @@ }; Optional LookupHeaderIncludeOrImport( - const DirectoryLookup *&CurDir, StringRef &Filename, + const DirectoryLookup **CurDir, StringRef &Filename, SourceLocation FilenameLoc, CharSourceRange FilenameRange, const Token &FilenameTok, bool &IsFrameworkFound, bool IsImportDecl, bool &IsMapped, const DirectoryLookup *LookupFrom, diff --git a/clang/lib/Frontend/FrontendActions.cpp b/clang/lib/Frontend/FrontendActions.cpp --- a/clang/lib/Frontend/FrontendActions.cpp +++ b/clang/lib/Frontend/FrontendActions.cpp @@ -310,9 +310,8 @@ auto &HS = CI.getPreprocessor().getHeaderSearchInfo(); SmallVector Headers; for (StringRef Name : ModuleHeaders) { - const DirectoryLookup *CurDir = nullptr; Optional FE = HS.LookupFile( - Name, SourceLocation(), /*Angled*/ false, nullptr, CurDir, None, + Name, SourceLocation(), /*Angled*/ false, nullptr, nullptr, None, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr); if (!FE) { CI.getDiagnostics().Report(diag::err_module_header_file_not_found) diff --git a/clang/lib/Frontend/VerifyDiagnosticConsumer.cpp b/clang/lib/Frontend/VerifyDiagnosticConsumer.cpp --- a/clang/lib/Frontend/VerifyDiagnosticConsumer.cpp +++ b/clang/lib/Frontend/VerifyDiagnosticConsumer.cpp @@ -541,9 +541,8 @@ ExpectedLoc = SourceLocation(); } else { // Lookup file via Preprocessor, like a #include. - const DirectoryLookup *CurDir; Optional File = - PP->LookupFile(Pos, Filename, false, nullptr, nullptr, CurDir, + PP->LookupFile(Pos, Filename, false, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr); if (!File) { Diags.Report(Pos.getLocWithOffset(PH.C - PH.Begin), 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 @@ -831,12 +831,15 @@ /// search is needed. Microsoft mode will pass all \#including files. Optional HeaderSearch::LookupFile( StringRef Filename, SourceLocation IncludeLoc, bool isAngled, - const DirectoryLookup *FromDir, const DirectoryLookup *&CurDir, + const DirectoryLookup *FromDir, const DirectoryLookup **CurDirArg, ArrayRef> Includers, SmallVectorImpl *SearchPath, SmallVectorImpl *RelativePath, Module *RequestingModule, ModuleMap::KnownHeader *SuggestedModule, bool *IsMapped, bool *IsFrameworkFound, bool SkipCache, bool BuildSystemModule) { + const DirectoryLookup *CurDirLocal = nullptr; + const DirectoryLookup *&CurDir = CurDirArg ? *CurDirArg : CurDirLocal; + if (IsMapped) *IsMapped = false; @@ -1083,7 +1086,7 @@ ScratchFilename += Filename; Optional File = LookupFile( - ScratchFilename, IncludeLoc, /*isAngled=*/true, FromDir, CurDir, + ScratchFilename, IncludeLoc, /*isAngled=*/true, FromDir, &CurDir, Includers.front(), SearchPath, RelativePath, RequestingModule, SuggestedModule, IsMapped, /*IsFrameworkFound=*/nullptr); 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 @@ -818,10 +818,13 @@ Optional Preprocessor::LookupFile( SourceLocation FilenameLoc, StringRef Filename, bool isAngled, const DirectoryLookup *FromDir, const FileEntry *FromFile, - const DirectoryLookup *&CurDir, SmallVectorImpl *SearchPath, + const DirectoryLookup **CurDirArg, SmallVectorImpl *SearchPath, SmallVectorImpl *RelativePath, ModuleMap::KnownHeader *SuggestedModule, bool *IsMapped, bool *IsFrameworkFound, bool SkipCache) { + const DirectoryLookup *CurDirLocal = nullptr; + const DirectoryLookup *&CurDir = CurDirArg ? *CurDirArg : CurDirLocal; + Module *RequestingModule = getModuleForLocation(FilenameLoc); bool RequestingModuleIsModuleInterface = !SourceMgr.isInMainFile(FilenameLoc); @@ -877,7 +880,7 @@ const DirectoryLookup *TmpCurDir = CurDir; const DirectoryLookup *TmpFromDir = nullptr; while (Optional FE = HeaderInfo.LookupFile( - Filename, FilenameLoc, isAngled, TmpFromDir, TmpCurDir, + Filename, FilenameLoc, isAngled, TmpFromDir, &TmpCurDir, Includers, SearchPath, RelativePath, RequestingModule, SuggestedModule, /*IsMapped=*/nullptr, /*IsFrameworkFound=*/nullptr, SkipCache)) { @@ -895,7 +898,7 @@ // Do a standard file entry lookup. Optional FE = HeaderInfo.LookupFile( - Filename, FilenameLoc, isAngled, FromDir, CurDir, Includers, SearchPath, + Filename, FilenameLoc, isAngled, FromDir, &CurDir, Includers, SearchPath, RelativePath, RequestingModule, SuggestedModule, IsMapped, IsFrameworkFound, SkipCache, BuildSystemModule); if (FE) { @@ -1827,7 +1830,7 @@ } Optional Preprocessor::LookupHeaderIncludeOrImport( - const DirectoryLookup *&CurDir, StringRef& Filename, + const DirectoryLookup **CurDir, StringRef& Filename, SourceLocation FilenameLoc, CharSourceRange FilenameRange, const Token &FilenameTok, bool &IsFrameworkFound, bool IsImportDecl, bool &IsMapped, const DirectoryLookup *LookupFrom, @@ -2028,7 +2031,7 @@ } Optional File = LookupHeaderIncludeOrImport( - CurDir, Filename, FilenameLoc, FilenameRange, FilenameTok, + &CurDir, Filename, FilenameLoc, FilenameRange, FilenameTok, IsFrameworkFound, IsImportDecl, IsMapped, LookupFrom, LookupFromFile, LookupFilename, RelativePath, SearchPath, SuggestedModule, isAngled); diff --git a/clang/lib/Lex/PPMacroExpansion.cpp b/clang/lib/Lex/PPMacroExpansion.cpp --- a/clang/lib/Lex/PPMacroExpansion.cpp +++ b/clang/lib/Lex/PPMacroExpansion.cpp @@ -1228,10 +1228,9 @@ return false; // Search include directories. - const DirectoryLookup *CurDir; Optional File = PP.LookupFile(FilenameLoc, Filename, isAngled, LookupFrom, LookupFromFile, - CurDir, nullptr, nullptr, nullptr, nullptr, nullptr); + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr); if (PPCallbacks *Callbacks = PP.getPPCallbacks()) { SrcMgr::CharacteristicKind FileType = SrcMgr::C_User; diff --git a/clang/lib/Lex/Pragma.cpp b/clang/lib/Lex/Pragma.cpp --- a/clang/lib/Lex/Pragma.cpp +++ b/clang/lib/Lex/Pragma.cpp @@ -526,9 +526,8 @@ return llvm::None; // Search include directories for this file. - const DirectoryLookup *CurDir; File = PP.LookupFile(FilenameTok.getLocation(), Filename, isAngled, nullptr, - nullptr, CurDir, nullptr, nullptr, nullptr, nullptr, + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr); if (!File) { if (!SuppressIncludeNotFoundError) diff --git a/clang/lib/Lex/Preprocessor.cpp b/clang/lib/Lex/Preprocessor.cpp --- a/clang/lib/Lex/Preprocessor.cpp +++ b/clang/lib/Lex/Preprocessor.cpp @@ -566,11 +566,10 @@ if (!PPOpts->PCHThroughHeader.empty()) { // Lookup and save the FileID for the through header. If it isn't found // in the search path, it's a fatal error. - const DirectoryLookup *CurDir; Optional File = LookupFile( SourceLocation(), PPOpts->PCHThroughHeader, - /*isAngled=*/false, /*FromDir=*/nullptr, /*FromFile=*/nullptr, CurDir, - /*SearchPath=*/nullptr, /*RelativePath=*/nullptr, + /*isAngled=*/false, /*FromDir=*/nullptr, /*FromFile=*/nullptr, + /*CurDir=*/nullptr, /*SearchPath=*/nullptr, /*RelativePath=*/nullptr, /*SuggestedModule=*/nullptr, /*IsMapped=*/nullptr, /*IsFrameworkFound=*/nullptr); if (!File) { diff --git a/clang/unittests/Lex/HeaderSearchTest.cpp b/clang/unittests/Lex/HeaderSearchTest.cpp --- a/clang/unittests/Lex/HeaderSearchTest.cpp +++ b/clang/unittests/Lex/HeaderSearchTest.cpp @@ -238,10 +238,9 @@ /*User=*/None, /*Group=*/None, llvm::sys::fs::file_type::regular_file); bool IsMapped = false; - const DirectoryLookup *CurDir = nullptr; auto FoundFile = Search.LookupFile( "Foo/Foo.h", SourceLocation(), /*isAngled=*/true, /*FromDir=*/nullptr, - CurDir, /*Includers=*/{}, /*SearchPath=*/nullptr, + /*CurDir=*/nullptr, /*Includers=*/{}, /*SearchPath=*/nullptr, /*RelativePath=*/nullptr, /*RequestingModule=*/nullptr, /*SuggestedModule=*/nullptr, &IsMapped, /*IsFrameworkFound=*/nullptr);