[WinEH] Update CoreCLR EH for catchpad MBBs
authorJoseph Tremoulet <jotrem@microsoft.com>
Wed, 7 Oct 2015 17:16:25 +0000 (17:16 +0000)
committerJoseph Tremoulet <jotrem@microsoft.com>
Wed, 7 Oct 2015 17:16:25 +0000 (17:16 +0000)
Summary:
Set the pad MBB as a funclet entry for CoreCLR as well as MSVCCXX, and
update state numbering to put the catchpad block rather than its normal
successor into the unwind map.

Reviewers: majnemer

Subscribers: llvm-commits

Differential Revision: http://reviews.llvm.org/D13492

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@249569 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
lib/CodeGen/WinEHPrepare.cpp

index ed96742..9e31519 100644 (file)
@@ -1163,9 +1163,10 @@ void SelectionDAGBuilder::visitCatchPad(const CatchPadInst &I) {
   auto Pers = classifyEHPersonality(FuncInfo.Fn->getPersonalityFn());
   bool IsMSVCCXX = Pers == EHPersonality::MSVC_CXX;
   bool IsSEH = isAsynchronousEHPersonality(Pers);
+  bool IsCoreCLR = Pers == EHPersonality::CoreCLR;
   MachineBasicBlock *CatchPadMBB = FuncInfo.MBB;
-  // In MSVC C++, catchblocks are funclets and need prologues.
-  if (IsMSVCCXX)
+  // In MSVC C++ and CoreCLR, catchblocks are funclets and need prologues.
+  if (IsMSVCCXX || IsCoreCLR)
     CatchPadMBB->setIsEHFuncletEntry();
 
   MachineBasicBlock *NormalDestMBB = FuncInfo.MBBMap[I.getNormalDest()];
index 86b511c..3f930c8 100644 (file)
@@ -2928,11 +2928,11 @@ void llvm::calculateClrEHStateNumbers(const Function *Fn,
       // Preds of the endpad should get the parent state.
       PredState = ParentState;
     } else if (const CatchPadInst *Catch = dyn_cast<CatchPadInst>(Pad)) {
-      const BasicBlock *Handler = Catch->getNormalDest();
+      const BasicBlock *PadBlock = Catch->getParent();
       uint32_t TypeToken = static_cast<uint32_t>(
           cast<ConstantInt>(Catch->getArgOperand(0))->getZExtValue());
       int NewState = addClrEHHandler(FuncInfo, ParentState,
-                                     ClrHandlerType::Catch, TypeToken, Handler);
+                                     ClrHandlerType::Catch, TypeToken, PadBlock);
       FuncInfo.EHPadStateMap[Catch] = NewState;
       // Preds of the catch get its state
       PredState = NewState;