Fix crash on finally blocks that don't fall through

llvm-svn: 228243
diff --git a/clang/lib/CodeGen/CGException.cpp b/clang/lib/CodeGen/CGException.cpp
index e90f568..89c1a2d 100644
--- a/clang/lib/CodeGen/CGException.cpp
+++ b/clang/lib/CodeGen/CGException.cpp
@@ -1902,12 +1902,20 @@
   // Just pop the cleanup if it's a __finally block.
   if (const SEHFinallyStmt *Finally = S.getFinallyHandler()) {
     PopCleanupBlock();
+    assert(FI.ContBB && "did not emit normal cleanup");
 
     // Emit the code into FinallyBB.
     Builder.SetInsertPoint(FI.FinallyBB);
     EmitStmt(Finally->getBlock());
 
-    assert(FI.ContBB);
+    // If the finally block doesn't fall through, we don't need these blocks.
+    if (!HaveInsertPoint()) {
+      FI.ContBB->eraseFromParent();
+      if (FI.ResumeBB)
+        FI.ResumeBB->eraseFromParent();
+      return;
+    }
+
     if (FI.ResumeBB) {
       llvm::Value *IsEH = Builder.CreateLoad(getAbnormalTerminationSlot(),
                                              "abnormal.termination");