[cfe-commits] r64692 - /cfe/trunk/lib/CodeGen/CGObjCMac.cpp

Anders Carlsson andersca at mac.com
Mon Feb 16 14:59:18 PST 2009


Author: andersca
Date: Mon Feb 16 16:59:18 2009
New Revision: 64692

URL: http://llvm.org/viewvc/llvm-project?rev=64692&view=rev
Log:
Add support for throwing exceptions to the nonfragile ABI

Modified:
    cfe/trunk/lib/CodeGen/CGObjCMac.cpp

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

==============================================================================
--- cfe/trunk/lib/CodeGen/CGObjCMac.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjCMac.cpp Mon Feb 16 16:59:18 2009
@@ -101,7 +101,10 @@
   
   /// GcAssignStrongCastFn -- LLVM objc_assign_strongCast function.
   llvm::Function *GcAssignStrongCastFn;
-    
+
+  /// ExceptionThrowFn - LLVM objc_exception_throw function.
+  llvm::Function *ExceptionThrowFn;
+  
   ObjCCommonTypesHelper(CodeGen::CodeGenModule &cgm);
   ~ObjCCommonTypesHelper(){}
 };
@@ -170,9 +173,6 @@
   /// ExceptionDataTy - LLVM type for struct _objc_exception_data.
   const llvm::Type *ExceptionDataTy;
   
-  /// ExceptionThrowFn - LLVM objc_exception_throw function.
-  llvm::Function *ExceptionThrowFn;
-  
   /// ExceptionTryEnterFn - LLVM objc_exception_try_enter function.
   llvm::Function *ExceptionTryEnterFn;
 
@@ -735,9 +735,7 @@
     CGF.ErrorUnsupported(&S, "try or synchronized statement");
   }
   virtual void EmitThrowStmt(CodeGen::CodeGenFunction &CGF,
-                             const ObjCAtThrowStmt &S) {
-    CGF.ErrorUnsupported(&S, "throw statement");
-  }
+                             const ObjCAtThrowStmt &S);
   virtual llvm::Value * EmitObjCWeakRead(CodeGen::CodeGenFunction &CGF,
                                          llvm::Value *AddrWeakObj);
   virtual void EmitObjCWeakAssign(CodeGen::CodeGenFunction &CGF,
@@ -2735,6 +2733,15 @@
   GcAssignIvarFn = CGM.CreateRuntimeFunction(FTy, "objc_assign_ivar");
   GcAssignStrongCastFn = 
     CGM.CreateRuntimeFunction(FTy, "objc_assign_strongCast");
+  
+  // void objc_exception_throw(id)
+  Params.clear();
+  Params.push_back(IdType);
+  
+  FTy = Types.GetFunctionType(Types.getFunctionInfo(Ctx.VoidTy, Params), false);
+
+  ExceptionThrowFn =
+    CGM.CreateRuntimeFunction(FTy, "objc_exception_throw");
 }
 
 ObjCTypesHelper::ObjCTypesHelper(CodeGen::CodeGenModule &cgm) 
@@ -3015,14 +3022,6 @@
                               ExceptionDataTy);
 
   Params.clear();
-  Params.push_back(ObjectPtrTy);
-  ExceptionThrowFn =
-    CGM.CreateRuntimeFunction(llvm::FunctionType::get(llvm::Type::VoidTy,
-                                                      Params,
-                                                      false),
-                              "objc_exception_throw");
-  
-  Params.clear();
   Params.push_back(llvm::PointerType::getUnqual(ExceptionDataTy));
   ExceptionTryEnterFn = 
     CGM.CreateRuntimeFunction(llvm::FunctionType::get(llvm::Type::VoidTy,
@@ -4699,6 +4698,26 @@
   return;
 }
 
+/// EmitThrowStmt - Generate code for a throw statement.
+void CGObjCNonFragileABIMac::EmitThrowStmt(CodeGen::CodeGenFunction &CGF,
+                                           const ObjCAtThrowStmt &S) {
+  llvm::Value *ExceptionAsObject;
+  
+  if (const Expr *ThrowExpr = S.getThrowExpr()) {
+    llvm::Value *Exception = CGF.EmitScalarExpr(ThrowExpr);
+    ExceptionAsObject = 
+      CGF.Builder.CreateBitCast(Exception, ObjCTypes.ObjectPtrTy, "tmp");
+    
+    CGF.Builder.CreateCall(ObjCTypes.ExceptionThrowFn, ExceptionAsObject);
+    CGF.Builder.CreateUnreachable();
+  } else {
+    CGF.ErrorUnsupported(&S, "rethrow statement");
+  }
+
+  // Clear the insertion point to indicate we are in unreachable code.
+  CGF.Builder.ClearInsertionPoint();
+}
+  
 /* *** */
 
 CodeGen::CGObjCRuntime *





More information about the cfe-commits mailing list