From 59540fd9c40bb38e4a3a66cc4a60a0d72349cdfc Mon Sep 17 00:00:00 2001 From: Reid Kleckner Date: Fri, 9 Oct 2015 21:27:28 +0000 Subject: [PATCH] [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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@249906 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/AsmPrinter/WinException.cpp | 5 ++- test/CodeGen/X86/win32-eh.ll | 42 ++++++++++++------------- 2 files changed, 24 insertions(+), 23 deletions(-) diff --git a/lib/CodeGen/AsmPrinter/WinException.cpp b/lib/CodeGen/AsmPrinter/WinException.cpp index 56a8b844ca5..a5172fdd7d7 100644 --- a/lib/CodeGen/AsmPrinter/WinException.cpp +++ b/lib/CodeGen/AsmPrinter/WinException.cpp @@ -902,7 +902,10 @@ void WinException::emitExceptHandlerTable(const MachineFunction *MF) { for (SEHUnwindMapEntry &UME : FuncInfo.SEHUnwindMap) { MCSymbol *ExceptOrFinally = UME.Handler.get()->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 } diff --git a/test/CodeGen/X86/win32-eh.ll b/test/CodeGen/X86/win32-eh.ll index f477ed1d4c6..87926a463f7 100644 --- a/test/CodeGen/X86/win32-eh.ll +++ b/test/CodeGen/X86/win32-eh.ll @@ -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() -- 2.34.1