diff --git a/lib/Transforms/Scalar/DCE.cpp b/lib/Transforms/Scalar/DCE.cpp index cb78207d760..fb9a0e04fd6 100644 --- a/lib/Transforms/Scalar/DCE.cpp +++ b/lib/Transforms/Scalar/DCE.cpp @@ -111,11 +111,12 @@ bool DCE::runOnFunction(Function &F) { // Remove the instruction from the worklist if it still exists in it. for (std::vector::iterator WI = WorkList.begin(); - WI != WorkList.end(); ++WI) - if (*WI == I) { + WI != WorkList.end(); ) { + if (*WI == I) WI = WorkList.erase(WI); - --WI; - } + else + ++WI; + } MadeChange = true; ++DCEEliminated;