]> granicus.if.org Git - clang/commitdiff
Don't crash when a statement in a block is ill-formed but
authorJohn McCall <rjmccall@apple.com>
Thu, 8 Mar 2012 22:00:17 +0000 (22:00 +0000)
committerJohn McCall <rjmccall@apple.com>
Thu, 8 Mar 2012 22:00:17 +0000 (22:00 +0000)
introduces cleanups anyway.

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

lib/Sema/SemaExpr.cpp
test/SemaObjC/arc-invalid.m [new file with mode: 0644]

index c1ce02eeea2ab80b5cb3092d0124af177a8fe903..b989fac8389cacb00f6baa79afc32bdca71c37f3 100644 (file)
@@ -8892,6 +8892,8 @@ ExprResult Sema::ActOnBlockStmtExpr(SourceLocation CaretLoc,
     Diag(CaretLoc, diag::err_blocks_disable);
 
   // Leave the expression-evaluation context.
+  if (hasAnyUnrecoverableErrorsInThisFunction())
+    DiscardCleanupsInEvaluationContext();
   assert(!ExprNeedsCleanups && "cleanups within block not correctly bound!");
   PopExpressionEvaluationContext();
 
diff --git a/test/SemaObjC/arc-invalid.m b/test/SemaObjC/arc-invalid.m
new file mode 100644 (file)
index 0000000..b07460d
--- /dev/null
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -fsyntax-only -fobjc-arc -fblocks -verify %s
+
+// rdar://problem/10982793
+// [p foo] in ARC creates a cleanup.
+// The plus is invalid and causes the cleanup to go unbound.
+// Don't crash.
+@interface A
+- (id) foo;
+@end
+void takeBlock(void (^)(void));
+void test0(id p) {
+  takeBlock(^{ [p foo] + p; }); // expected-error {{invalid operands to binary expression}}
+}