diff --git a/clang/include/clang/Basic/SourceManager.h b/clang/include/clang/Basic/SourceManager.h --- a/clang/include/clang/Basic/SourceManager.h +++ b/clang/include/clang/Basic/SourceManager.h @@ -1825,7 +1825,13 @@ /// specified SourceLocation offset. This is a very hot method. inline bool isOffsetInFileID(FileID FID, SourceLocation::UIntTy SLocOffset) const { - const SrcMgr::SLocEntry &Entry = getSLocEntry(FID); + bool Invalid = false; + const SrcMgr::SLocEntry &Entry = getSLocEntry(FID, &Invalid); + + // If the entry is invalid, it can't contain it. + if (Invalid) + return false; + // If the entry is after the offset, it can't contain it. if (SLocOffset < Entry.getOffset()) return false;