Skip to content
This repository was archived by the owner on Apr 23, 2020. It is now read-only.

Commit e91b6db

Browse files
committed
InferAddressSpaces: Avoid looking up deleted values
While looking at pure addressing expressions, it's possible for the value to appear later in Postorder. I haven't been able to come up with a testcase where this exhibits an actual issue, but if you insert a dump before the value map lookup, a few testcases crash. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@301705 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent afc9030 commit e91b6db

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

lib/Transforms/Scalar/InferAddressSpaces.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -815,6 +815,8 @@ bool InferAddressSpaces::rewriteWithNewAddressSpaces(
815815
NewV->setOperand(OperandNo, ValueWithNewAddrSpace.lookup(UndefUse->get()));
816816
}
817817

818+
SmallVector<Instruction *, 16> DeadInstructions;
819+
818820
// Replaces the uses of the old address expressions with the new ones.
819821
for (Value *V : Postorder) {
820822
Value *NewV = ValueWithNewAddrSpace.lookup(V);
@@ -888,7 +890,7 @@ bool InferAddressSpaces::rewriteWithNewAddressSpaces(
888890
unsigned NewAS = NewV->getType()->getPointerAddressSpace();
889891
if (ASC->getDestAddressSpace() == NewAS) {
890892
ASC->replaceAllUsesWith(NewV);
891-
ASC->eraseFromParent();
893+
DeadInstructions.push_back(ASC);
892894
continue;
893895
}
894896
}
@@ -906,10 +908,15 @@ bool InferAddressSpaces::rewriteWithNewAddressSpaces(
906908
}
907909
}
908910

909-
if (V->use_empty())
910-
RecursivelyDeleteTriviallyDeadInstructions(V);
911+
if (V->use_empty()) {
912+
if (Instruction *I = dyn_cast<Instruction>(V))
913+
DeadInstructions.push_back(I);
914+
}
911915
}
912916

917+
for (Instruction *I : DeadInstructions)
918+
RecursivelyDeleteTriviallyDeadInstructions(I);
919+
913920
return true;
914921
}
915922

0 commit comments

Comments
 (0)