[WinEH] Fix ip2state table emission with funclets
[oota-llvm.git] / test / CodeGen / X86 / win-cleanuppad.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 %struct.Dtor = type { i8 }
5
6 define void @simple_cleanup() #0 personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*) {
7 entry:
8   %o = alloca %struct.Dtor, align 1
9   invoke void @f(i32 1)
10           to label %invoke.cont unwind label %ehcleanup
11
12 invoke.cont:                                      ; preds = %entry
13   call x86_thiscallcc void @"\01??1Dtor@@QAE@XZ"(%struct.Dtor* %o) #2
14   ret void
15
16 ehcleanup:                                        ; preds = %entry
17   %0 = cleanuppad []
18   call x86_thiscallcc void @"\01??1Dtor@@QAE@XZ"(%struct.Dtor* %o) #2
19   cleanupret %0 unwind to caller
20 }
21
22 declare void @f(i32) #0
23
24 declare i32 @__CxxFrameHandler3(...)
25
26 ; Function Attrs: nounwind
27 declare x86_thiscallcc void @"\01??1Dtor@@QAE@XZ"(%struct.Dtor*) #1
28
29 define void @nested_cleanup() #0 personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*) {
30 entry:
31   %o1 = alloca %struct.Dtor, align 1
32   %o2 = alloca %struct.Dtor, align 1
33   invoke void @f(i32 1)
34           to label %invoke.cont unwind label %cleanup.outer
35
36 invoke.cont:                                      ; preds = %entry
37   invoke void @f(i32 2)
38           to label %invoke.cont.1 unwind label %cleanup.inner
39
40 invoke.cont.1:                                    ; preds = %invoke.cont
41   call x86_thiscallcc void @"\01??1Dtor@@QAE@XZ"(%struct.Dtor* %o2) #2
42   invoke void @f(i32 3)
43           to label %invoke.cont.2 unwind label %cleanup.outer
44
45 invoke.cont.2:                                    ; preds = %invoke.cont.1
46   call x86_thiscallcc void @"\01??1Dtor@@QAE@XZ"(%struct.Dtor* %o1) #2
47   ret void
48
49 cleanup.inner:                                        ; preds = %invoke.cont
50   %0 = cleanuppad []
51   call x86_thiscallcc void @"\01??1Dtor@@QAE@XZ"(%struct.Dtor* %o2) #2
52   cleanupret %0 unwind label %cleanup.outer
53
54 cleanup.outer:                                      ; preds = %invoke.cont.1, %cleanup.inner, %entry
55   %1 = cleanuppad []
56   call x86_thiscallcc void @"\01??1Dtor@@QAE@XZ"(%struct.Dtor* %o1) #2
57   cleanupret %1 unwind to caller
58 }
59
60 ; X86-LABEL: _nested_cleanup:
61 ; X86: movl    $1, (%esp)
62 ; X86: calll   _f
63 ; X86: movl    $2, (%esp)
64 ; X86: calll   _f
65 ; X86: movl    $3, (%esp)
66 ; X86: calll   _f
67
68 ; X86: LBB1_[[cleanup_inner:[0-9]+]]: # %cleanup.inner
69 ; X86: pushl %ebp
70 ; X86: leal    {{.*}}(%ebp), %ecx
71 ; X86: calll   "??1Dtor@@QAE@XZ"
72 ; X86: popl %ebp
73 ; X86: retl
74
75 ; X86: LBB1_[[cleanup_outer:[0-9]+]]: # %cleanup.outer
76 ; X86: pushl %ebp
77 ; X86: leal    {{.*}}(%ebp), %ecx
78 ; X86: calll   "??1Dtor@@QAE@XZ"
79 ; X86: popl %ebp
80 ; X86: retl
81
82 ; X86: L__ehtable$nested_cleanup:
83 ; X86:         .long   429065506
84 ; X86:         .long   2
85 ; X86:         .long   ($stateUnwindMap$nested_cleanup)
86 ; X86:         .long   0
87 ; X86:         .long   0
88 ; X86:         .long   0
89 ; X86:         .long   0
90 ; X86:         .long   0
91 ; X86:         .long   1
92 ; X86: $stateUnwindMap$nested_cleanup:
93 ; X86:         .long   -1
94 ; X86:         .long   LBB1_[[cleanup_outer]]
95 ; X86:         .long   0
96 ; X86:         .long   LBB1_[[cleanup_inner]]
97
98 ; X64-LABEL: nested_cleanup:
99 ; X64: .Lfunc_begin1:
100 ; X64: .Ltmp8:
101 ; X64: movl    $1, %ecx
102 ; X64: callq   f
103 ; X64: .Ltmp10:
104 ; X64: movl    $2, %ecx
105 ; X64: callq   f
106 ; X64: .Ltmp11:
107 ; X64: callq   "??1Dtor@@QAE@XZ"
108 ; X64: .Ltmp12:
109 ; X64: movl    $3, %ecx
110 ; X64: callq   f
111 ; X64: .Ltmp13:
112
113 ; X64: .LBB1_[[cleanup_inner:[0-9]+]]: # %cleanup.inner
114 ; X64: pushq %rbp
115 ; X64: leaq    {{.*}}(%rbp), %rcx
116 ; X64: callq   "??1Dtor@@QAE@XZ"
117 ; X64: popq %rbp
118 ; X64: retq
119
120 ; X64: .LBB1_[[cleanup_outer:[0-9]+]]: # %cleanup.outer
121 ; X64: pushq %rbp
122 ; X64: leaq    {{.*}}(%rbp), %rcx
123 ; X64: callq   "??1Dtor@@QAE@XZ"
124 ; X64: popq %rbp
125 ; X64: retq
126
127 ; X64: .seh_handlerdata
128 ; X64-NEXT: .long   ($cppxdata$nested_cleanup)@IMGREL
129 ; X64-NEXT: .align  4
130 ; X64: $cppxdata$nested_cleanup:
131 ; X64-NEXT: .long   429065506
132 ; X64-NEXT: .long   2
133 ; X64-NEXT: .long   ($stateUnwindMap$nested_cleanup)@IMGREL
134 ; X64-NEXT: .long   0
135 ; X64-NEXT: .long   0
136 ; X64-NEXT: .long   5
137 ; X64-NEXT: .long   ($ip2state$nested_cleanup)@IMGREL
138 ; X64-NEXT: .long   40
139 ; X64-NEXT: .long   0
140 ; X64-NEXT: .long   1
141
142 ; X64: $stateUnwindMap$nested_cleanup:
143 ; X64-NEXT: .long   -1
144 ; X64-NEXT: .long   .LBB1_[[cleanup_outer]]@IMGREL
145 ; X64-NEXT: .long   0
146 ; X64-NEXT: .long   .LBB1_[[cleanup_inner]]@IMGREL
147
148 ; X64: $ip2state$nested_cleanup:
149 ; X64-NEXT: .long   .Lfunc_begin1@IMGREL
150 ; X64-NEXT: .long   -1
151 ; X64-NEXT: .long   .Ltmp8@IMGREL
152 ; X64-NEXT: .long   0
153 ; X64-NEXT: .long   .Ltmp10@IMGREL
154 ; X64-NEXT: .long   1
155 ; X64-NEXT: .long   .Ltmp12@IMGREL
156 ; X64-NEXT: .long   0
157 ; X64-NEXT: .long   .Ltmp13@IMGREL+1
158 ; X64-NEXT: .long   -1
159
160 attributes #0 = { "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-realign-stack" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
161 attributes #1 = { nounwind "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-realign-stack" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
162 attributes #2 = { nounwind }