Validated by nightly-test runs on x86 and x86-64 darwin, including after
self-host.  Hopefully these results hold up on different platforms.  

I tried to keep the GNU ObjC runtime happy, but it's hard for me to test.
Reimplement how clang generates IR for exceptions.  Instead of creating new
invoke destinations which sequentially chain to the previous destination,
push a more semantic representation of *why* we need the cleanup/catch/filter
behavior, then collect that information into a single landing pad upon request.

Also reorganizes how normal cleanups (i.e. cleanups triggered by non-exceptional
control flow) are generated, since it's actually fairly closely tied in with
the former.  Remove the need to track which cleanup scope a block is associated
with.

Document a lot of previously poorly-understood (by me, at least) behavior.

The new framework implements the Horrible Hack (tm), which requires every
landing pad to have a catch-all so that inlining will work.  Clang no longer
requires the Horrible Hack just to make exceptions flow correctly within
a function, however.  The HH is an unfortunate requirement of LLVM's EH IR.




git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@107631 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/test/CodeGenCXX/destructors.cpp b/test/CodeGenCXX/destructors.cpp
index ef3d4b9..ee8f1a5 100644
--- a/test/CodeGenCXX/destructors.cpp
+++ b/test/CodeGenCXX/destructors.cpp
@@ -187,15 +187,63 @@
   // Checked at top of file:
   // @_ZN5test312_GLOBAL__N_11CD1Ev = alias internal {{.*}} @_ZN5test312_GLOBAL__N_11CD2Ev
 
+  // More checks at end of file.
+
+}
+
+namespace test4 {
+  struct A { ~A(); };
+
+  // CHECK: define void @_ZN5test43fooEv()
+  // CHECK: call void @_ZN5test41AD1Ev
+  // CHECK: ret void
+  void foo() {
+    {
+      A a;
+      goto failure;
+    }
+
+  failure:
+    return;
+  }
+
+  // CHECK: define void @_ZN5test43barEi(
+  // CHECK:      [[X:%.*]] = alloca i32
+  // CHECK-NEXT: [[A:%.*]] = alloca
+  // CHECK:      br label
+  // CHECK:      [[TMP:%.*]] = load i32* [[X]]
+  // CHECK-NEXT: [[CMP:%.*]] = icmp ne i32 [[TMP]], 0
+  // CHECK-NEXT: br i1
+  // CHECK:      call void @_ZN5test41AD1Ev(
+  // CHECK:      br label
+  // CHECK:      [[TMP:%.*]] = load i32* [[X]]
+  // CHECK:      [[TMP2:%.*]] = add nsw i32 [[TMP]], -1
+  // CHECK:      store i32 [[TMP2]], i32* [[X]]
+  // CHECK:      br label
+  // CHECK:      ret void
+  void bar(int x) {
+    for (A a; x; ) {
+      x--;
+    }
+  }
+}
+
+// Checks from test3:
+
   // CHECK: define internal void @_ZN5test312_GLOBAL__N_11CD2Ev(
   // CHECK: call void @_ZN5test31BD2Ev(
   // CHECK: call void @_ZN5test31AD2Ev(
   // CHECK: ret void
 
   // CHECK: define internal void @_ZN5test312_GLOBAL__N_11DD0Ev(
-  // CHECK: call void @_ZN5test312_GLOBAL__N_11DD1Ev(
+  // CHECK: invoke void @_ZN5test312_GLOBAL__N_11DD1Ev(
   // CHECK: call void @_ZdlPv(
   // CHECK: ret void
+  // CHECK: call i8* @llvm.eh.exception(
+  // CHECK: invoke void @_ZdlPv
+  // CHECK: call void @_Unwind_Resume_or_Rethrow
+  // CHECK: call i8* @llvm.eh.exception(
+  // CHECK: call void @_ZSt9terminatev(
 
   // Checked at top of file:
   // @_ZN5test312_GLOBAL__N_11DD1Ev = alias internal {{.*}} @_ZN5test312_GLOBAL__N_11DD2Ev
@@ -215,9 +263,14 @@
   // CHECK: declare void @_ZN5test31AD2Ev(
 
   // CHECK: define internal void @_ZN5test312_GLOBAL__N_11CD0Ev(
-  // CHECK: call void @_ZN5test312_GLOBAL__N_11CD1Ev(
+  // CHECK: invoke void @_ZN5test312_GLOBAL__N_11CD1Ev(
   // CHECK: call void @_ZdlPv(
   // CHECK: ret void
+  // CHECK: call i8* @llvm.eh.exception()
+  // CHECK: invoke void @_ZdlPv(
+  // CHECK: call void @_Unwind_Resume_or_Rethrow(
+  // CHECK: call i8* @llvm.eh.exception()
+  // CHECK: call void @_ZSt9terminatev()
 
   // CHECK: define internal void @_ZThn8_N5test312_GLOBAL__N_11CD1Ev(
   // CHECK: getelementptr inbounds i8* {{.*}}, i64 -8
@@ -228,4 +281,3 @@
   // CHECK: getelementptr inbounds i8* {{.*}}, i64 -8
   // CHECK: call void @_ZN5test312_GLOBAL__N_11CD0Ev(
   // CHECK: ret void
-}