aboutsummaryrefslogtreecommitdiff
path: root/lib/CodeGen/CGException.cpp
diff options
context:
space:
mode:
authorMike Stump <mrs@apple.com>2009-12-09 23:31:35 +0000
committerMike Stump <mrs@apple.com>2009-12-09 23:31:35 +0000
commit76958099828bac6ebd45abef9f76934b3e99e397 (patch)
tree7cf247733aef30a23863d9a7e234d58803f43686 /lib/CodeGen/CGException.cpp
parent6bcd5a04db4eb9d51e7f92a4edc418737a5aeefd (diff)
Add terminate handler for copy constructors for thrown objects. WIP.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@90994 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CGException.cpp')
-rw-r--r--lib/CodeGen/CGException.cpp18
1 files changed, 16 insertions, 2 deletions
diff --git a/lib/CodeGen/CGException.cpp b/lib/CodeGen/CGException.cpp
index d1edde5273..5e26e9bbea 100644
--- a/lib/CodeGen/CGException.cpp
+++ b/lib/CodeGen/CGException.cpp
@@ -165,6 +165,10 @@ static void CopyObject(CodeGenFunction &CGF, const Expr *E, llvm::Value *N) {
llvm::Value *Src = CGF.EmitLValue(E).getAddress();
+ llvm::BasicBlock *TerminateHandler = CGF.getTerminateHandler();
+ llvm::BasicBlock *PrevLandingPad = CGF.getInvokeDest();
+ CGF.setInvokeDest(TerminateHandler);
+
// Stolen from EmitClassAggrMemberwiseCopy
llvm::Value *Callee = CGF.CGM.GetAddrOfCXXConstructor(CopyCtor,
Ctor_Complete);
@@ -179,6 +183,7 @@ static void CopyObject(CodeGenFunction &CGF, const Expr *E, llvm::Value *N) {
CopyCtor->getType()->getAs<FunctionType>()->getResultType();
CGF.EmitCall(CGF.CGM.getTypes().getFunctionInfo(ResultType, CallArgs),
Callee, CallArgs, CopyCtor);
+ CGF.setInvokeDest(PrevLandingPad);
} else
llvm::llvm_unreachable("uncopyable object");
}
@@ -253,7 +258,6 @@ void CodeGenFunction::EmitCXXThrowExpr(const CXXThrowExpr *E) {
llvm::ConstantInt::get(SizeTy, TypeSize),
"exception");
- // FIXME: terminate protect this
CopyObject(*this, E->getSubExpr(), ExceptionPtr);
// Now throw the exception.
@@ -685,6 +689,13 @@ CodeGenFunction::EHCleanupBlock::~EHCleanupBlock() {
}
llvm::BasicBlock *CodeGenFunction::getTerminateHandler() {
+ llvm::BasicBlock *Cont = 0;
+
+ if (HaveInsertPoint()) {
+ Cont = createBasicBlock("cont");
+ EmitBranch(Cont);
+ }
+
llvm::Constant *Personality =
CGM.CreateRuntimeFunction(llvm::FunctionType::get(llvm::Type::getInt32Ty
(VMContext),
@@ -706,7 +717,7 @@ llvm::BasicBlock *CodeGenFunction::getTerminateHandler() {
Args.push_back(Exc);
Args.push_back(Personality);
Args.push_back(llvm::ConstantInt::get(llvm::Type::getInt32Ty(VMContext),
- 0));
+ 1));
Builder.CreateCall(llvm_eh_selector, Args.begin(), Args.end());
llvm::CallInst *TerminateCall =
Builder.CreateCall(getTerminateFn(*this));
@@ -717,5 +728,8 @@ llvm::BasicBlock *CodeGenFunction::getTerminateHandler() {
// Clear the insertion point to indicate we are in unreachable code.
Builder.ClearInsertionPoint();
+ if (Cont)
+ EmitBlock(Cont);
+
return TerminateHandler;
}