1; RUN: llc -stack-symbol-ordering=0 -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 %__exceptioncode = alloca i32, align 4 20 call void (...) @llvm.localescape(i32* %__exceptioncode) 21 invoke void @crash() #5 22 to label %__try.cont unwind label %lpad 23 24lpad: ; preds = %entry 25 %cs1 = catchswitch within none [label %__except] unwind to caller 26 27__except: ; preds = %lpad 28 %p = catchpad within %cs1 [i8* bitcast (i32 ()* @"filt$main" to i8*)] 29 %code = load i32, i32* %__exceptioncode, align 4 30 %call = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @str, i32 0, i32 0), i32 %code) #4 [ "funclet"(token %p) ] 31 catchret from %p to label %__try.cont 32 33__try.cont: ; preds = %entry, %__except 34 ret i32 0 35} 36 37define internal i32 @"filt$main"() { 38entry: 39 %ebp = tail call i8* @llvm.frameaddress(i32 1) 40 %parentfp = tail call i8* @llvm.x86.seh.recoverfp(i8* bitcast (i32 ()* @main to i8*), i8* %ebp) 41 %code.i8 = tail call i8* @llvm.localrecover(i8* bitcast (i32 ()* @main to i8*), i8* %parentfp, i32 0) 42 %__exceptioncode = bitcast i8* %code.i8 to i32* 43 %info.addr = getelementptr inbounds i8, i8* %ebp, i32 -20 44 %0 = bitcast i8* %info.addr to i32*** 45 %1 = load i32**, i32*** %0, align 4 46 %2 = load i32*, i32** %1, align 4 47 %3 = load i32, i32* %2, align 4 48 store i32 %3, i32* %__exceptioncode, align 4 49 ret i32 1 50} 51 52; Check that we can get the exception code from eax to the printf. 53 54; CHECK-LABEL: _main: 55; CHECK: pushl %ebp 56; CHECK: movl %esp, %ebp 57; Ensure that we push *all* the CSRs, since they are clobbered by the 58; __except block. 59; CHECK: pushl %ebx 60; CHECK: pushl %edi 61; CHECK: pushl %esi 62 63; CHECK: Lmain$frame_escape_0 = [[code_offs:[-0-9]+]] 64; CHECK: movl %esp, [[reg_offs:[-0-9]+]](%ebp) 65; CHECK: movl $L__ehtable$main, 66; EH state 0 67; CHECK: movl $0, -16(%ebp) 68; CHECK: calll _crash 69; CHECK: popl %esi 70; CHECK: popl %edi 71; CHECK: popl %ebx 72; CHECK: retl 73; CHECK: LBB0_[[lpbb:[0-9]+]]: # %__except{{$}} 74; stackrestore 75; CHECK: movl -24(%ebp), %esp 76; EH state -1 77; CHECK: movl [[code_offs]](%ebp), %[[code:[a-z]+]] 78; CHECK: pushl %[[code]] 79; CHECK: pushl $_str 80; CHECK: calll _printf 81 82; CHECK: .section .xdata,"dr" 83; CHECK: Lmain$parent_frame_offset = [[reg_offs]] 84; CHECK: .p2align 2 85; CHECK: L__ehtable$main 86; CHECK-NEXT: .long -1 87; CHECK-NEXT: .long _filt$main 88; CHECK-NEXT: .long LBB0_[[lpbb]] 89 90; CHECK-LABEL: _filt$main: 91; CHECK: pushl %ebp 92; CHECK: movl %esp, %ebp 93; CHECK: movl (%ebp), %[[oldebp:[a-z]+]] 94; CHECK: movl -20(%[[oldebp]]), %[[ehinfo:[a-z]+]] 95; CHECK: movl (%[[ehinfo]]), %[[ehrec:[a-z]+]] 96; CHECK: movl (%[[ehrec]]), %[[ehcode:[a-z]+]] 97; CHECK: movl %[[ehcode]], {{.*}}(%{{.*}}) 98