1; RUN: llc -mtriple=i686-windows-msvc < %s | FileCheck %s 2 3; 32-bit catch-all has to use a filter function because that's how it saves the 4; exception code. 5 6@str = linkonce_odr unnamed_addr constant [27 x i8] c"GetExceptionCode(): 0x%lx\0A\00", align 1 7 8declare i32 @_except_handler3(...) 9declare void @crash() 10declare i32 @printf(i8* nocapture readonly, ...) nounwind 11declare i32 @llvm.eh.typeid.for(i8*) 12declare i8* @llvm.frameaddress(i32) 13declare i8* @llvm.localrecover(i8*, i8*, i32) 14declare void @llvm.localescape(...) 15declare i8* @llvm.x86.seh.recoverfp(i8*, i8*) 16 17define i32 @main() personality i8* bitcast (i32 (...)* @_except_handler3 to i8*) { 18entry: 19 ; The EH code allocation is overaligned, triggering realignment. 20 %__exceptioncode = alloca i32, align 8 21 call void (...) @llvm.localescape(i32* %__exceptioncode) 22 invoke void @crash() #5 23 to label %__try.cont unwind label %lpad 24 25lpad: ; preds = %entry 26 %p = catchpad [i8* bitcast (i32 ()* @"filt$main" to i8*)] 27 to label %__except unwind label %endpad 28 29__except: ; preds = %lpad 30 %code = load i32, i32* %__exceptioncode, align 4 31 %call = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @str, i32 0, i32 0), i32 %code) #4 32 catchret %p to label %__try.cont 33 34endpad: 35 catchendpad unwind to caller 36 37__try.cont: ; preds = %entry, %__except 38 ret i32 0 39} 40 41define internal i32 @"filt$main"() { 42entry: 43 %ebp = tail call i8* @llvm.frameaddress(i32 1) 44 %parentfp = tail call i8* @llvm.x86.seh.recoverfp(i8* bitcast (i32 ()* @main to i8*), i8* %ebp) 45 %code.i8 = tail call i8* @llvm.localrecover(i8* bitcast (i32 ()* @main to i8*), i8* %parentfp, i32 0) 46 %__exceptioncode = bitcast i8* %code.i8 to i32* 47 %info.addr = getelementptr inbounds i8, i8* %ebp, i32 -20 48 %0 = bitcast i8* %info.addr to i32*** 49 %1 = load i32**, i32*** %0, align 4 50 %2 = load i32*, i32** %1, align 4 51 %3 = load i32, i32* %2, align 4 52 store i32 %3, i32* %__exceptioncode, align 4 53 ret i32 1 54} 55 56; Check that we can get the exception code from eax to the printf. 57 58; CHECK-LABEL: _main: 59; CHECK: Lmain$frame_escape_0 = [[code_offs:[-0-9]+]] 60; CHECK: movl %esp, [[reg_offs:[-0-9]+]](%esi) 61; CHECK: movl $L__ehtable$main, 62; EH state 0 63; CHECK: movl $0, 40(%esi) 64; CHECK: calll _crash 65; CHECK: retl 66; CHECK: LBB0_[[lpbb:[0-9]+]]: # %lpad 67; Restore ESP 68; CHECK: movl -24(%ebp), %esp 69; Restore ESI 70; CHECK: leal -44(%ebp), %esi 71; Restore EBP 72; CHECK: movl 12(%esi), %ebp 73; CHECK: movl [[code_offs]](%esi), %[[code:[a-z]+]] 74; CHECK-DAG: movl %[[code]], 4(%esp) 75; CHECK-DAG: movl $_str, (%esp) 76; CHECK: calll _printf 77 78; CHECK: .section .xdata,"dr" 79; CHECK: Lmain$parent_frame_offset = [[reg_offs]] 80; CHECK: L__ehtable$main 81; CHECK-NEXT: .long -1 82; CHECK-NEXT: .long _filt$main 83; CHECK-NEXT: .long LBB0_[[lpbb]] 84 85; CHECK-LABEL: _filt$main: 86; CHECK: pushl %ebp 87; CHECK: movl %esp, %ebp 88; CHECK: movl (%ebp), %[[oldebp:[a-z]+]] 89; CHECK: movl -20(%[[oldebp]]), %[[ehinfo:[a-z]+]] 90; CHECK: movl (%[[ehinfo]]), %[[ehrec:[a-z]+]] 91; CHECK: movl (%[[ehrec]]), %[[ehcode:[a-z]+]] 92; CHECK: movl %[[ehcode]], {{.*}}(%{{.*}}) 93