r245153 - [MS ABI] Switch catchpad/cleanuppad to use tokens

David Majnemer via cfe-commits cfe-commits at lists.llvm.org
Fri Aug 14 20:21:08 PDT 2015


Author: majnemer
Date: Fri Aug 14 22:21:08 2015
New Revision: 245153

URL: http://llvm.org/viewvc/llvm-project?rev=245153&view=rev
Log:
[MS ABI] Switch catchpad/cleanuppad to use tokens

Modified:
    cfe/trunk/lib/CodeGen/CGCleanup.cpp
    cfe/trunk/lib/CodeGen/CGException.cpp
    cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp

Modified: cfe/trunk/lib/CodeGen/CGCleanup.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCleanup.cpp?rev=245153&r1=245152&r2=245153&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGCleanup.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCleanup.cpp Fri Aug 14 22:21:08 2015
@@ -900,14 +900,12 @@ void CodeGenFunction::PopCleanupBlock(bo
     CGBuilderTy::InsertPoint SavedIP = Builder.saveAndClearIP();
 
     EmitBlock(EHEntry);
+    llvm::CleanupPadInst *CPI = nullptr;
     llvm::BasicBlock *NextAction = getEHDispatchBlock(EHParent);
     if (CGM.getCodeGenOpts().NewMSEH &&
-        EHPersonality::get(*this).isMSVCPersonality()) {
-      if (NextAction)
-        Builder.CreateCleanupPad(VoidTy, NextAction);
-      else
-        Builder.CreateCleanupPad(VoidTy, {});
-    }
+        EHPersonality::get(*this).isMSVCPersonality())
+      CPI = Builder.CreateCleanupPad(llvm::Type::getTokenTy(getLLVMContext()),
+                                     {});
 
     // We only actually emit the cleanup code if the cleanup is either
     // active or was used before it was deactivated.
@@ -917,8 +915,8 @@ void CodeGenFunction::PopCleanupBlock(bo
       EmitCleanup(*this, Fn, cleanupFlags, EHActiveFlag);
     }
 
-    if (CGM.getCodeGenOpts().NewMSEH && EHPersonality::get(*this).isMSVCPersonality())
-      Builder.CreateCleanupRet(NextAction);
+    if (CPI)
+      Builder.CreateCleanupRet(NextAction, CPI);
     else
       Builder.CreateBr(NextAction);
 

Modified: cfe/trunk/lib/CodeGen/CGException.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGException.cpp?rev=245153&r1=245152&r2=245153&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGException.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGException.cpp Fri Aug 14 22:21:08 2015
@@ -887,11 +887,11 @@ static llvm::BasicBlock *emitMSVCCatchDi
 
     if (EHPersonality::get(CGF).isMSVCXXPersonality()) {
       CGF.Builder.CreateCatchPad(
-          CGF.VoidTy, Handler.Block, NextBlock,
-          {TypeValue, llvm::Constant::getNullValue(CGF.VoidPtrTy)});
+          llvm::Type::getTokenTy(CGF.getLLVMContext()), Handler.Block,
+          NextBlock, {TypeValue, llvm::Constant::getNullValue(CGF.VoidPtrTy)});
     } else {
-      CGF.Builder.CreateCatchPad(CGF.VoidTy, Handler.Block, NextBlock,
-                                 {TypeValue});
+      CGF.Builder.CreateCatchPad(llvm::Type::getTokenTy(CGF.getLLVMContext()),
+                                 Handler.Block, NextBlock, {TypeValue});
     }
 
     // Otherwise we need to emit and continue at that block.

Modified: cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp?rev=245153&r1=245152&r2=245153&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp (original)
+++ cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp Fri Aug 14 22:21:08 2015
@@ -852,11 +852,14 @@ void MicrosoftCXXABI::emitRethrow(CodeGe
 
 namespace {
 struct CallEndCatchMSVC : EHScopeStack::Cleanup {
-  CallEndCatchMSVC() {}
+  llvm::CatchPadInst *CPI;
+
+  CallEndCatchMSVC(llvm::CatchPadInst *CPI) : CPI(CPI) {}
+
   void Emit(CodeGenFunction &CGF, Flags flags) override {
     if (CGF.CGM.getCodeGenOpts().NewMSEH) {
       llvm::BasicBlock *BB = CGF.createBasicBlock("catchret.dest");
-      CGF.Builder.CreateCatchRet(BB);
+      CGF.Builder.CreateCatchRet(BB, CPI);
       CGF.EmitBlock(BB);
     } else {
       CGF.EmitNounwindRuntimeCall(
@@ -873,10 +876,15 @@ void MicrosoftCXXABI::emitBeginCatch(Cod
   VarDecl *CatchParam = S->getExceptionDecl();
   llvm::Value *Exn = nullptr;
   llvm::Function *BeginCatch = nullptr;
+  llvm::CatchPadInst *CPI = nullptr;
   bool NewEH = CGF.CGM.getCodeGenOpts().NewMSEH;
   if (!NewEH) {
     Exn = CGF.getExceptionFromSlot();
     BeginCatch = CGF.CGM.getIntrinsic(llvm::Intrinsic::eh_begincatch);
+  } else {
+    llvm::BasicBlock *CatchPadBB =
+        CGF.Builder.GetInsertBlock()->getSinglePredecessor();
+    CPI = cast<llvm::CatchPadInst>(CatchPadBB->getFirstNonPHI());
   }
   // If this is a catch-all or the catch parameter is unnamed, we don't need to
   // emit an alloca to the object.
@@ -885,7 +893,7 @@ void MicrosoftCXXABI::emitBeginCatch(Cod
       llvm::Value *Args[2] = {Exn, llvm::Constant::getNullValue(CGF.Int8PtrTy)};
       CGF.EmitNounwindRuntimeCall(BeginCatch, Args);
     }
-    CGF.EHStack.pushCleanup<CallEndCatchMSVC>(NormalCleanup);
+    CGF.EHStack.pushCleanup<CallEndCatchMSVC>(NormalCleanup, CPI);
     return;
   }
 
@@ -896,12 +904,9 @@ void MicrosoftCXXABI::emitBeginCatch(Cod
     llvm::Value *Args[2] = {Exn, ParamAddr};
     CGF.EmitNounwindRuntimeCall(BeginCatch, Args);
   } else {
-    llvm::BasicBlock *CatchPadBB =
-        CGF.Builder.GetInsertBlock()->getSinglePredecessor();
-    auto *CPI = cast<llvm::CatchPadInst>(CatchPadBB->getFirstNonPHI());
     CPI->setArgOperand(1, var.getObjectAddress(CGF));
   }
-  CGF.EHStack.pushCleanup<CallEndCatchMSVC>(NormalCleanup);
+  CGF.EHStack.pushCleanup<CallEndCatchMSVC>(NormalCleanup, CPI);
   CGF.EmitAutoVarCleanups(var);
 }
 




More information about the cfe-commits mailing list