mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-11-01 15:17:25 +00:00
[RewriteStatepointsForGC] Fix iterator invalidation bug
Inserting into a DenseMap you're iterating over is not well defined. This is unfortunate since this is well defined on a std::map. "cleanup per llvm code style standards" bug #2 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@230827 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -684,12 +684,19 @@ static Value *findBasePointer(Value *I, DefiningValueMapTy &cache,
|
|||||||
states[def] = PhiState();
|
states[def] = PhiState();
|
||||||
// Recursively fill in all phis & selects reachable from the initial one
|
// Recursively fill in all phis & selects reachable from the initial one
|
||||||
// for which we don't already know a definite base value for
|
// for which we don't already know a definite base value for
|
||||||
// PERF: Yes, this is as horribly inefficient as it looks.
|
// TODO: This should be rewritten with a worklist
|
||||||
bool done = false;
|
bool done = false;
|
||||||
while (!done) {
|
while (!done) {
|
||||||
done = true;
|
done = true;
|
||||||
|
// Since we're adding elements to 'states' as we run, we can't keep
|
||||||
|
// iterators into the set.
|
||||||
|
SmallVector<Value*, 16> Keys;
|
||||||
|
Keys.reserve(states.size());
|
||||||
for (auto Pair : states) {
|
for (auto Pair : states) {
|
||||||
Value *v = Pair.first;
|
Value *V = Pair.first;
|
||||||
|
Keys.push_back(V);
|
||||||
|
}
|
||||||
|
for (Value *v : Keys) {
|
||||||
assert(!isKnownBaseResult(v) && "why did it get added?");
|
assert(!isKnownBaseResult(v) && "why did it get added?");
|
||||||
if (PHINode *phi = dyn_cast<PHINode>(v)) {
|
if (PHINode *phi = dyn_cast<PHINode>(v)) {
|
||||||
assert(phi->getNumIncomingValues() > 0 &&
|
assert(phi->getNumIncomingValues() > 0 &&
|
||||||
@@ -734,6 +741,7 @@ static Value *findBasePointer(Value *I, DefiningValueMapTy &cache,
|
|||||||
while (progress) {
|
while (progress) {
|
||||||
oldSize = states.size();
|
oldSize = states.size();
|
||||||
progress = false;
|
progress = false;
|
||||||
|
// We're only changing keys in this loop, thus safe to keep iterators
|
||||||
for (auto Pair : states) {
|
for (auto Pair : states) {
|
||||||
MeetPhiStates calculateMeet(states);
|
MeetPhiStates calculateMeet(states);
|
||||||
Value *v = Pair.first;
|
Value *v = Pair.first;
|
||||||
@@ -768,6 +776,7 @@ static Value *findBasePointer(Value *I, DefiningValueMapTy &cache,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Insert Phis for all conflicts
|
// Insert Phis for all conflicts
|
||||||
|
// Only changing keys in 'states', thus safe to keep iterators
|
||||||
for (auto Pair : states) {
|
for (auto Pair : states) {
|
||||||
Instruction *v = cast<Instruction>(Pair.first);
|
Instruction *v = cast<Instruction>(Pair.first);
|
||||||
PhiState state = Pair.second;
|
PhiState state = Pair.second;
|
||||||
|
|||||||
Reference in New Issue
Block a user