[llvm] r249906 - [SEH] Fix _except_handler4 table base states

Reid Kleckner via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 9 14:27:28 PDT 2015


Author: rnk
Date: Fri Oct  9 16:27:28 2015
New Revision: 249906

URL: http://llvm.org/viewvc/llvm-project?rev=249906&view=rev
Log:
[SEH] Fix _except_handler4 table base states

We got them right for the old IR, but not with funclets.  Port the old
test to the new IR and fix the code.

Modified:
    llvm/trunk/lib/CodeGen/AsmPrinter/WinException.cpp
    llvm/trunk/test/CodeGen/X86/win32-eh.ll

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/WinException.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/WinException.cpp?rev=249906&r1=249905&r2=249906&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/WinException.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/WinException.cpp Fri Oct  9 16:27:28 2015
@@ -902,7 +902,10 @@ void WinException::emitExceptHandlerTabl
     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
     }

Modified: llvm/trunk/test/CodeGen/X86/win32-eh.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/win32-eh.ll?rev=249906&r1=249905&r2=249906&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/win32-eh.ll (original)
+++ llvm/trunk/test/CodeGen/X86/win32-eh.ll Fri Oct  9 16:27:28 2015
@@ -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()




More information about the llvm-commits mailing list