diff options
author | Jan Svoboda <jan_svoboda@apple.com> | 2022-03-22 17:03:58 +0100 |
---|---|---|
committer | Jan Svoboda <jan_svoboda@apple.com> | 2022-03-23 14:49:17 +0100 |
commit | 59dadd178b0b12cb4a975a262ed20e7c3822aedc (patch) | |
tree | c22de76253e94a64bbe485cbf42ce75e75196457 /clang/lib/Lex/HeaderSearch.cpp | |
parent | 9a6e0afac5bf117bdd0bbc82937e04f0edb7f305 (diff) | |
download | llvm-59dadd178b0b12cb4a975a262ed20e7c3822aedc.zip llvm-59dadd178b0b12cb4a975a262ed20e7c3822aedc.tar.gz llvm-59dadd178b0b12cb4a975a262ed20e7c3822aedc.tar.bz2 |
[clang][lex] Fix failures with Microsoft header search rules
`HeaderSearch` currently assumes `LookupFileCache` is eventually populated in `LookupFile`. However, that's not always the case with `-fms-compatibility` and its early returns.
This patch adds a defensive check that the iterator pulled out of the cache is actually valid before using it.
(This bug was introduced in D119721. Before that, the cache was initialized to `0` - essentially the `search_dir_begin()` iterator.)
Reviewed By: dexonsmith, erichkeane
Differential Revision: https://reviews.llvm.org/D122237
Diffstat (limited to 'clang/lib/Lex/HeaderSearch.cpp')
-rw-r--r-- | clang/lib/Lex/HeaderSearch.cpp | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/clang/lib/Lex/HeaderSearch.cpp b/clang/lib/Lex/HeaderSearch.cpp index 087bd1d..082e62d 100644 --- a/clang/lib/Lex/HeaderSearch.cpp +++ b/clang/lib/Lex/HeaderSearch.cpp @@ -976,7 +976,8 @@ Optional<FileEntryRef> HeaderSearch::LookupFile( // this is a matching hit. if (!SkipCache && CacheLookup.StartIt == NextIt) { // Skip querying potentially lots of directories for this lookup. - It = CacheLookup.HitIt; + if (CacheLookup.HitIt) + It = CacheLookup.HitIt; if (CacheLookup.MappedName) { Filename = CacheLookup.MappedName; if (IsMapped) |