[WinEH] Add 32-bit SEH state table emission prototype
[oota-llvm.git] / test / CodeGen / X86 / seh-catch-all.ll
1 ; RUN: llc -mtriple=x86_64-windows-msvc < %s | FileCheck %s --check-prefix=X64
2 ; RUN: sed -e 's/__C_specific_handler/_except_handler3/' %s | \
3 ; RUN:         llc -mtriple=i686-windows-msvc | FileCheck %s --check-prefix=X86
4
5 @str = linkonce_odr unnamed_addr constant [27 x i8] c"GetExceptionCode(): 0x%lx\0A\00", align 1
6
7 declare i32 @__C_specific_handler(...)
8 declare void @crash()
9 declare i32 @printf(i8* nocapture readonly, ...) nounwind
10
11 define i32 @main() {
12 entry:
13   invoke void @crash()
14           to label %__try.cont unwind label %lpad
15
16 lpad:
17   %0 = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__C_specific_handler to i8*)
18           catch i8* null
19   %1 = extractvalue { i8*, i32 } %0, 0
20   %2 = ptrtoint i8* %1 to i64
21   %3 = trunc i64 %2 to i32
22   call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @str, i64 0, i64 0), i32 %3)
23   br label %__try.cont
24
25 __try.cont:
26   ret i32 0
27
28 eh.resume:
29   resume { i8*, i32 } %0
30 }
31
32 ; Check that we can get the exception code from eax to the printf.
33
34 ; X64-LABEL: main:
35 ; X64: callq crash
36 ; X64: retq
37 ; X64: # Block address taken
38 ; X64: leaq str(%rip), %rcx
39 ; X64: movl %eax, %edx
40 ; X64: callq printf
41
42 ; X64: .seh_handlerdata
43 ; X64-NEXT: .long 1
44 ; X64-NEXT: .long .Ltmp{{[0-9]+}}@IMGREL
45 ; X64-NEXT: .long .Ltmp{{[0-9]+}}@IMGREL+1
46 ; X64-NEXT: .long 1
47 ; X64-NEXT: .long .Ltmp{{[0-9]+}}@IMGREL
48
49 ; X86-LABEL: _main:
50 ;       The EH code load should be this offset +4.
51 ; X86: movl %esp, -24(%ebp)
52 ; X86: movl $L__ehtable$main,
53 ;       EH state 0
54 ; X86: movl $0, -4(%ebp)
55 ; X86: calll _crash
56 ; X86: retl
57 ; X86: # Block address taken
58 ; X86: movl -20(%ebp), %[[ptrs:[^ ,]*]]
59 ; X86: movl (%[[ptrs]]), %[[rec:[^ ,]*]]
60 ; X86: movl (%[[rec]]), %[[code:[^ ,]*]]
61 ;       EH state -1
62 ; X86: movl $-1, -4(%ebp)
63 ; X86-DAG: movl %[[code]], 4(%esp)
64 ; X86-DAG: movl $_str, (%esp)
65 ; X86: calll _printf
66
67 ; X86: .section .xdata,"dr"
68 ; X86-NEXT: L__ehtable$main
69 ; X86-NEXT: .long -1
70 ; X86-NEXT: .long 1
71 ; X86-NEXT: .long Ltmp{{[0-9]+}}