[WinEH] Push cleanupendpad scopes around exceptional cleanups

We were only doing this for SEH as a special case. Generalize it to all
cleanups.

llvm-svn: 249748
diff --git a/clang/lib/CodeGen/CGException.cpp b/clang/lib/CodeGen/CGException.cpp
index 16f6e83..2c1ede4 100644
--- a/clang/lib/CodeGen/CGException.cpp
+++ b/clang/lib/CodeGen/CGException.cpp
@@ -1410,10 +1410,8 @@
 namespace {
 struct PerformSEHFinally final : EHScopeStack::Cleanup {
   llvm::Function *OutlinedFinally;
-  EHScopeStack::stable_iterator EnclosingScope;
-  PerformSEHFinally(llvm::Function *OutlinedFinally,
-                    EHScopeStack::stable_iterator EnclosingScope)
-      : OutlinedFinally(OutlinedFinally), EnclosingScope(EnclosingScope) {}
+  PerformSEHFinally(llvm::Function *OutlinedFinally)
+      : OutlinedFinally(OutlinedFinally) {}
 
   void Emit(CodeGenFunction &CGF, Flags F) override {
     ASTContext &Context = CGF.getContext();
@@ -1438,28 +1436,7 @@
         CGM.getTypes().arrangeFreeFunctionCall(Args, FPT,
                                                /*chainCall=*/false);
 
-    // If this is the normal cleanup, just emit the call.
-    if (!F.isForEHCleanup()) {
-      CGF.EmitCall(FnInfo, OutlinedFinally, ReturnValueSlot(), Args);
-      return;
-    }
-
-    // Build a cleanupendpad to unwind through.
-    llvm::BasicBlock *CleanupBB = CGF.Builder.GetInsertBlock();
-    llvm::BasicBlock *CleanupEndBB = CGF.createBasicBlock("ehcleanup.end");
-    llvm::Instruction *PadInst = CleanupBB->getFirstNonPHI();
-    auto *CPI = cast<llvm::CleanupPadInst>(PadInst);
-    CGBuilderTy(CGF, CleanupEndBB)
-        .CreateCleanupEndPad(CPI, CGF.getEHDispatchBlock(EnclosingScope));
-
-    // Push and pop the cleanupendpad around the call.
-    CGF.EHStack.pushPadEnd(CleanupEndBB);
     CGF.EmitCall(FnInfo, OutlinedFinally, ReturnValueSlot(), Args);
-    CGF.EHStack.popPadEnd();
-
-    // Insert the catchendpad block here.
-    CGF.CurFn->getBasicBlockList().insertAfter(CGF.Builder.GetInsertBlock(),
-                                               CleanupEndBB);
   }
 };
 } // end anonymous namespace
@@ -1815,8 +1792,7 @@
         HelperCGF.GenerateSEHFinallyFunction(*this, *Finally);
 
     // Push a cleanup for __finally blocks.
-    EHStack.pushCleanup<PerformSEHFinally>(NormalAndEHCleanup, FinallyFunc,
-                                           EHStack.getInnermostEHScope());
+    EHStack.pushCleanup<PerformSEHFinally>(NormalAndEHCleanup, FinallyFunc);
     return;
   }