Don't modify the DenseMap being iterated over from within the loop

that is iterating over it

Inserting elements into a `DenseMap` invalidated iterators pointing
into the `DenseMap` instance.

Differential Revision: http://reviews.llvm.org/D7924


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@230719 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Sanjoy Das 2015-02-27 02:24:16 +00:00
parent 26f67b5a27
commit 791a501266

View File

@ -561,12 +561,15 @@ static void computeBaseDerivedRelocateMap(
IntrinsicInst *I = Item.second;
auto BaseKey = std::make_pair(Key.first, Key.first);
IntrinsicInst *Base = RelocateIdxMap[BaseKey];
if (!Base)
// We're iterating over RelocateIdxMap so we cannot modify it.
auto MaybeBase = RelocateIdxMap.find(BaseKey);
if (MaybeBase == RelocateIdxMap.end())
// TODO: We might want to insert a new base object relocate and gep off
// that, if there are enough derived object relocates.
continue;
RelocateInstMap[Base].push_back(I);
RelocateInstMap[MaybeBase->second].push_back(I);
}
}