aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Lex/HeaderSearch.cpp
diff options
context:
space:
mode:
authorJan Svoboda <jan_svoboda@apple.com>2022-03-22 17:03:58 +0100
committerJan Svoboda <jan_svoboda@apple.com>2022-03-23 14:49:17 +0100
commit59dadd178b0b12cb4a975a262ed20e7c3822aedc (patch)
treec22de76253e94a64bbe485cbf42ce75e75196457 /clang/lib/Lex/HeaderSearch.cpp
parent9a6e0afac5bf117bdd0bbc82937e04f0edb7f305 (diff)
downloadllvm-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.cpp3
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)