ivanmurashko created this revision. ivanmurashko added reviewers: dexonsmith, aaron.ballman. ivanmurashko added a project: clang. Herald added subscribers: usaxena95, kadircet. Herald added a project: All. ivanmurashko requested review of this revision. Herald added subscribers: cfe-commits, ilya-biryukov.
The `getSLocEntry` might return `SourceManager::FakeSLocEntryForRecovery` introduced at D89748 <https://reviews.llvm.org/D89748>. The result entry is not tested and as result the call return SLocOffset < getSLocEntryByID(FID.ID+1).getOffset(); might return `true` value. That would mark the tested offset as one that belongs to the fake `SLockEntry`. It might cause a weird clangd crash when preamble contains some header files that were removed just after the preamble created. Unfortunately it's not so easy to reproduce the crash in the form of a LIT test thus I provided the fix only. Test Plan: ninja check-clang Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D130847 Files: clang/include/clang/Basic/SourceManager.h Index: clang/include/clang/Basic/SourceManager.h =================================================================== --- clang/include/clang/Basic/SourceManager.h +++ 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;
Index: clang/include/clang/Basic/SourceManager.h =================================================================== --- clang/include/clang/Basic/SourceManager.h +++ 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;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits