Fixup semantic analysis for nested blocks, and allow block literal
expressions that can be of static duration to be returned.
Radar 6786551


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@69331 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/test/Sema/block-return.c b/test/Sema/block-return.c
index d7717b3..3eee002 100644
--- a/test/Sema/block-return.c
+++ b/test/Sema/block-return.c
@@ -41,13 +41,13 @@
       return 2; // expected-warning {{incompatible integer to pointer conversion returning 'int', expected 'char *'}}
   };
 
-  return ^{ return 1; }; // expected-warning {{incompatible block pointer types returning 'int (^)(void)', expected 'CL'}} expected-error {{returning block that lives on the local stack}}
+  return ^{ return 1; }; // expected-warning {{incompatible block pointer types returning 'int (^)(void)', expected 'CL'}}
 }
 
 typedef int (^CL2)(void);
 
 CL2 foo2() {
-  return ^{ return 1; }; // expected-error {{returning block that lives on the local stack}}
+  return ^{ return 1; };
 }
 
 typedef unsigned int * uintptr_t;
@@ -83,3 +83,12 @@
   int (^nested)(char *s) = ^(char *str) { void (^nest)(void) = ^(void) { printf("%s\n", str); }; next(); return 1; }; // expected-warning{{implicitly declaring C library function 'printf' with type 'int (char const *, ...)'}} \
   // expected-note{{please include the header <stdio.h> or explicitly provide a declaration for 'printf'}}
 }
+
+typedef void (^bptr)(void);
+
+bptr foo5(int j) {
+  __block int i;
+  if (j)
+    return ^{ ^{ i=0; }(); };  // expected-error {{returning block that lives on the local stack}}
+  return ^{ i=0; };  // expected-error {{returning block that lives on the local stack}}
+}