aboutsummaryrefslogtreecommitdiff
path: root/lib/CodeGen
diff options
context:
space:
mode:
authorAnders Carlsson <andersca@mac.com>2009-02-16 22:59:18 +0000
committerAnders Carlsson <andersca@mac.com>2009-02-16 22:59:18 +0000
commitf57c5b2ef767223f349be6adba9bf1b4f9d19283 (patch)
tree1655973e2a4e72ddeaf866db4cb1bed6e93c5a5f /lib/CodeGen
parent6948aea3664832416031eaac6fb55af3efb99b48 (diff)
Add support for throwing exceptions to the nonfragile ABI
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@64692 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen')
-rw-r--r--lib/CodeGen/CGObjCMac.cpp49
1 files changed, 34 insertions, 15 deletions
diff --git a/lib/CodeGen/CGObjCMac.cpp b/lib/CodeGen/CGObjCMac.cpp
index 456530dfe0..6be5009554 100644
--- a/lib/CodeGen/CGObjCMac.cpp
+++ b/lib/CodeGen/CGObjCMac.cpp
@@ -101,7 +101,10 @@ public:
/// 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 @@ public:
/// 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 @@ public:
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 @@ ObjCCommonTypesHelper::ObjCCommonTypesHelper(CodeGen::CodeGenModule &cgm)
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 @@ ObjCTypesHelper::ObjCTypesHelper(CodeGen::CodeGenModule &cgm)
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 @@ void CGObjCNonFragileABIMac::EmitObjCGlobalAssign(CodeGen::CodeGenFunction &CGF,
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 *