From 7d3dd38582fb7a2d4133edc9a06f8581e5d8988f Mon Sep 17 00:00:00 2001 From: Andrew Kaylor Date: Fri, 24 Apr 2015 23:10:38 +0000 Subject: [PATCH] [WinEH] Find correct cloned entry block for outlined handler functions. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@235789 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/WinEHPrepare.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/CodeGen/WinEHPrepare.cpp b/lib/CodeGen/WinEHPrepare.cpp index 072aea77900..1325821d498 100644 --- a/lib/CodeGen/WinEHPrepare.cpp +++ b/lib/CodeGen/WinEHPrepare.cpp @@ -1179,10 +1179,19 @@ bool WinEHPrepare::outlineHandler(ActionHandler *Action, Function *SrcFn, /*ModuleLevelChanges=*/false, Returns, "", &OutlinedFunctionInfo, Director.get()); - // Move all the instructions in the first cloned block into our entry block. - BasicBlock *FirstClonedBB = std::next(Function::iterator(Entry)); - Entry->getInstList().splice(Entry->end(), FirstClonedBB->getInstList()); - FirstClonedBB->eraseFromParent(); + // Move all the instructions in the cloned "entry" block into our entry block. + // Depending on how the parent function was laid out, the block that will + // correspond to the outlined entry block may not be the first block in the + // list. We can recognize it, however, as the cloned block which has no + // predecessors. Any other block wouldn't have been cloned if it didn't + // have a predecessor which was also cloned. + Function::iterator ClonedIt = std::next(Function::iterator(Entry)); + while (!pred_empty(ClonedIt)) + ++ClonedIt; + BasicBlock *ClonedEntryBB = ClonedIt; + assert(ClonedEntryBB); + Entry->getInstList().splice(Entry->end(), ClonedEntryBB->getInstList()); + ClonedEntryBB->eraseFromParent(); // Make sure we can identify the handler's personality later. addStubInvokeToHandlerIfNeeded(Handler, LPad->getPersonalityFn()); -- 2.49.0