Instantiate the BlockDecl in ActOnBlockStart() so we can use it as a DeclContext.
This required changes to attach the compound statement later on (like we do for functions).


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@57304 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/Sema.h b/lib/Sema/Sema.h
index 406d9f7..0600ae1 100644
--- a/lib/Sema/Sema.h
+++ b/lib/Sema/Sema.h
@@ -1070,6 +1070,8 @@
   bool hasPrototype;
   bool isVariadic;
   
+  BlockDecl *TheDecl;
+  
   /// TheScope - This is the scope for the block itself, which contains
   /// arguments etc.
   Scope *TheScope;
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp
index b8b614d..cdba6ec 100644
--- a/lib/Sema/SemaExpr.cpp
+++ b/lib/Sema/SemaExpr.cpp
@@ -2889,6 +2889,8 @@
       BSI->Params.push_back((ParmVarDecl *)FTI.ArgInfo[i].Param);
     BSI->isVariadic = FTI.isVariadic;
   }
+  BSI->TheDecl = BlockDecl::Create(Context, CurContext, CaretLoc,
+                                   &BSI->Params[0], BSI->Params.size());
 }
 
 /// ActOnBlockError - If there is an error parsing a block, this callback
@@ -2932,10 +2934,8 @@
   
   BlockTy = Context.getBlockPointerType(BlockTy);
   
-  BlockDecl *NewBD = BlockDecl::Create(Context, CurContext, CaretLoc,
-                                       &BSI->Params[0], BSI->Params.size(),
-                                       Body.take());
-  return new BlockExpr(NewBD, BlockTy);
+  BSI->TheDecl->setBody(Body.take());
+  return new BlockExpr(BSI->TheDecl, BlockTy);
 }
 
 /// ExprsMatchFnType - return true if the Exprs in array Args have