In SourceManager::getFileIDLoaded(), add some sanity checks to make sure we don't enter an infinite loop.

rdar://13120919

llvm-svn: 176331
This commit is contained in:
Argyrios Kyrtzidis 2013-03-01 03:26:00 +00:00
parent e9e588dd72
commit 7dc4f33c77
1 changed files with 7 additions and 0 deletions

View File

@ -840,10 +840,17 @@ FileID SourceManager::getFileIDLoaded(unsigned SLocOffset) const {
++NumProbes;
unsigned MiddleIndex = (LessIndex - GreaterIndex) / 2 + GreaterIndex;
const SrcMgr::SLocEntry &E = getLoadedSLocEntry(MiddleIndex);
if (E.getOffset() == 0)
return FileID(); // invalid entry.
++NumProbes;
if (E.getOffset() > SLocOffset) {
// Sanity checking, otherwise a bug may lead to hanging in release build.
if (GreaterIndex == MiddleIndex) {
assert(0 && "binary search missed the entry");
return FileID();
}
GreaterIndex = MiddleIndex;
continue;
}