[MS ABI] Switch catchpad/cleanuppad to use tokens

llvm-svn: 245153
This commit is contained in:
David Majnemer 2015-08-15 03:21:08 +00:00
parent ad28aaa131
commit e888a2f655
3 changed files with 22 additions and 19 deletions

View File

@ -900,14 +900,12 @@ void CodeGenFunction::PopCleanupBlock(bool FallthroughIsBranchThrough) {
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(bool FallthroughIsBranchThrough) {
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);

View File

@ -887,11 +887,11 @@ static llvm::BasicBlock *emitMSVCCatchDispatchBlock(CodeGenFunction &CGF,
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.

View File

@ -852,11 +852,14 @@ void MicrosoftCXXABI::emitRethrow(CodeGenFunction &CGF, bool isNoReturn) {
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(CodeGenFunction &CGF,
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(CodeGenFunction &CGF,
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(CodeGenFunction &CGF,
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);
}