]> granicus.if.org Git - clang/commitdiff
[MS ABI] Don't rely on terminatepad
authorDavid Majnemer <david.majnemer@gmail.com>
Mon, 14 Dec 2015 18:34:18 +0000 (18:34 +0000)
committerDavid Majnemer <david.majnemer@gmail.com>
Mon, 14 Dec 2015 18:34:18 +0000 (18:34 +0000)
We'd like to remove support for terminatepad from LLVM.  To do this, we
need to move Clang off of it first.  The intent behind terminatepad was
to carefully model exception specifications for the MSVC personality.

However, we don't support exception specifications for the MSVC
personality and neither does MSVC.  Instead, MSVC supports
all-or-nothing exception specifications.  We can model this limited
usage using cleanuppads which call std::terminate.

Differential Revision: http://reviews.llvm.org/D15478

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@255521 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGException.cpp
test/CodeGenCXX/exceptions-cxx-new.cpp
test/CodeGenCXX/microsoft-abi-eh-terminate.cpp

index b5e1dcdc6c953d497ea2722019c912297252fcf8..a064e6246a7725ee7bef20df979b195e51cf8bf7 100644 (file)
@@ -1325,21 +1325,20 @@ llvm::BasicBlock *CodeGenFunction::getTerminateHandler() {
   // end of the function by FinishFunction.
   TerminateHandler = createBasicBlock("terminate.handler");
   Builder.SetInsertPoint(TerminateHandler);
+  llvm::Value *Exn = nullptr;
   if (EHPersonality::get(*this).usesFuncletPads()) {
     llvm::Value *ParentPad = CurrentFuncletPad;
     if (!ParentPad)
       ParentPad = llvm::ConstantTokenNone::get(CGM.getLLVMContext());
-    Builder.CreateTerminatePad(ParentPad, /*UnwindBB=*/nullptr,
-                               {CGM.getTerminateFn()});
+    Builder.CreateCleanupPad(ParentPad);
   } else {
-    llvm::Value *Exn = nullptr;
     if (getLangOpts().CPlusPlus)
       Exn = getExceptionFromSlot();
-    llvm::CallInst *terminateCall =
-        CGM.getCXXABI().emitTerminateForUnexpectedException(*this, Exn);
-    terminateCall->setDoesNotReturn();
-    Builder.CreateUnreachable();
   }
+  llvm::CallInst *terminateCall =
+      CGM.getCXXABI().emitTerminateForUnexpectedException(*this, Exn);
+  terminateCall->setDoesNotReturn();
+  Builder.CreateUnreachable();
 
   // Restore the saved insertion state.
   Builder.restoreIP(SavedIP);
index 42b26c9dc8ff4a45df6a1f0d525be79b502484b0..3767f3321c3e98d9f69ab795defdb6c1ff01734c 100644 (file)
@@ -72,5 +72,6 @@ void test_cleanup() {
 // CHECK:   ret void
 
 // CHECK: [[TERMINATE]]
-// CHECK:   terminatepad within none [void ()* @"\01?terminate@@YAXXZ"] unwind to caller
+// CHECK:   cleanuppad within none []
+// CHECK-NEXT:   call void @"\01?terminate@@YAXXZ"()
 
index 7eb9f08524efcedcfeaf8b2e952913d5756ce6fd..0b8d270e13792d429b22fdd1780cd3c604858c67 100644 (file)
@@ -9,6 +9,7 @@ void never_throws() noexcept(true) {
 // CHECK-LABEL: define void @"\01?never_throws@@YAXXZ"()
 // CHECK-SAME:          personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*)
 // CHECK:      invoke void @"\01?may_throw@@YAXXZ"()
-// MSVC2013:      terminatepad within none [void ()* @"\01?terminate@@YAXXZ"]
-// MSVC2015:      terminatepad within none [void ()* @__std_terminate]
+// CHECK:      cleanuppad within none []
+// MSVC2013:      call void @"\01?terminate@@YAXXZ"()
+// MSVC2015:      call void @__std_terminate()
 // CHECK-NEXT: unreachable