Finish off __Block_byref_id_object_dispose codegen for block literals.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@66247 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/CGDecl.cpp b/lib/CodeGen/CGDecl.cpp
index e783c60..cf9b741 100644
--- a/lib/CodeGen/CGDecl.cpp
+++ b/lib/CodeGen/CGDecl.cpp
@@ -345,8 +345,8 @@
       flag |= BLOCK_FIELD_IS_BLOCK;
       flags |= BLOCK_HAS_COPY_DISPOSE;
     } else if (BlockRequiresCopying(Ty)) {
-      flags |= BLOCK_HAS_COPY_DISPOSE;
       flag |= BLOCK_FIELD_IS_OBJECT;
+      flags |= BLOCK_HAS_COPY_DISPOSE;
     }
     // FIXME: Need to set BLOCK_FIELD_IS_WEAK as appropriate.
 
@@ -373,11 +373,11 @@
     if (flags & BLOCK_HAS_COPY_DISPOSE) {
       BlockHasCopyDispose = true;
       llvm::Value *copy_helper = Builder.CreateStructGEP(DeclPtr, 4);
-      llvm::Value *destroy_helper = Builder.CreateStructGEP(DeclPtr, 5);
-
       Builder.CreateStore(BuildbyrefCopyHelper(flag), copy_helper);
 
-      Builder.CreateStore(BuildbyrefDestroyHelper(flag), destroy_helper);
+      llvm::Value *destroy_helper = Builder.CreateStructGEP(DeclPtr, 5);
+      Builder.CreateStore(BuildbyrefDestroyHelper(DeclPtr->getType(), flag),
+                          destroy_helper);
     }
     needsDispose = true;
   }
@@ -400,7 +400,9 @@
 
   if (needsDispose && CGM.getLangOptions().getGCMode() != LangOptions::GCOnly) {
     CleanupScope scope(*this);
-    BuildBlockRelease(DeclPtr);
+    llvm::Value *V = Builder.CreateStructGEP(DeclPtr, 1, "forwarding");
+    V = Builder.CreateLoad(V, false);
+    BuildBlockRelease(V);
   }
 }