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