xref: /llvm-project/llvm/test/CodeGen/X86/seh-catch-all-win32.ll (revision 2f448bf509432c1a19ec46ab8cbc7353c03c6280)
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(ptr nocapture readonly, ...) nounwind
11declare i32 @llvm.eh.typeid.for(ptr)
12declare ptr @llvm.frameaddress(i32)
13declare ptr @llvm.localrecover(ptr, ptr, i32)
14declare void @llvm.localescape(...)
15declare ptr @llvm.eh.recoverfp(ptr, ptr)
16
17define i32 @main() personality ptr @_except_handler3 {
18entry:
19  %__exceptioncode = alloca i32, align 4
20  call void (...) @llvm.localescape(ptr %__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 [ptr @"filt$main"]
29  %code = load i32, ptr %__exceptioncode, align 4
30  %call = call i32 (ptr, ...) @printf(ptr @str, 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 ptr @llvm.frameaddress(i32 1)
40  %parentfp = tail call ptr @llvm.eh.recoverfp(ptr @main, ptr %ebp)
41  %code.i8 = tail call ptr @llvm.localrecover(ptr @main, ptr %parentfp, i32 0)
42  %info.addr = getelementptr inbounds i8, ptr %ebp, i32 -20
43  %0 = load ptr, ptr %info.addr, align 4
44  %1 = load ptr, ptr %0, align 4
45  %2 = load i32, ptr %1, align 4
46  store i32 %2, ptr %code.i8, align 4
47  ret i32 1
48}
49
50; Check that we can get the exception code from eax to the printf.
51
52; CHECK-LABEL: _main:
53; CHECK: pushl %ebp
54; CHECK: movl %esp, %ebp
55;       Ensure that we push *all* the CSRs, since they are clobbered by the
56;       __except block.
57; CHECK: pushl %ebx
58; CHECK: pushl %edi
59; CHECK: pushl %esi
60
61; CHECK: .set Lmain$frame_escape_0, [[code_offs:[-0-9]+]]
62; CHECK: movl %esp, [[reg_offs:[-0-9]+]](%ebp)
63; CHECK: movl $L__ehtable$main,
64;       EH state 0
65; CHECK: movl $0, -16(%ebp)
66; CHECK: calll _crash
67; CHECK: popl %esi
68; CHECK: popl %edi
69; CHECK: popl %ebx
70; CHECK: retl
71; CHECK: LBB0_[[lpbb:[0-9]+]]: # %__except{{$}}
72;       stackrestore
73; CHECK: movl -24(%ebp), %esp
74;       EH state -1
75; CHECK: movl [[code_offs]](%ebp), %[[code:[a-z]+]]
76; CHECK: pushl %[[code]]
77; CHECK: pushl $_str
78; CHECK: calll _printf
79
80; CHECK: .section .xdata,"dr"
81; CHECK: .set Lmain$parent_frame_offset, [[reg_offs]]
82; CHECK: .p2align 2
83; CHECK: L__ehtable$main
84; CHECK-NEXT: .long -1
85; CHECK-NEXT: .long _filt$main
86; CHECK-NEXT: .long LBB0_[[lpbb]]
87
88; CHECK-LABEL: _filt$main:
89; CHECK: pushl %ebp
90; CHECK: movl %esp, %ebp
91; CHECK: movl (%ebp), %[[oldebp:[a-z]+]]
92; CHECK: movl -20(%[[oldebp]]), %[[ehinfo:[a-z]+]]
93; CHECK: movl (%[[ehinfo]]), %[[ehrec:[a-z]+]]
94; CHECK: movl (%[[ehrec]]), %[[ehcode:[a-z]+]]
95; CHECK: movl %[[ehcode]], {{.*}}(%{{.*}})
96