xref: /llvm-project/llvm/test/CodeGen/X86/seh-catch-all.ll (revision 2f448bf509432c1a19ec46ab8cbc7353c03c6280)
1; RUN: llc -mtriple=x86_64-windows-msvc < %s | FileCheck %s
2
3@str = linkonce_odr unnamed_addr constant [27 x i8] c"GetExceptionCode(): 0x%lx\0A\00", align 1
4
5declare i32 @llvm.eh.exceptioncode(token)
6declare i32 @__C_specific_handler(...)
7declare void @crash()
8declare i32 @printf(ptr nocapture readonly, ...) nounwind
9
10define i32 @main() personality ptr @__C_specific_handler {
11entry:
12  invoke void @crash()
13          to label %__try.cont unwind label %lpad
14
15__try.cont:
16  ret i32 0
17
18lpad:
19  %cs1 = catchswitch within none [label %catchall] unwind to caller
20
21catchall:
22  %p = catchpad within %cs1 [ptr null, i32 64, ptr null]
23  %code = call i32 @llvm.eh.exceptioncode(token %p)
24  call i32 (ptr, ...) @printf(ptr @str, i32 %code) [ "funclet"(token %p) ]
25  catchret from %p to label %__try.cont
26}
27
28; Check that we can get the exception code from eax to the printf.
29
30; CHECK-LABEL: main:
31; CHECK: callq crash
32; CHECK: retq
33; CHECK: .LBB0_2: # %catchall
34; CHECK: leaq str(%rip), %rcx
35; CHECK: movl %eax, %edx
36; CHECK: callq printf
37
38; CHECK: .seh_handlerdata
39; CHECK-NEXT: .Lmain$parent_frame_offset
40; CHECK-NEXT: .long (.Llsda_end0-.Llsda_begin0)/16
41; CHECK-NEXT: .Llsda_begin0:
42; CHECK-NEXT: .long .Ltmp{{[0-9]+}}@IMGREL
43; CHECK-NEXT: .long .Ltmp{{[0-9]+}}@IMGREL+1
44; CHECK-NEXT: .long 1
45; CHECK-NEXT: .long .LBB0_2@IMGREL
46; CHECK-NEXT: .Llsda_end0:
47