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