Okay, that rule about zero-length arrays applies to destroying
them, too.

llvm-svn: 135038
diff --git a/clang/lib/CodeGen/CGExprCXX.cpp b/clang/lib/CodeGen/CGExprCXX.cpp
index e3c6a8f..e8ed849 100644
--- a/clang/lib/CodeGen/CGExprCXX.cpp
+++ b/clang/lib/CodeGen/CGExprCXX.cpp
@@ -1364,26 +1364,16 @@
   if (QualType::DestructionKind dtorKind = elementType.isDestructedType()) {
     assert(numElements && "no element count for a type with a destructor!");
 
-    // It's legal to allocate a zero-length array, but emitArrayDestroy
-    // won't handle that correctly, so we need to check that here.
-    llvm::Value *iszero =
-      CGF.Builder.CreateIsNull(numElements, "delete.isempty");
-
-    // We'll patch the 'true' successor of this to lead to the end of
-    // the emitArrayDestroy loop.
-    llvm::BasicBlock *destroyBB = CGF.createBasicBlock("delete.destroy");
-    llvm::BranchInst *br =
-      CGF.Builder.CreateCondBr(iszero, destroyBB, destroyBB);
-    CGF.EmitBlock(destroyBB);
-
     llvm::Value *arrayEnd =
       CGF.Builder.CreateInBoundsGEP(deletedPtr, numElements, "delete.end");
+
+    // Note that it is legal to allocate a zero-length array, and we
+    // can never fold the check away because the length should always
+    // come from a cookie.
     CGF.emitArrayDestroy(deletedPtr, arrayEnd, elementType,
                          CGF.getDestroyer(dtorKind),
+                         /*checkZeroLength*/ true,
                          CGF.needsEHCleanup(dtorKind));
-
-    assert(CGF.Builder.GetInsertBlock()->empty());
-    br->setSuccessor(0, CGF.Builder.GetInsertBlock());
   }
 
   // Pop the cleanup block.