|
| 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 | + |
| 8 | +declare i32 @_except_handler3(...) |
| 9 | +declare void @crash() |
| 10 | +declare i32 @printf(i8* nocapture readonly, ...) nounwind |
| 11 | +declare i32 @llvm.eh.typeid.for(i8*) |
| 12 | +declare i8* @llvm.frameaddress(i32) |
| 13 | +declare i8* @llvm.localrecover(i8*, i8*, i32) |
| 14 | +declare void @llvm.localescape(...) |
| 15 | +declare i8* @llvm.x86.seh.recoverfp(i8*, i8*) |
| 16 | + |
| 17 | +define i32 @main() personality i8* bitcast (i32 (...)* @_except_handler3 to i8*) { |
| 18 | +entry: |
| 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 | + |
| 25 | +lpad: ; preds = %entry |
| 26 | + %0 = landingpad { i8*, i32 } |
| 27 | + catch i8* bitcast (i32 ()* @"filt$main" to i8*) |
| 28 | + %1 = extractvalue { i8*, i32 } %0, 1 |
| 29 | + %2 = call i32 @llvm.eh.typeid.for(i8* bitcast (i32 ()* @"filt$main" to i8*)) #4 |
| 30 | + %matches = icmp eq i32 %1, %2 |
| 31 | + br i1 %matches, label %__except, label %eh.resume |
| 32 | + |
| 33 | +__except: ; preds = %lpad |
| 34 | + %3 = load i32, i32* %__exceptioncode, align 4 |
| 35 | + %call = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @str, i32 0, i32 0), i32 %3) #4 |
| 36 | + br label %__try.cont |
| 37 | + |
| 38 | +__try.cont: ; preds = %entry, %__except |
| 39 | + ret i32 0 |
| 40 | + |
| 41 | +eh.resume: ; preds = %lpad |
| 42 | + resume { i8*, i32 } %0 |
| 43 | +} |
| 44 | + |
| 45 | +define internal i32 @"filt$main"() { |
| 46 | +entry: |
| 47 | + %ebp = tail call i8* @llvm.frameaddress(i32 1) |
| 48 | + %parentfp = tail call i8* @llvm.x86.seh.recoverfp(i8* bitcast (i32 ()* @main to i8*), i8* %ebp) |
| 49 | + %code.i8 = tail call i8* @llvm.localrecover(i8* bitcast (i32 ()* @main to i8*), i8* %parentfp, i32 0) |
| 50 | + %__exceptioncode = bitcast i8* %code.i8 to i32* |
| 51 | + %info.addr = getelementptr inbounds i8, i8* %ebp, i32 -20 |
| 52 | + %0 = bitcast i8* %info.addr to i32*** |
| 53 | + %1 = load i32**, i32*** %0, align 4 |
| 54 | + %2 = load i32*, i32** %1, align 4 |
| 55 | + %3 = load i32, i32* %2, align 4 |
| 56 | + store i32 %3, i32* %__exceptioncode, align 4 |
| 57 | + ret i32 1 |
| 58 | +} |
| 59 | + |
| 60 | +; Check that we can get the exception code from eax to the printf. |
| 61 | + |
| 62 | +; CHECK-LABEL: _main: |
| 63 | +; CHECK: Lmain$frame_escape_0 = [[code_offs:[-0-9]+]] |
| 64 | +; CHECK: Lmain$frame_escape_1 = [[reg_offs:[-0-9]+]] |
| 65 | +; CHECK: movl %esp, [[reg_offs]](%esi) |
| 66 | +; CHECK: movl $L__ehtable$main, |
| 67 | +; EH state 0 |
| 68 | +; CHECK: movl $0, 40(%esi) |
| 69 | +; CHECK: calll _crash |
| 70 | +; CHECK: retl |
| 71 | +; CHECK: # Block address taken |
| 72 | +; Restore ESP |
| 73 | +; CHECK: movl -24(%ebp), %esp |
| 74 | +; Restore ESI |
| 75 | +; CHECK: movl $Lmain$parent_frame_offset, %eax |
| 76 | +; CHECK: negl %eax |
| 77 | +; CHECK: leal -24(%ebp,%eax), %esi |
| 78 | +; Restore EBP |
| 79 | +; CHECK: movl 12(%esi), %ebp # 4-byte Reload |
| 80 | +; EH state -1 |
| 81 | +; CHECK: movl [[code_offs]](%esi), %[[code:[a-z]+]] |
| 82 | +; CHECK: movl $-1, 40(%esi) |
| 83 | +; CHECK-DAG: movl %[[code]], 4(%esp) |
| 84 | +; CHECK-DAG: movl $_str, (%esp) |
| 85 | +; CHECK: calll _printf |
| 86 | + |
| 87 | +; CHECK: .section .xdata,"dr" |
| 88 | +; CHECK: Lmain$parent_frame_offset = Lmain$frame_escape_1 |
| 89 | +; CHECK: L__ehtable$main |
| 90 | +; CHECK-NEXT: .long -1 |
| 91 | +; CHECK-NEXT: .long _filt$main |
| 92 | +; CHECK-NEXT: .long Ltmp{{[0-9]+}} |
| 93 | + |
| 94 | +; CHECK-LABEL: _filt$main: |
| 95 | +; CHECK: pushl %ebp |
| 96 | +; CHECK: movl %esp, %ebp |
| 97 | +; CHECK: movl (%ebp), %[[oldebp:[a-z]+]] |
| 98 | +; CHECK: movl -20(%[[oldebp]]), %[[ehinfo:[a-z]+]] |
| 99 | +; CHECK: movl (%[[ehinfo]]), %[[ehrec:[a-z]+]] |
| 100 | +; CHECK: movl (%[[ehrec]]), %[[ehcode:[a-z]+]] |
| 101 | +; CHECK: movl %[[ehcode]], {{.*}}(%{{.*}}) |
0 commit comments