diff options
author | Jan Svoboda <jan_svoboda@apple.com> | 2022-02-15 10:11:00 +0100 |
---|---|---|
committer | Jan Svoboda <jan_svoboda@apple.com> | 2022-02-15 10:36:54 +0100 |
commit | 7631c366c8589dda488cb7ff1df26cc134002208 (patch) | |
tree | 447dc10e20bc2a1831d5a72db9e51bdfde8cc99c /clang/lib/Lex/HeaderSearch.cpp | |
parent | f72d8897acfcc3c8476d70353e2c4f91615ff4f0 (diff) | |
download | llvm-7631c366c8589dda488cb7ff1df26cc134002208.zip llvm-7631c366c8589dda488cb7ff1df26cc134002208.tar.gz llvm-7631c366c8589dda488cb7ff1df26cc134002208.tar.bz2 |
[clang][lex] Introduce `ConstSearchDirIterator`
The `const DirectoryLookup *` out-parameter of `{HeaderSearch,Preprocessor}::LookupFile()` is assigned the most recently used search directory, which callers use to implement `#include_next`.
From the function signature it's not obvious the `const DirectoryLookup *` is being used as an iterator. This patch introduces `ConstSearchDirIterator` to make that affordance obvious. This would've prevented a bug that occurred after initially landing D116750.
Reviewed By: ahoppen
Differential Revision: https://reviews.llvm.org/D117566
Diffstat (limited to 'clang/lib/Lex/HeaderSearch.cpp')
-rw-r--r-- | clang/lib/Lex/HeaderSearch.cpp | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/clang/lib/Lex/HeaderSearch.cpp b/clang/lib/Lex/HeaderSearch.cpp index 500f569..5e22a28 100644 --- a/clang/lib/Lex/HeaderSearch.cpp +++ b/clang/lib/Lex/HeaderSearch.cpp @@ -79,6 +79,11 @@ HeaderFileInfo::getControllingMacro(ExternalPreprocessorSource *External) { ExternalHeaderFileInfoSource::~ExternalHeaderFileInfoSource() = default; +const DirectoryLookup &ConstSearchDirIterator::operator*() const { + assert(*this && "Invalid iterator."); + return HS->SearchDirs[Idx]; +} + HeaderSearch::HeaderSearch(std::shared_ptr<HeaderSearchOptions> HSOpts, SourceManager &SourceMgr, DiagnosticsEngine &Diags, const LangOptions &LangOpts, @@ -829,14 +834,14 @@ diagnoseFrameworkInclude(DiagnosticsEngine &Diags, SourceLocation IncludeLoc, /// search is needed. Microsoft mode will pass all \#including files. Optional<FileEntryRef> HeaderSearch::LookupFile( StringRef Filename, SourceLocation IncludeLoc, bool isAngled, - const DirectoryLookup *FromDir, const DirectoryLookup **CurDirArg, + ConstSearchDirIterator FromDir, ConstSearchDirIterator *CurDirArg, ArrayRef<std::pair<const FileEntry *, const DirectoryEntry *>> Includers, SmallVectorImpl<char> *SearchPath, SmallVectorImpl<char> *RelativePath, Module *RequestingModule, ModuleMap::KnownHeader *SuggestedModule, bool *IsMapped, bool *IsFrameworkFound, bool SkipCache, bool BuildSystemModule) { - const DirectoryLookup *CurDirLocal = nullptr; - const DirectoryLookup *&CurDir = CurDirArg ? *CurDirArg : CurDirLocal; + ConstSearchDirIterator CurDirLocal = nullptr; + ConstSearchDirIterator &CurDir = CurDirArg ? *CurDirArg : CurDirLocal; if (IsMapped) *IsMapped = false; @@ -964,7 +969,7 @@ Optional<FileEntryRef> HeaderSearch::LookupFile( // If this is a #include_next request, start searching after the directory the // file was found in. if (FromDir) - i = FromDir-&SearchDirs[0]; + i = FromDir.Idx; // Cache all of the lookups performed by this method. Many headers are // multiply included, and the "pragma once" optimization prevents them from @@ -1019,7 +1024,7 @@ Optional<FileEntryRef> HeaderSearch::LookupFile( if (!File) continue; - CurDir = &SearchDirs[i]; + CurDir = ConstSearchDirIterator(*this, i); // This file is a system header or C++ unfriendly if the dir is. HeaderFileInfo &HFI = getFileInfo(&File->getFileEntry()); |