summaryrefslogtreecommitdiffstats
path: root/clang/lib
diff options
context:
space:
mode:
authorReid Kleckner <rnk@google.com>2015-10-08 01:13:52 +0000
committerReid Kleckner <rnk@google.com>2015-10-08 01:13:52 +0000
commit129552b3757fa15f5e2f8ead1b1e24684f183574 (patch)
treecb282daf5ede313fa6aa705d7ff6a555dda7f42a /clang/lib
parent3b804877fd7e3270b1c53f1de9adce5fb0cbd380 (diff)
downloadbcm5719-llvm-129552b3757fa15f5e2f8ead1b1e24684f183574.tar.gz
bcm5719-llvm-129552b3757fa15f5e2f8ead1b1e24684f183574.zip
[WinEH] Remove NewMSEH and enable its behavior by default
Testing has shown that it is at least as reliable as the old landingpad pattern matching code. llvm-svn: 249647
Diffstat (limited to 'clang/lib')
-rw-r--r--clang/lib/CodeGen/CGCleanup.cpp3
-rw-r--r--clang/lib/CodeGen/CGCleanup.h4
-rw-r--r--clang/lib/CodeGen/CGException.cpp64
-rw-r--r--clang/lib/CodeGen/MicrosoftCXXABI.cpp49
-rw-r--r--clang/lib/Frontend/CompilerInvocation.cpp1
5 files changed, 44 insertions, 77 deletions
diff --git a/clang/lib/CodeGen/CGCleanup.cpp b/clang/lib/CodeGen/CGCleanup.cpp
index 31c870ff6f6..5796320894b 100644
--- a/clang/lib/CodeGen/CGCleanup.cpp
+++ b/clang/lib/CodeGen/CGCleanup.cpp
@@ -933,8 +933,7 @@ void CodeGenFunction::PopCleanupBlock(bool FallthroughIsBranchThrough) {
EmitBlock(EHEntry);
llvm::CleanupPadInst *CPI = nullptr;
llvm::BasicBlock *NextAction = getEHDispatchBlock(EHParent);
- if (CGM.getCodeGenOpts().NewMSEH &&
- EHPersonality::get(*this).isMSVCPersonality())
+ if (EHPersonality::get(*this).usesFuncletPads())
CPI = Builder.CreateCleanupPad({});
// We only actually emit the cleanup code if the cleanup is either
diff --git a/clang/lib/CodeGen/CGCleanup.h b/clang/lib/CodeGen/CGCleanup.h
index 51b33f43e90..5a0145eb0b8 100644
--- a/clang/lib/CodeGen/CGCleanup.h
+++ b/clang/lib/CodeGen/CGCleanup.h
@@ -633,6 +633,10 @@ struct EHPersonality {
static const EHPersonality MSVC_C_specific_handler;
static const EHPersonality MSVC_CxxFrameHandler3;
+ /// Does this personality use landingpads or the family of pad instructions
+ /// designed to form funclets?
+ bool usesFuncletPads() const { return isMSVCPersonality(); }
+
bool isMSVCPersonality() const {
return this == &MSVC_except_handler || this == &MSVC_C_specific_handler ||
this == &MSVC_CxxFrameHandler3;
diff --git a/clang/lib/CodeGen/CGException.cpp b/clang/lib/CodeGen/CGException.cpp
index 2490098d67c..16f6e83647b 100644
--- a/clang/lib/CodeGen/CGException.cpp
+++ b/clang/lib/CodeGen/CGException.cpp
@@ -572,8 +572,7 @@ void CodeGenFunction::EnterCXXTryStmt(const CXXTryStmt &S, bool IsFnTryBlock) {
llvm::BasicBlock *
CodeGenFunction::getEHDispatchBlock(EHScopeStack::stable_iterator si) {
- if (CGM.getCodeGenOpts().NewMSEH &&
- EHPersonality::get(*this).isMSVCPersonality())
+ if (EHPersonality::get(*this).usesFuncletPads())
return getMSVCDispatchBlock(si);
// The dispatch block for the end of the scope chain is a block that
@@ -705,8 +704,8 @@ llvm::BasicBlock *CodeGenFunction::getInvokeDestImpl() {
if (!CurFn->hasPersonalityFn())
CurFn->setPersonalityFn(getOpaquePersonalityFn(CGM, Personality));
- if (CGM.getCodeGenOpts().NewMSEH && Personality.isMSVCPersonality()) {
- // We don't need separate landing pads in the MSVC model.
+ if (Personality.usesFuncletPads()) {
+ // We don't need separate landing pads in the funclet model.
LP = getEHDispatchBlock(EHStack.getInnermostEHScope());
} else {
// Build the landing pad for this scope.
@@ -870,8 +869,8 @@ llvm::BasicBlock *CodeGenFunction::EmitLandingPad() {
return lpad;
}
-static llvm::BasicBlock *emitMSVCCatchDispatchBlock(CodeGenFunction &CGF,
- EHCatchScope &CatchScope) {
+static llvm::BasicBlock *emitCatchPadBlock(CodeGenFunction &CGF,
+ EHCatchScope &CatchScope) {
llvm::BasicBlock *DispatchBlock = CatchScope.getCachedEHDispatchBlock();
assert(DispatchBlock);
@@ -922,9 +921,8 @@ static llvm::BasicBlock *emitMSVCCatchDispatchBlock(CodeGenFunction &CGF,
/// block holding the final catchendblock instruction is returned.
static llvm::BasicBlock *emitCatchDispatchBlock(CodeGenFunction &CGF,
EHCatchScope &catchScope) {
- if (CGF.CGM.getCodeGenOpts().NewMSEH &&
- EHPersonality::get(CGF).isMSVCPersonality())
- return emitMSVCCatchDispatchBlock(CGF, catchScope);
+ if (EHPersonality::get(CGF).usesFuncletPads())
+ return emitCatchPadBlock(CGF, catchScope);
llvm::BasicBlock *dispatchBlock = catchScope.getCachedEHDispatchBlock();
assert(dispatchBlock);
@@ -1337,8 +1335,7 @@ llvm::BasicBlock *CodeGenFunction::getTerminateHandler() {
// end of the function by FinishFunction.
TerminateHandler = createBasicBlock("terminate.handler");
Builder.SetInsertPoint(TerminateHandler);
- if (CGM.getCodeGenOpts().NewMSEH &&
- EHPersonality::get(*this).isMSVCPersonality()) {
+ if (EHPersonality::get(*this).usesFuncletPads()) {
Builder.CreateTerminatePad(/*UnwindBB=*/nullptr, CGM.getTerminateFn());
} else {
llvm::Value *Exn = nullptr;
@@ -1441,8 +1438,8 @@ struct PerformSEHFinally final : EHScopeStack::Cleanup {
CGM.getTypes().arrangeFreeFunctionCall(Args, FPT,
/*chainCall=*/false);
- // If this is the normal cleanup or using the old EH IR, just emit the call.
- if (!F.isForEHCleanup() || !CGM.getCodeGenOpts().NewMSEH) {
+ // If this is the normal cleanup, just emit the call.
+ if (!F.isForEHCleanup()) {
CGF.EmitCall(FnInfo, OutlinedFinally, ReturnValueSlot(), Args);
return;
}
@@ -1888,31 +1885,22 @@ void CodeGenFunction::ExitSEHTryStmt(const SEHTryStmt &S) {
EmitBlockAfterUses(ExceptBB);
- if (CGM.getCodeGenOpts().NewMSEH) {
- // __except blocks don't get outlined into funclets, so immediately do a
- // catchret.
- llvm::BasicBlock *CatchPadBB = ExceptBB->getSinglePredecessor();
- assert(CatchPadBB && "only ExceptBB pred should be catchpad");
- llvm::CatchPadInst *CPI =
- cast<llvm::CatchPadInst>(CatchPadBB->getFirstNonPHI());
- ExceptBB = createBasicBlock("__except");
- Builder.CreateCatchRet(CPI, ExceptBB);
- EmitBlock(ExceptBB);
- // On Win64, the exception code is returned in EAX. Copy it into the slot.
- if (CGM.getTarget().getTriple().getArch() != llvm::Triple::x86) {
- llvm::Function *SEHCodeIntrin =
- CGM.getIntrinsic(llvm::Intrinsic::eh_exceptioncode);
- llvm::Value *Code = Builder.CreateCall(SEHCodeIntrin, {CPI});
- Builder.CreateStore(Code, SEHCodeSlotStack.back());
- }
- } else {
- // On Win64, the exception pointer is the exception code. Copy it to the slot.
- if (CGM.getTarget().getTriple().getArch() != llvm::Triple::x86) {
- llvm::Value *Code =
- Builder.CreatePtrToInt(getExceptionFromSlot(), IntPtrTy);
- Code = Builder.CreateTrunc(Code, Int32Ty);
- Builder.CreateStore(Code, SEHCodeSlotStack.back());
- }
+ // __except blocks don't get outlined into funclets, so immediately do a
+ // catchret.
+ llvm::BasicBlock *CatchPadBB = ExceptBB->getSinglePredecessor();
+ assert(CatchPadBB && "only ExceptBB pred should be catchpad");
+ llvm::CatchPadInst *CPI =
+ cast<llvm::CatchPadInst>(CatchPadBB->getFirstNonPHI());
+ ExceptBB = createBasicBlock("__except");
+ Builder.CreateCatchRet(CPI, ExceptBB);
+ EmitBlock(ExceptBB);
+
+ // On Win64, the exception code is returned in EAX. Copy it into the slot.
+ if (CGM.getTarget().getTriple().getArch() != llvm::Triple::x86) {
+ llvm::Function *SEHCodeIntrin =
+ CGM.getIntrinsic(llvm::Intrinsic::eh_exceptioncode);
+ llvm::Value *Code = Builder.CreateCall(SEHCodeIntrin, {CPI});
+ Builder.CreateStore(Code, SEHCodeSlotStack.back());
}
// Emit the __except body.
diff --git a/clang/lib/CodeGen/MicrosoftCXXABI.cpp b/clang/lib/CodeGen/MicrosoftCXXABI.cpp
index 504dc3fa09b..369d21f3988 100644
--- a/clang/lib/CodeGen/MicrosoftCXXABI.cpp
+++ b/clang/lib/CodeGen/MicrosoftCXXABI.cpp
@@ -879,20 +879,15 @@ void MicrosoftCXXABI::emitRethrow(CodeGenFunction &CGF, bool isNoReturn) {
}
namespace {
-struct CallEndCatchMSVC final : EHScopeStack::Cleanup {
+struct CatchRetScope final : EHScopeStack::Cleanup {
llvm::CatchPadInst *CPI;
- CallEndCatchMSVC(llvm::CatchPadInst *CPI) : CPI(CPI) {}
+ CatchRetScope(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(CPI, BB);
- CGF.EmitBlock(BB);
- } else {
- CGF.EmitNounwindRuntimeCall(
- CGF.CGM.getIntrinsic(llvm::Intrinsic::eh_endcatch));
- }
+ llvm::BasicBlock *BB = CGF.createBasicBlock("catchret.dest");
+ CGF.Builder.CreateCatchRet(CPI, BB);
+ CGF.EmitBlock(BB);
}
};
}
@@ -902,39 +897,21 @@ void MicrosoftCXXABI::emitBeginCatch(CodeGenFunction &CGF,
// In the MS ABI, the runtime handles the copy, and the catch handler is
// responsible for destruction.
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());
- }
+ llvm::BasicBlock *CatchPadBB =
+ CGF.Builder.GetInsertBlock()->getSinglePredecessor();
+ llvm::CatchPadInst *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.
if (!CatchParam || !CatchParam->getDeclName()) {
- if (!NewEH) {
- llvm::Value *Args[2] = {Exn, llvm::Constant::getNullValue(CGF.Int8PtrTy)};
- CGF.EmitNounwindRuntimeCall(BeginCatch, Args);
- }
- CGF.EHStack.pushCleanup<CallEndCatchMSVC>(NormalCleanup, CPI);
+ CGF.EHStack.pushCleanup<CatchRetScope>(NormalCleanup, CPI);
return;
}
CodeGenFunction::AutoVarEmission var = CGF.EmitAutoVarAlloca(*CatchParam);
- if (!NewEH) {
- Address ParamAddr =
- CGF.Builder.CreateElementBitCast(var.getObjectAddress(CGF), CGF.Int8Ty);
- llvm::Value *Args[2] = {Exn, ParamAddr.getPointer()};
- CGF.EmitNounwindRuntimeCall(BeginCatch, Args);
- } else {
- CPI->setArgOperand(2, var.getObjectAddress(CGF).getPointer());
- }
- CGF.EHStack.pushCleanup<CallEndCatchMSVC>(NormalCleanup, CPI);
+ CPI->setArgOperand(2, var.getObjectAddress(CGF).getPointer());
+ CGF.EHStack.pushCleanup<CatchRetScope>(NormalCleanup, CPI);
CGF.EmitAutoVarCleanups(var);
}
diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp
index a1afd80f699..8a7e879d07b 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -462,7 +462,6 @@ static bool ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, InputKind IK,
Opts.DumpCoverageMapping = Args.hasArg(OPT_dump_coverage_mapping);
Opts.AsmVerbose = Args.hasArg(OPT_masm_verbose);
Opts.ObjCAutoRefCountExceptions = Args.hasArg(OPT_fobjc_arc_exceptions);
- Opts.NewMSEH = Args.hasArg(OPT_fnew_ms_eh);
Opts.CXAAtExit = !Args.hasArg(OPT_fno_use_cxa_atexit);
Opts.CXXCtorDtorAliases = Args.hasArg(OPT_mconstructor_aliases);
Opts.CodeModel = getCodeModel(Args, Diags);
OpenPOWER on IntegriCloud