aboutsummaryrefslogtreecommitdiff
path: root/lib/CodeGen
diff options
context:
space:
mode:
authorFariborz Jahanian <fjahanian@apple.com>2013-01-10 19:02:56 +0000
committerFariborz Jahanian <fjahanian@apple.com>2013-01-10 19:02:56 +0000
commit6a3c70ec59804347c99e96aa13934f63f4fed573 (patch)
treedf913e85b27bebfc601d4a61edf7d22364593b7e /lib/CodeGen
parentd8d9b847bd7120ebd5be83a55d31d9c26142962e (diff)
objectiveC++: When throwing c++ exception of
an objectiveC object, use objc_exception_throw to raise the exception. // rdar://12605907 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172091 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen')
-rw-r--r--lib/CodeGen/CGException.cpp12
-rw-r--r--lib/CodeGen/CGObjCGNU.cpp9
-rw-r--r--lib/CodeGen/CGObjCMac.cpp18
-rw-r--r--lib/CodeGen/CGObjCRuntime.h3
4 files changed, 32 insertions, 10 deletions
diff --git a/lib/CodeGen/CGException.cpp b/lib/CodeGen/CGException.cpp
index 4d4f529f20..5797fd7578 100644
--- a/lib/CodeGen/CGException.cpp
+++ b/lib/CodeGen/CGException.cpp
@@ -15,6 +15,7 @@
#include "CGCleanup.h"
#include "CGObjCRuntime.h"
#include "TargetInfo.h"
+#include "clang/AST/StmtObjC.h"
#include "clang/AST/StmtCXX.h"
#include "llvm/IR/Intrinsics.h"
#include "llvm/Support/CallSite.h"
@@ -434,6 +435,17 @@ void CodeGenFunction::EmitCXXThrowExpr(const CXXThrowExpr *E) {
QualType ThrowType = E->getSubExpr()->getType();
+ if (ThrowType->isObjCObjectPointerType()) {
+ const Stmt *ThrowStmt = E->getSubExpr();
+ const ObjCAtThrowStmt S(E->getExprLoc(),
+ const_cast<Stmt *>(ThrowStmt));
+ CGM.getObjCRuntime().EmitThrowStmt(*this, S, false);
+ // This will clear insertion point which was not cleared in
+ // call to EmitThrowStmt.
+ EmitBlock(createBasicBlock("throw.cont"));
+ return;
+ }
+
// Now allocate the exception object.
llvm::Type *SizeTy = ConvertType(getContext().getSizeType());
uint64_t TypeSize = getContext().getTypeSizeInChars(ThrowType).getQuantity();
diff --git a/lib/CodeGen/CGObjCGNU.cpp b/lib/CodeGen/CGObjCGNU.cpp
index b639056da4..d1ca3bf263 100644
--- a/lib/CodeGen/CGObjCGNU.cpp
+++ b/lib/CodeGen/CGObjCGNU.cpp
@@ -502,7 +502,8 @@ public:
virtual void EmitSynchronizedStmt(CodeGenFunction &CGF,
const ObjCAtSynchronizedStmt &S);
virtual void EmitThrowStmt(CodeGenFunction &CGF,
- const ObjCAtThrowStmt &S);
+ const ObjCAtThrowStmt &S,
+ bool ClearInsertionPoint=true);
virtual llvm::Value * EmitObjCWeakRead(CodeGenFunction &CGF,
llvm::Value *AddrWeakObj);
virtual void EmitObjCWeakAssign(CodeGenFunction &CGF,
@@ -2637,7 +2638,8 @@ void CGObjCGNU::EmitTryStmt(CodeGenFunction &CGF,
}
void CGObjCGNU::EmitThrowStmt(CodeGenFunction &CGF,
- const ObjCAtThrowStmt &S) {
+ const ObjCAtThrowStmt &S,
+ bool ClearInsertionPoint) {
llvm::Value *ExceptionAsObject;
if (const Expr *ThrowExpr = S.getThrowExpr()) {
@@ -2653,7 +2655,8 @@ void CGObjCGNU::EmitThrowStmt(CodeGenFunction &CGF,
CGF.EmitCallOrInvoke(ExceptionThrowFn, ExceptionAsObject);
Throw.setDoesNotReturn();
CGF.Builder.CreateUnreachable();
- CGF.Builder.ClearInsertionPoint();
+ if (ClearInsertionPoint)
+ CGF.Builder.ClearInsertionPoint();
}
llvm::Value * CGObjCGNU::EmitObjCWeakRead(CodeGenFunction &CGF,
diff --git a/lib/CodeGen/CGObjCMac.cpp b/lib/CodeGen/CGObjCMac.cpp
index 36eda82af0..ddc422395b 100644
--- a/lib/CodeGen/CGObjCMac.cpp
+++ b/lib/CodeGen/CGObjCMac.cpp
@@ -1233,7 +1233,8 @@ public:
const ObjCAtSynchronizedStmt &S);
void EmitTryOrSynchronizedStmt(CodeGen::CodeGenFunction &CGF, const Stmt &S);
virtual void EmitThrowStmt(CodeGen::CodeGenFunction &CGF,
- const ObjCAtThrowStmt &S);
+ const ObjCAtThrowStmt &S,
+ bool ClearInsertionPoint=true);
virtual llvm::Value * EmitObjCWeakRead(CodeGen::CodeGenFunction &CGF,
llvm::Value *AddrWeakObj);
virtual void EmitObjCWeakAssign(CodeGen::CodeGenFunction &CGF,
@@ -1511,7 +1512,8 @@ public:
virtual void EmitSynchronizedStmt(CodeGen::CodeGenFunction &CGF,
const ObjCAtSynchronizedStmt &S);
virtual void EmitThrowStmt(CodeGen::CodeGenFunction &CGF,
- const ObjCAtThrowStmt &S);
+ const ObjCAtThrowStmt &S,
+ bool ClearInsertionPoint=true);
virtual llvm::Value * EmitObjCWeakRead(CodeGen::CodeGenFunction &CGF,
llvm::Value *AddrWeakObj);
virtual void EmitObjCWeakAssign(CodeGen::CodeGenFunction &CGF,
@@ -4071,7 +4073,8 @@ void CGObjCMac::EmitTryOrSynchronizedStmt(CodeGen::CodeGenFunction &CGF,
}
void CGObjCMac::EmitThrowStmt(CodeGen::CodeGenFunction &CGF,
- const ObjCAtThrowStmt &S) {
+ const ObjCAtThrowStmt &S,
+ bool ClearInsertionPoint) {
llvm::Value *ExceptionAsObject;
if (const Expr *ThrowExpr = S.getThrowExpr()) {
@@ -4089,7 +4092,8 @@ void CGObjCMac::EmitThrowStmt(CodeGen::CodeGenFunction &CGF,
CGF.Builder.CreateUnreachable();
// Clear the insertion point to indicate we are in unreachable code.
- CGF.Builder.ClearInsertionPoint();
+ if (ClearInsertionPoint)
+ CGF.Builder.ClearInsertionPoint();
}
/// EmitObjCWeakRead - Code gen for loading value of a __weak
@@ -6924,7 +6928,8 @@ void CGObjCNonFragileABIMac::EmitTryStmt(CodeGen::CodeGenFunction &CGF,
/// EmitThrowStmt - Generate code for a throw statement.
void CGObjCNonFragileABIMac::EmitThrowStmt(CodeGen::CodeGenFunction &CGF,
- const ObjCAtThrowStmt &S) {
+ const ObjCAtThrowStmt &S,
+ bool ClearInsertionPoint) {
if (const Expr *ThrowExpr = S.getThrowExpr()) {
llvm::Value *Exception = CGF.EmitObjCThrowOperand(ThrowExpr);
Exception = CGF.Builder.CreateBitCast(Exception, ObjCTypes.ObjectPtrTy);
@@ -6936,7 +6941,8 @@ void CGObjCNonFragileABIMac::EmitThrowStmt(CodeGen::CodeGenFunction &CGF,
}
CGF.Builder.CreateUnreachable();
- CGF.Builder.ClearInsertionPoint();
+ if (ClearInsertionPoint)
+ CGF.Builder.ClearInsertionPoint();
}
llvm::Constant *
diff --git a/lib/CodeGen/CGObjCRuntime.h b/lib/CodeGen/CGObjCRuntime.h
index 584bf6738f..cbd255d7ff 100644
--- a/lib/CodeGen/CGObjCRuntime.h
+++ b/lib/CodeGen/CGObjCRuntime.h
@@ -235,7 +235,8 @@ public:
virtual void EmitTryStmt(CodeGen::CodeGenFunction &CGF,
const ObjCAtTryStmt &S) = 0;
virtual void EmitThrowStmt(CodeGen::CodeGenFunction &CGF,
- const ObjCAtThrowStmt &S) = 0;
+ const ObjCAtThrowStmt &S,
+ bool ClearInsertionPoint=true) = 0;
virtual llvm::Value *EmitObjCWeakRead(CodeGen::CodeGenFunction &CGF,
llvm::Value *AddrWeakObj) = 0;
virtual void EmitObjCWeakAssign(CodeGen::CodeGenFunction &CGF,