Skip to content

Commit 1ad5668

Browse files
committed
Address review comments.
1 parent 50c6fcb commit 1ad5668

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

clang/include/clang/Basic/SourceManager.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1903,7 +1903,7 @@ class SourceManager : public RefCountedBase<SourceManager> {
19031903

19041904
FileID getFileID(SourceLocation::UIntTy SLocOffset) const {
19051905
// If our one-entry cache covers this offset, just return it.
1906-
if (SLocOffset >= LastLookupStartOffset && SLocOffset < LastLookupEndOffset)
1906+
if (isOffsetInFileID(LastFileIDLookup, SLocOffset))
19071907
return LastFileIDLookup;
19081908
return getFileIDSlow(SLocOffset);
19091909
}
@@ -1927,6 +1927,10 @@ class SourceManager : public RefCountedBase<SourceManager> {
19271927
/// specified SourceLocation offset. This is a very hot method.
19281928
inline bool isOffsetInFileID(FileID FID,
19291929
SourceLocation::UIntTy SLocOffset) const {
1930+
if (FID == LastFileIDLookup)
1931+
return SLocOffset >= LastLookupStartOffset &&
1932+
SLocOffset < LastLookupEndOffset;
1933+
19301934
const SrcMgr::SLocEntry &Entry = getSLocEntry(FID);
19311935
// If the entry is after the offset, it can't contain it.
19321936
if (SLocOffset < Entry.getOffset()) return false;

clang/lib/Basic/SourceManager.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -814,8 +814,9 @@ FileID SourceManager::getFileIDSlow(SourceLocation::UIntTy SLocOffset) const {
814814
/// loaded one.
815815
FileID SourceManager::getFileIDLocal(SourceLocation::UIntTy SLocOffset) const {
816816
assert(SLocOffset < NextLocalOffset && "Bad function choice");
817-
assert(SLocOffset >= LocalSLocEntryTable[0].getOffset() &&
817+
assert(SLocOffset >= LocalSLocEntryTable[0].getOffset() && SLocOffset > 0 &&
818818
"Invalid SLocOffset");
819+
assert(LastFileIDLookup.ID >= 0 && "Only cache local file sloc entry");
819820

820821
// After the first and second level caches, I see two common sorts of
821822
// behavior: 1) a lot of searched FileID's are "near" the cached file

0 commit comments

Comments
 (0)