[WinEH] Make funclet return instrs pseudo instrs
[oota-llvm.git] / test / CodeGen / X86 / win-catchpad-csrs.ll
1 ; RUN: llc -mtriple=i686-pc-windows-msvc < %s | FileCheck --check-prefix=X86 %s
2 ; RUN: llc -mtriple=x86_64-pc-windows-msvc < %s | FileCheck --check-prefix=X64 %s
3
4 %rtti.TypeDescriptor2 = type { i8**, i8*, [3 x i8] }
5 %eh.CatchableType = type { i32, i8*, i32, i32, i32, i32, i8* }
6 %eh.CatchableTypeArray.1 = type { i32, [1 x %eh.CatchableType*] }
7 %eh.ThrowInfo = type { i32, i8*, i8*, i8* }
8
9 $"\01??_R0H@8" = comdat any
10
11 @"\01??_7type_info@@6B@" = external constant i8*
12 @"\01??_R0H@8" = linkonce_odr global %rtti.TypeDescriptor2 { i8** @"\01??_7type_info@@6B@", i8* null, [3 x i8] c".H\00" }, comdat
13
14 declare i32 @getint()
15 declare void @useints(...)
16 declare void @f(i32 %p)
17 declare i32 @__CxxFrameHandler3(...)
18
19 define i32 @try_catch_catch() personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*) {
20 entry:
21   %a = call i32 @getint()
22   %b = call i32 @getint()
23   %c = call i32 @getint()
24   %d = call i32 @getint()
25   call void (...) @useints(i32 %a, i32 %b, i32 %c, i32 %d)
26   invoke void @f(i32 1)
27           to label %try.cont unwind label %catch.dispatch
28
29 catch.dispatch:                                   ; preds = %entry
30   %0 = catchpad [%rtti.TypeDescriptor2* @"\01??_R0H@8", i32 0, i8* null]
31           to label %catch unwind label %catchendblock
32
33 catch:
34   invoke void @f(i32 2)
35           to label %invoke.cont.2 unwind label %catchendblock
36
37 invoke.cont.2:                                    ; preds = %catch
38   catchret %0 to label %try.cont
39
40 try.cont:                                         ; preds = %entry, %invoke.cont.2, %invoke.cont.3
41   ret i32 0
42
43 catchendblock:                                    ; preds = %catch,
44   catchendpad unwind to caller
45 }
46
47 ; X86-LABEL: _try_catch_catch:
48 ; X86: pushl %ebp
49 ; X86: movl %esp, %ebp
50 ; X86: pushl %ebx
51 ; X86: pushl %edi
52 ; X86: pushl %esi
53 ; X86: subl ${{[0-9]+}}, %esp
54 ; X86: calll _getint
55 ; X86: calll _getint
56 ; X86: calll _getint
57 ; X86: calll _getint
58 ; X86: calll _useints
59 ; X86: movl $0, -{{[0-9]+}}(%ebp)
60 ; X86: movl $1, (%esp)
61 ; X86: calll _f
62 ; X86: [[contbb:LBB0_[0-9]+]]: # %try.cont
63 ; X86: popl %esi
64 ; X86: popl %edi
65 ; X86: popl %ebx
66 ; X86: popl %ebp
67 ; X86: retl
68
69 ; X86: [[catch1bb:LBB0_[0-9]+]]: # %catch{{$}}
70 ; X86: pushl %ebp
71 ; X86-NOT: pushl
72 ; X86: addl $12, %ebp
73 ; X86: subl $16, %esp
74 ; X86: movl $1, -{{[0-9]+}}(%ebp)
75 ; X86: movl $2, (%esp)
76 ; X86: calll _f
77 ; X86: addl $16, %esp
78 ; X86-NEXT: popl %ebp
79 ; X86-NEXT: movl $[[restorebb:LBB0_[0-9]+]], %eax
80 ; X86-NEXT: retl
81
82 ; FIXME: Lay this out in the parent funclet.
83 ; X86: [[restorebb]]:
84 ; X86: movl -16(%ebp), %esp
85 ; X86: addl $12, %ebp
86 ; X86: jmp [[contbb]]
87
88 ; X86: L__ehtable$try_catch_catch:
89 ; X86: $handlerMap$0$try_catch_catch:
90 ; X86:   .long   0
91 ; X86:   .long   "??_R0H@8"
92 ; X86:   .long   0
93 ; X86:   .long   [[catch1bb]]
94
95 ; X64-LABEL: try_catch_catch:
96 ; X64: pushq %rbp
97 ; X64: .seh_pushreg 5
98 ; X64: pushq %rsi
99 ; X64: .seh_pushreg 6
100 ; X64: pushq %rdi
101 ; X64: .seh_pushreg 7
102 ; X64: pushq %rbx
103 ; X64: .seh_pushreg 3
104 ; X64: subq $40, %rsp
105 ; X64: .seh_stackalloc 40
106 ; X64: leaq 32(%rsp), %rbp
107 ; X64: .seh_setframe 5, 32
108 ; X64: callq getint
109 ; X64: callq getint
110 ; X64: callq getint
111 ; X64: callq getint
112 ; X64: callq useints
113 ; X64: movl $1, %ecx
114 ; X64: callq f
115 ; X64: [[contbb:\.LBB0_[0-9]+]]: # %try.cont
116 ; X64: addq $40, %rsp
117 ; X64: popq %rbp
118 ; X64: retq
119
120 ; X64: [[catch1bb:\.LBB0_[0-9]+]]: # %catch{{$}}
121 ; X64: movq %rdx, 16(%rsp)
122 ; X64: pushq %rbp
123 ; X64: movq %rdx, %rbp
124 ; X64: subq $32, %rsp
125 ; X64: movl $2, %ecx
126 ; X64: callq f
127 ; X64: addq $32, %rsp
128 ; X64: popq %rbp
129 ; X64: leaq [[contbb]](%rip), %rax
130 ; X64: retq
131
132 ; X64: $handlerMap$0$try_catch_catch:
133 ; X64:   .long   0
134 ; X64:   .long   "??_R0H@8"@IMGREL
135 ; X64:   .long   0
136 ; X64:   .long   [[catch1bb]]@IMGREL
137 ; X64:   .long   56