[SourceManager] Explicitly check for potential iterator underflow

Differential Revision: https://reviews.llvm.org/D86231
This commit is contained in:
Jan Korous 2020-08-18 22:36:16 -07:00
parent a4e35cc2ec
commit ae726fecae
1 changed files with 5 additions and 0 deletions

View File

@ -1936,6 +1936,11 @@ SourceManager::getMacroArgExpandedLocation(SourceLocation Loc) const {
assert(!MacroArgsCache->empty());
MacroArgsMap::iterator I = MacroArgsCache->upper_bound(Offset);
// In case every element in MacroArgsCache is greater than Offset we can't
// decrement the iterator.
if (I == MacroArgsCache->begin())
return Loc;
--I;
unsigned MacroArgBeginOffs = I->first;