From 2aca944a0ee8a469179ebf9ec38eae8ea351cb78 Mon Sep 17 00:00:00 2001 From: Andrew Kaylor Date: Thu, 12 Nov 2015 17:36:03 +0000 Subject: [PATCH] [WinEH] Fix problem with removing an element from a SetVector while iterating. Patch provided by Yaron Keren. (Thanks!) git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@252913 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/WinEHPrepare.cpp | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/lib/CodeGen/WinEHPrepare.cpp b/lib/CodeGen/WinEHPrepare.cpp index a4e10d908fe..87713f65671 100644 --- a/lib/CodeGen/WinEHPrepare.cpp +++ b/lib/CodeGen/WinEHPrepare.cpp @@ -1665,18 +1665,12 @@ void WinEHPrepare::cloneCommonBlocks( // Remove this block from the FuncletBlocks set of any funclet that // isn't the funclet whose color we just selected. - for (auto It = BlockColors[BB].begin(), End = BlockColors[BB].end(); - It != End; ) { - // The iterator must be incremented here because we are removing - // elements from the set we're walking. - auto Temp = It++; - BasicBlock *ContainingFunclet = *Temp; - if (ContainingFunclet != CorrectColor) { + for (BasicBlock *ContainingFunclet : BlockColors[BB]) + if (ContainingFunclet != CorrectColor) FuncletBlocks[ContainingFunclet].erase(BB); - BlockColors[BB].remove(ContainingFunclet); - } - } - + BlockColors[BB].remove_if([&](BasicBlock *ContainingFunclet) { + return ContainingFunclet != CorrectColor; + }); // This should leave just one color for BB. assert(BlockColors[BB].size() == 1); continue; -- 2.34.1