[cfe-commits] r90994 - in /cfe/trunk: lib/CodeGen/CGException.cpp test/CodeGenCXX/eh.cpp

Mike Stump mrs at apple.com
Wed Dec 9 15:31:35 PST 2009


Author: mrs
Date: Wed Dec  9 17:31:35 2009
New Revision: 90994

URL: http://llvm.org/viewvc/llvm-project?rev=90994&view=rev
Log:
Add terminate handler for copy constructors for thrown objects.  WIP.

Modified:
    cfe/trunk/lib/CodeGen/CGException.cpp
    cfe/trunk/test/CodeGenCXX/eh.cpp

Modified: cfe/trunk/lib/CodeGen/CGException.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGException.cpp?rev=90994&r1=90993&r2=90994&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGException.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGException.cpp Wed Dec  9 17:31:35 2009
@@ -165,6 +165,10 @@
 
       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 @@
         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 @@
                        llvm::ConstantInt::get(SizeTy, TypeSize),
                        "exception");
 
-  // FIXME: terminate protect this
   CopyObject(*this, E->getSubExpr(), ExceptionPtr);
   
   // Now throw the exception.
@@ -685,6 +689,13 @@
 }
 
 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 @@
   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 @@
   // Clear the insertion point to indicate we are in unreachable code.
   Builder.ClearInsertionPoint();
 
+  if (Cont)
+    EmitBlock(Cont);
+
   return TerminateHandler;
 }

Modified: cfe/trunk/test/CodeGenCXX/eh.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/eh.cpp?rev=90994&r1=90993&r2=90994&view=diff

==============================================================================
--- cfe/trunk/test/CodeGenCXX/eh.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/eh.cpp Wed Dec  9 17:31:35 2009
@@ -34,8 +34,9 @@
 // CHECK-NEXT:entry:
 // CHECK-NEXT:  %exception = call i8* @__cxa_allocate_exception(i64 16)
 // CHECK-NEXT:  %0 = bitcast i8* %exception to %struct.test2_D*
-// CHECK-NEXT:  call void @_ZN7test2_DC1ERKS_(%struct.test2_D* %0, %struct.test2_D* @d2)
-// CHECK-NEXT:  call void @__cxa_throw(i8* %exception, i8* bitcast (%0* @_ZTI7test2_D to i8*), i8* null) noreturn
+// CHECK:       invoke void @_ZN7test2_DC1ERKS_(%struct.test2_D* %0, %struct.test2_D* @d2)
+// CHECK-NEXT:     to label %invoke.cont unwind label %terminate.handler
+// CHECK:  call void @__cxa_throw(i8* %exception, i8* bitcast (%0* @_ZTI7test2_D to i8*), i8* null) noreturn
 // CHECK-NEXT:  unreachable
 
 





More information about the cfe-commits mailing list