[llvm] r230719 - Don't modify the DenseMap being iterated over from within the loop
Sanjoy Das
sanjoy at playingwithpointers.com
Thu Feb 26 18:24:16 PST 2015
Author: sanjoy
Date: Thu Feb 26 20:24:16 2015
New Revision: 230719
URL: http://llvm.org/viewvc/llvm-project?rev=230719&view=rev
Log:
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
Modified:
llvm/trunk/lib/CodeGen/CodeGenPrepare.cpp
Modified: llvm/trunk/lib/CodeGen/CodeGenPrepare.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/CodeGenPrepare.cpp?rev=230719&r1=230718&r2=230719&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/CodeGenPrepare.cpp (original)
+++ llvm/trunk/lib/CodeGen/CodeGenPrepare.cpp Thu Feb 26 20:24:16 2015
@@ -561,12 +561,15 @@ static void computeBaseDerivedRelocateMa
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);
}
}
More information about the llvm-commits
mailing list