From: Max Kazantsev Date: Fri, 27 Oct 2017 08:19:35 +0000 (+0000) Subject: [GVN][NFC] Refactor loop iteration with foreach X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e8e122ad89e7bd5084819aba04fdeee5274fe1b1;p=llvm [GVN][NFC] Refactor loop iteration with foreach git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@316748 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Transforms/Scalar/GVN.cpp b/lib/Transforms/Scalar/GVN.cpp index 9d2c7b977f2..d7dcfd2eb16 100644 --- a/lib/Transforms/Scalar/GVN.cpp +++ b/lib/Transforms/Scalar/GVN.cpp @@ -2065,12 +2065,12 @@ bool GVN::processBlock(BasicBlock *BB) { if (!AtStart) --BI; - for (SmallVectorImpl::iterator I = InstrsToErase.begin(), - E = InstrsToErase.end(); I != E; ++I) { - DEBUG(dbgs() << "GVN removed: " << **I << '\n'); - if (MD) MD->removeInstruction(*I); - DEBUG(verifyRemoved(*I)); - (*I)->eraseFromParent(); + for (auto *I : InstrsToErase) { + assert(I->getParent() == BB && "Removing instruction from wrong block?"); + DEBUG(dbgs() << "GVN removed: " << *I << '\n'); + if (MD) MD->removeInstruction(I); + DEBUG(verifyRemoved(I)); + I->eraseFromParent(); } InstrsToErase.clear();