From f2dd68fb37a62571a4985c8dd05310ac90d07ef0 Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Wed, 20 Jul 2011 23:39:56 +0000 Subject: [PATCH] objc-arc: Fixes a crash @throw'ing an objc message. // pr10411 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@135638 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaStmt.cpp | 3 ++- test/CodeGenObjC/arc-with-atthrow.m | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 test/CodeGenObjC/arc-with-atthrow.m diff --git a/lib/Sema/SemaStmt.cpp b/lib/Sema/SemaStmt.cpp index 65f431d460..7acfc985db 100644 --- a/lib/Sema/SemaStmt.cpp +++ b/lib/Sema/SemaStmt.cpp @@ -2154,6 +2154,7 @@ Sema::ActOnObjCAtTryStmt(SourceLocation AtLoc, Stmt *Try, StmtResult Sema::BuildObjCAtThrowStmt(SourceLocation AtLoc, Expr *Throw) { if (Throw) { + Throw = MaybeCreateExprWithCleanups(Throw); ExprResult Result = DefaultLvalueConversion(Throw); if (Result.isInvalid()) return StmtError(); @@ -2188,7 +2189,7 @@ Sema::ActOnObjCAtThrowStmt(SourceLocation AtLoc, Expr *Throw, if (!AtCatchParent) return StmtError(Diag(AtLoc, diag::error_rethrow_used_outside_catch)); } - + return BuildObjCAtThrowStmt(AtLoc, Throw); } diff --git a/test/CodeGenObjC/arc-with-atthrow.m b/test/CodeGenObjC/arc-with-atthrow.m new file mode 100644 index 0000000000..b076879bdd --- /dev/null +++ b/test/CodeGenObjC/arc-with-atthrow.m @@ -0,0 +1,16 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -fobjc-arc -fobjc-nonfragile-abi -fobjc-exceptions -o - %s | FileCheck %s +// $CLANG -cc1 -fobjc-arc -fobjc-nonfragile-abi -fobjc-exceptions +// pr10411 + +@interface NSException ++ (id)exception; +@end + +void test() +{ + @throw [NSException exception]; +} + +// CHECK: objc_retainAutoreleasedReturnValue +// CHECK: call void @objc_release +// CHECK: call void @objc_exception_throw -- 2.40.0