From 90456d2ef5610ffdd6ed72483a54cad1f06b4e87 Mon Sep 17 00:00:00 2001 From: Chandler Carruth Date: Fri, 15 Nov 2013 21:56:44 +0000 Subject: [PATCH] [PM] Fix an iterator problem spotted by the MSVC debug iterators and AaronBallman. Thanks for the excellent review. llvm-svn: 194857 --- lib/IR/PassManager.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/lib/IR/PassManager.cpp b/lib/IR/PassManager.cpp index f706a0dc80b..966af7debc7 100644 --- a/lib/IR/PassManager.cpp +++ b/lib/IR/PassManager.cpp @@ -47,11 +47,12 @@ void AnalysisManager::invalidateAll(Function *F) { FunctionAnalysisResultListT &ResultsList = FunctionAnalysisResultLists[F]; for (FunctionAnalysisResultListT::iterator I = ResultsList.begin(), E = ResultsList.end(); - I != E; ++I) + I != E;) if (I->second->invalidate(F)) { - FunctionAnalysisResultListT::iterator Old = I--; - InvalidatedPassIDs.push_back(Old->first); - ResultsList.erase(Old); + InvalidatedPassIDs.push_back(I->first); + I = ResultsList.erase(I); + } else { + ++I; } while (!InvalidatedPassIDs.empty()) FunctionAnalysisResults.erase( @@ -80,11 +81,12 @@ void AnalysisManager::invalidateAll(Module *M) { FunctionAnalysisResultListT &ResultsList = FI->second; for (FunctionAnalysisResultListT::iterator I = ResultsList.begin(), E = ResultsList.end(); - I != E; ++I) + I != E;) if (I->second->invalidate(F)) { - FunctionAnalysisResultListT::iterator Old = I--; - InvalidatedPassIDs.push_back(Old->first); - ResultsList.erase(Old); + InvalidatedPassIDs.push_back(I->first); + I = ResultsList.erase(I); + } else { + ++I; } while (!InvalidatedPassIDs.empty()) FunctionAnalysisResults.erase(