[SEH] Fix _except_handler4 table base states
authorReid Kleckner <rnk@google.com>
Fri, 9 Oct 2015 21:27:28 +0000 (21:27 +0000)
committerReid Kleckner <rnk@google.com>
Fri, 9 Oct 2015 21:27:28 +0000 (21:27 +0000)
We got them right for the old IR, but not with funclets.  Port the old
test to the new IR and fix the code.

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

lib/CodeGen/AsmPrinter/WinException.cpp
test/CodeGen/X86/win32-eh.ll

index 56a8b844ca56566af1f55bc2f27f038e4988b880..a5172fdd7d731ba159ff44c974fcc6c5dfa9391c 100644 (file)
@@ -902,7 +902,10 @@ void WinException::emitExceptHandlerTable(const MachineFunction *MF) {
     for (SEHUnwindMapEntry &UME : FuncInfo.SEHUnwindMap) {
       MCSymbol *ExceptOrFinally =
           UME.Handler.get<MachineBasicBlock *>()->getSymbol();
-      OS.EmitIntValue(UME.ToState, 4);                  // ToState
+      // -1 is usually the base state for "unwind to caller", but for
+      // _except_handler4 it's -2. Do that replacement here if necessary.
+      int ToState = UME.ToState == -1 ? BaseState : UME.ToState;
+      OS.EmitIntValue(ToState, 4);                      // ToState
       OS.EmitValue(create32bitRef(UME.Filter), 4);      // Filter
       OS.EmitValue(create32bitRef(ExceptOrFinally), 4); // Except/Finally
     }
index f477ed1d4c695dadeb58627eb977f4727e88f995..87926a463f7be58060417abadb9247ebf7ea2551 100644 (file)
@@ -15,18 +15,16 @@ define internal i32 @catchall_filt() {
 define void @use_except_handler3() personality i32 (...)* @_except_handler3 {
 entry:
   invoke void @may_throw_or_crash()
-      to label %cont unwind label %catchall
+      to label %cont unwind label %lpad
 cont:
   ret void
-catchall:
-  %0 = landingpad { i8*, i32 }
-      catch i8* bitcast (i32 ()* @catchall_filt to i8*)
-  %1 = extractvalue { i8*, i32 } %0, 1
-  %2 = call i32 @llvm.eh.typeid.for(i8* bitcast (i32 ()* @catchall_filt to i8*)) #4
-  %matches = icmp eq i32 %1, %2
-  br i1 %matches, label %cont, label %eh.resume
-eh.resume:
-  resume { i8*, i32 } %0
+lpad:
+  %p = catchpad [i8* bitcast (i32 ()* @catchall_filt to i8*)]
+      to label %catch unwind label %endpad
+catch:
+  catchret %p to label %cont
+endpad:
+  catchendpad unwind to caller
 }
 
 ; CHECK-LABEL: _use_except_handler3:
@@ -47,28 +45,27 @@ eh.resume:
 ; CHECK: movl -28(%ebp), %[[next:[^ ,]*]]
 ; CHECK: movl %[[next]], %fs:0
 ; CHECK: retl
+; CHECK: LBB1_2: # %lpad{{$}}
 
 ; CHECK: .section .xdata,"dr"
 ; CHECK-LABEL: L__ehtable$use_except_handler3:
 ; CHECK-NEXT:  .long   -1
 ; CHECK-NEXT:  .long   _catchall_filt
-; CHECK-NEXT:  .long   Ltmp{{[0-9]+}}
+; CHECK-NEXT:  .long   LBB1_2
 
 define void @use_except_handler4() personality i32 (...)* @_except_handler4 {
 entry:
   invoke void @may_throw_or_crash()
-      to label %cont unwind label %catchall
+      to label %cont unwind label %lpad
 cont:
   ret void
-catchall:
-  %0 = landingpad { i8*, i32 }
-      catch i8* bitcast (i32 ()* @catchall_filt to i8*)
-  %1 = extractvalue { i8*, i32 } %0, 1
-  %2 = call i32 @llvm.eh.typeid.for(i8* bitcast (i32 ()* @catchall_filt to i8*)) #4
-  %matches = icmp eq i32 %1, %2
-  br i1 %matches, label %cont, label %eh.resume
-eh.resume:
-  resume { i8*, i32 } %0
+lpad:
+  %p = catchpad [i8* bitcast (i32 ()* @catchall_filt to i8*)]
+      to label %catch unwind label %endpad
+catch:
+  catchret %p to label %cont
+endpad:
+  catchendpad unwind to caller
 }
 
 ; CHECK-LABEL: _use_except_handler4:
@@ -89,6 +86,7 @@ eh.resume:
 ; CHECK: movl -28(%ebp), %[[next:[^ ,]*]]
 ; CHECK: movl %[[next]], %fs:0
 ; CHECK: retl
+; CHECK: LBB2_2: # %lpad{{$}}
 
 ; CHECK: .section .xdata,"dr"
 ; CHECK-LABEL: L__ehtable$use_except_handler4:
@@ -98,7 +96,7 @@ eh.resume:
 ; CHECK-NEXT:  .long   0
 ; CHECK-NEXT:  .long   -2
 ; CHECK-NEXT:  .long   _catchall_filt
-; CHECK-NEXT:  .long   Ltmp{{[0-9]+}}
+; CHECK-NEXT:  .long   LBB2_2
 
 define void @use_CxxFrameHandler3() personality i32 (...)* @__CxxFrameHandler3 {
   invoke void @may_throw_or_crash()