]> granicus.if.org Git - clang/commitdiff
objc-arc: Fixes a crash @throw'ing an objc message.
authorFariborz Jahanian <fjahanian@apple.com>
Wed, 20 Jul 2011 23:39:56 +0000 (23:39 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Wed, 20 Jul 2011 23:39:56 +0000 (23:39 +0000)
// pr10411

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@135638 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaStmt.cpp
test/CodeGenObjC/arc-with-atthrow.m [new file with mode: 0644]

index 65f431d46075e3c0514b9e7668c93d0d2e2d19d5..7acfc985dbbd374a0ce4e50871ea530928aa91e6 100644 (file)
@@ -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 (file)
index 0000000..b076879
--- /dev/null
@@ -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