Add codegen support for __block variables to call _Block_object_dispose as necessary.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@66117 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/CGDecl.cpp b/lib/CodeGen/CGDecl.cpp
index 9cdb40b..a01aad6 100644
--- a/lib/CodeGen/CGDecl.cpp
+++ b/lib/CodeGen/CGDecl.cpp
@@ -227,6 +227,7 @@
 void CodeGenFunction::EmitLocalBlockVarDecl(const VarDecl &D) {
   QualType Ty = D.getType();
   bool isByRef = D.getAttr<BlocksAttr>();
+  bool needsDispose = false;
 
   llvm::Value *DeclPtr;
   if (Ty->isConstantSizeType()) {
@@ -371,6 +372,7 @@
 
       Builder.CreateStore(BuildDestroyHelper(flag), destroy_helper);
     }
+    needsDispose = true;
   }
 
   // Handle the cleanup attribute
@@ -388,6 +390,11 @@
       
     EmitCall(CGM.getTypes().getFunctionInfo(FD), F, Args);
   }
+
+  if (needsDispose) {
+    CleanupScope scope(*this);
+    BuildBlockRelease(D, DeclPtr);
+  }
 }
 
 /// Emit an alloca (or GlobalValue depending on target)