Rearrange code so that we pass the right pointer to delete[] when an exception is thrown constructing the array elements in an array new expression.  Fixes PR10870.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@139158 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/test/CodeGenCXX/exceptions.cpp b/test/CodeGenCXX/exceptions.cpp
index 18a3d10..0fbb09c 100644
--- a/test/CodeGenCXX/exceptions.cpp
+++ b/test/CodeGenCXX/exceptions.cpp
@@ -406,4 +406,22 @@
   void test() {
     throw makeA();
   }
+  // CHECK: define void @_ZN5test84testEv
+}
+
+// Make sure we generate the correct code for the delete[] call which
+// happens if A::A() throws.  (We were previously calling delete[] on
+// a pointer to the first array element, not the pointer returned by new[].)
+// PR10870
+namespace test9 {
+  struct A {
+    A();
+    ~A();
+  };
+  A* test() {
+    return new A[10];
+  }
+  // CHECK: define {{%.*}}* @_ZN5test94testEv
+  // CHECK: [[TEST9_NEW:%.*]] = call noalias i8* @_Znam
+  // CHECK: call void @_ZdaPv(i8* [[TEST9_NEW]])
 }