From 8430a4545c2743568aee94c39e3912795ce463ec Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sat, 19 Jun 2004 02:02:22 +0000 Subject: [PATCH] Do not loop over uses as we delete them. This causes iterators to be invalidated out from under us. This bug goes back to revision 1.1: scary. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14242 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/Scalar/ScalarReplAggregates.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/Transforms/Scalar/ScalarReplAggregates.cpp b/lib/Transforms/Scalar/ScalarReplAggregates.cpp index 9598918880a..aeba94afa1d 100644 --- a/lib/Transforms/Scalar/ScalarReplAggregates.cpp +++ b/lib/Transforms/Scalar/ScalarReplAggregates.cpp @@ -171,9 +171,8 @@ bool SROA::performScalarRepl(Function &F) { // Now that we have created the alloca instructions that we want to use, // expand the getelementptr instructions to use them. // - for (Value::use_iterator I = AI->use_begin(), E = AI->use_end(); - I != E; ++I) { - Instruction *User = cast(*I); + while (!AI->use_empty()) { + Instruction *User = cast(AI->use_back()); if (GetElementPtrInst *GEPI = dyn_cast(User)) { // We now know that the GEP is of the form: GEP , 0, uint64_t Idx = cast(GEPI->getOperand(2))->getRawValue();