xref: /llvm-project/llvm/test/CodeGen/X86/windows-seh-EHa-CppCatchDotDotDot.ll (revision b9ae06ba15936c9802d5668cea260ad36a243a10)
1; RUN: llc -verify-machineinstrs < %s | FileCheck %s
2
3; CHECK-LABEL: "$cppxdata$?crash@@YAXH@Z":
4; CHECK:	.long	("$stateUnwindMap$?crash@@YAXH@Z")
5; CHECK:        .long   ("$tryMap$?crash@@YAXH@Z")@IMGREL # TryBlockMap
6; CHECK-NEXT:   .long   6                       # IPMapEntries
7; CHECK-NEXT:	.long	("$ip2state$?crash@@YAXH@Z")
8
9; CHECK-LABEL: "$stateUnwindMap$?crash@@YAXH@Z":
10; CHECK-NEXT:        .long   -1
11; CHECK-NEXT:        .long   0
12; CHECK-NEXT:        .long   0
13; CHECK-NEXT:        .long   "?dtor$
14; CHECK-NEXT:        .long   -1
15; CHECK-NEXT:        .long   0
16
17; CHECK-LABEL: "$tryMap$?crash@@YAXH@Z":
18; CHECK-NEXT:        .long   0
19; CHECK-NEXT:        .long   1
20; CHECK-NEXT:        .long   2
21; CHECK-NEXT:        .long   1
22; CHECK-NEXT:        .long   ("$handlerMap$
23
24; CHECK:       "$handlerMap$0$?crash@@YAXH@Z"
25; CHECK-NEXT:        .long   0
26; CHECK-NEXT:        .long   0
27; CHECK-NEXT:        .long   0
28; CHECK-NEXT:        .long   "?catch$
29
30; CHECK-LABEL: "$ip2state$?crash@@YAXH@Z":
31; CHECK-NEXT:	.long	.Lfunc_begin0@IMGREL
32; CHECK-NEXT:	.long	-1
33; CHECK-NEXT:	.long	.Ltmp
34; CHECK-NEXT:	.long	0
35; CHECK-NEXT:	.long	.Ltmp
36; CHECK-NEXT:	.long	1
37; CHECK-NEXT:	.long	.Ltmp
38; CHECK-NEXT:	.long	0
39; CHECK-NEXT:	.long	.Ltmp
40; CHECK-NEXT:	.long	-1
41; CHECK-NEXT:	.long	"?catch$
42; CHECK-NEXT:	.long	2
43
44; ModuleID = 'windows-seh-EHa-CppCatchDotDotDot.cpp'
45source_filename = "windows-seh-EHa-CppCatchDotDotDot.cpp"
46target datalayout = "e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
47target triple = "x86_64-unknown-windows-msvc"
48
49%rtti.TypeDescriptor2 = type { ptr, ptr, [3 x i8] }
50%eh.CatchableType = type { i32, i32, i32, i32, i32, i32, i32 }
51%eh.CatchableTypeArray.1 = type { i32, [1 x i32] }
52%eh.ThrowInfo = type { i32, i32, i32, i32 }
53%struct.A = type { i8 }
54
55$"??_C@_0BJ@EIKFKKLB@?5in?5catch?$CI?4?4?4?$CJ?5funclet?5?6?$AA@" = comdat any
56
57$"??_R0H@8" = comdat any
58
59$"_CT??_R0H@84" = comdat any
60
61$_CTA1H = comdat any
62
63$_TI1H = comdat any
64
65$"??_C@_0CN@MKCAOFNA@?5Test?5CPP?5unwind?3?5in?5except?5hand@" = comdat any
66
67$"??_C@_0N@LJHFFAKD@?5in?5A?5ctor?5?6?$AA@" = comdat any
68
69$"??_C@_0N@HMNCGOCN@?5in?5A?5dtor?5?6?$AA@" = comdat any
70
71@"?pt1@@3PEAHEA" = dso_local global ptr null, align 8
72@"?pt2@@3PEAHEA" = dso_local global ptr null, align 8
73@"?pt3@@3PEAHEA" = dso_local global ptr null, align 8
74@"?g@@3HA" = dso_local global i32 0, align 4
75@"??_C@_0BJ@EIKFKKLB@?5in?5catch?$CI?4?4?4?$CJ?5funclet?5?6?$AA@" = linkonce_odr dso_local unnamed_addr constant [25 x i8] c" in catch(...) funclet \0A\00", comdat, align 1
76@"??_7type_info@@6B@" = external constant ptr
77@"??_R0H@8" = linkonce_odr global %rtti.TypeDescriptor2 { ptr @"??_7type_info@@6B@", ptr null, [3 x i8] c".H\00" }, comdat
78@__ImageBase = external dso_local constant i8
79@"_CT??_R0H@84" = linkonce_odr unnamed_addr constant %eh.CatchableType { i32 1, i32 trunc (i64 sub nuw nsw (i64 ptrtoint (ptr @"??_R0H@8" to i64), i64 ptrtoint (ptr @__ImageBase to i64)) to i32), i32 0, i32 -1, i32 0, i32 4, i32 0 }, section ".xdata", comdat
80@_CTA1H = linkonce_odr unnamed_addr constant %eh.CatchableTypeArray.1 { i32 1, [1 x i32] [i32 trunc (i64 sub nuw nsw (i64 ptrtoint (ptr @"_CT??_R0H@84" to i64), i64 ptrtoint (ptr @__ImageBase to i64)) to i32)] }, section ".xdata", comdat
81@_TI1H = linkonce_odr unnamed_addr constant %eh.ThrowInfo { i32 0, i32 0, i32 0, i32 trunc (i64 sub nuw nsw (i64 ptrtoint (ptr @_CTA1H to i64), i64 ptrtoint (ptr @__ImageBase to i64)) to i32) }, section ".xdata", comdat
82@"??_C@_0CN@MKCAOFNA@?5Test?5CPP?5unwind?3?5in?5except?5hand@" = linkonce_odr dso_local unnamed_addr constant [45 x i8] c" Test CPP unwind: in except handler i = %d \0A\00", comdat, align 1
83@"??_C@_0N@LJHFFAKD@?5in?5A?5ctor?5?6?$AA@" = linkonce_odr dso_local unnamed_addr constant [13 x i8] c" in A ctor \0A\00", comdat, align 1
84@"??_C@_0N@HMNCGOCN@?5in?5A?5dtor?5?6?$AA@" = linkonce_odr dso_local unnamed_addr constant [13 x i8] c" in A dtor \0A\00", comdat, align 1
85
86; Function Attrs: noinline nounwind optnone
87define dso_local void @"?foo@@YAXXZ"() #0 {
88entry:
89  store volatile i32 0, ptr inttoptr (i64 17 to ptr), align 4
90  ret void
91}
92
93; Function Attrs: noinline optnone
94define dso_local void @"?crash@@YAXH@Z"(i32 %i) #1 personality ptr @__CxxFrameHandler3 {
95entry:
96  %i.addr = alloca i32, align 4
97  %ObjA = alloca %struct.A, align 1
98  %tmp = alloca i32, align 4
99  store i32 %i, ptr %i.addr, align 4
100  %0 = load i32, ptr %i.addr, align 4
101  store i32 %0, ptr @"?g@@3HA", align 4
102  invoke void @llvm.seh.try.begin()
103          to label %invoke.cont unwind label %catch.dispatch
104
105invoke.cont:                                      ; preds = %entry
106  %call = invoke ptr @"??0A@?1??crash@@YAXH@Z@QEAA@XZ"(ptr %ObjA)
107          to label %invoke.cont1 unwind label %catch.dispatch
108
109invoke.cont1:                                     ; preds = %invoke.cont
110  invoke void @llvm.seh.scope.begin()
111          to label %invoke.cont2 unwind label %ehcleanup
112
113invoke.cont2:                                     ; preds = %invoke.cont1
114  %1 = load i32, ptr %i.addr, align 4
115  %cmp = icmp eq i32 %1, 1
116  br i1 %cmp, label %if.then, label %if.end
117
118if.then:                                          ; preds = %invoke.cont2
119  store volatile i32 0, ptr inttoptr (i64 17 to ptr), align 4
120  br label %if.end
121
122if.end:                                           ; preds = %if.then, %invoke.cont2
123  invoke void @llvm.seh.scope.end()
124          to label %invoke.cont3 unwind label %ehcleanup
125
126invoke.cont3:                                     ; preds = %if.end
127  call void @"??1A@?1??crash@@YAXH@Z@QEAA@XZ"(ptr %ObjA) #6
128  br label %try.cont
129
130ehcleanup:                                        ; preds = %if.end, %invoke.cont1
131  %2 = cleanuppad within none []
132  call void @"??1A@?1??crash@@YAXH@Z@QEAA@XZ"(ptr %ObjA) #6 [ "funclet"(token %2) ]
133  cleanupret from %2 unwind label %catch.dispatch
134
135catch.dispatch:                                   ; preds = %ehcleanup, %invoke.cont, %entry
136  %3 = catchswitch within none [label %catch] unwind to caller
137
138catch:                                            ; preds = %catch.dispatch
139  %4 = catchpad within %3 [ptr null, i32 0, ptr null]
140  call void (...) @"?printf@@YAXZZ"(ptr @"??_C@_0BJ@EIKFKKLB@?5in?5catch?$CI?4?4?4?$CJ?5funclet?5?6?$AA@") [ "funclet"(token %4) ]
141  %5 = load i32, ptr %i.addr, align 4
142  %cmp4 = icmp eq i32 %5, 1
143  br i1 %cmp4, label %if.then5, label %if.end6
144
145if.then5:                                         ; preds = %catch
146  %6 = load i32, ptr %i.addr, align 4
147  store i32 %6, ptr %tmp, align 4
148  %7 = bitcast ptr %tmp to ptr
149  call void @_CxxThrowException(ptr %7, ptr @_TI1H) #7 [ "funclet"(token %4) ]
150  unreachable
151
152if.end6:                                          ; preds = %catch
153  catchret from %4 to label %catchret.dest
154
155catchret.dest:                                    ; preds = %if.end6
156  br label %try.cont
157
158try.cont:                                         ; preds = %catchret.dest, %invoke.cont3
159  ret void
160}
161
162; Function Attrs: nounwind willreturn
163declare dso_local void @llvm.seh.try.begin() #2
164
165declare dso_local i32 @__CxxFrameHandler3(...)
166
167; Function Attrs: noinline optnone
168define internal ptr @"??0A@?1??crash@@YAXH@Z@QEAA@XZ"(ptr returned %this) unnamed_addr #1 align 2 {
169entry:
170  %retval = alloca ptr, align 8
171  %this.addr = alloca ptr, align 8
172  store ptr %this, ptr %this.addr, align 8
173  %this1 = load ptr, ptr %this.addr, align 8
174  store ptr %this1, ptr %retval, align 8
175  call void (...) @"?printf@@YAXZZ"(ptr @"??_C@_0N@LJHFFAKD@?5in?5A?5ctor?5?6?$AA@")
176  %0 = load i32, ptr @"?g@@3HA", align 4
177  %cmp = icmp eq i32 %0, 0
178  br i1 %cmp, label %if.then, label %if.end
179
180if.then:                                          ; preds = %entry
181  store volatile i32 0, ptr inttoptr (i64 17 to ptr), align 4
182  br label %if.end
183
184if.end:                                           ; preds = %if.then, %entry
185  %1 = load ptr, ptr %retval, align 8
186  ret ptr %1
187}
188
189; Function Attrs: nounwind readnone
190declare dso_local void @llvm.seh.scope.begin() #3
191
192; Function Attrs: nounwind readnone
193declare dso_local void @llvm.seh.scope.end() #3
194
195; Function Attrs: noinline nounwind optnone
196define internal void @"??1A@?1??crash@@YAXH@Z@QEAA@XZ"(ptr %this) unnamed_addr #0 align 2 {
197entry:
198  %this.addr = alloca ptr, align 8
199  store ptr %this, ptr %this.addr, align 8
200  %this1 = load ptr, ptr %this.addr, align 8
201  call void (...) @"?printf@@YAXZZ"(ptr @"??_C@_0N@HMNCGOCN@?5in?5A?5dtor?5?6?$AA@")
202  ret void
203}
204
205declare dso_local void @"?printf@@YAXZZ"(...) #4
206
207declare dso_local void @_CxxThrowException(ptr, ptr)
208
209; Function Attrs: noinline norecurse optnone
210define dso_local i32 @main() #5 personality ptr @__C_specific_handler {
211entry:
212  %retval = alloca i32, align 4
213  %i = alloca i32, align 4
214  %__exception_code = alloca i32, align 4
215  store i32 0, ptr %retval, align 4
216  store i32 0, ptr %i, align 4
217  br label %for.cond
218
219for.cond:                                         ; preds = %for.inc, %entry
220  %0 = load i32, ptr %i, align 4
221  %cmp = icmp slt i32 %0, 2
222  br i1 %cmp, label %for.body, label %for.end
223
224for.body:                                         ; preds = %for.cond
225  invoke void @llvm.seh.try.begin()
226          to label %invoke.cont unwind label %catch.dispatch
227
228invoke.cont:                                      ; preds = %for.body
229  %1 = load volatile i32, ptr %i, align 4
230  invoke void @"?crash@@YAXH@Z"(i32 %1) #8
231          to label %invoke.cont1 unwind label %catch.dispatch
232
233invoke.cont1:                                     ; preds = %invoke.cont
234  invoke void @llvm.seh.try.end()
235          to label %invoke.cont2 unwind label %catch.dispatch
236
237catch.dispatch:                                   ; preds = %invoke.cont1, %invoke.cont, %for.body
238  %2 = catchswitch within none [label %__except] unwind to caller
239
240__except:                                         ; preds = %catch.dispatch
241  %3 = catchpad within %2 [ptr null]
242  catchret from %3 to label %__except3
243
244__except3:                                        ; preds = %__except
245  %4 = call i32 @llvm.eh.exceptioncode(token %3)
246  store i32 %4, ptr %__exception_code, align 4
247  %5 = load i32, ptr %i, align 4
248  call void (...) @"?printf@@YAXZZ"(ptr @"??_C@_0CN@MKCAOFNA@?5Test?5CPP?5unwind?3?5in?5except?5hand@", i32 %5)
249  br label %__try.cont
250
251__try.cont:                                       ; preds = %__except3, %invoke.cont2
252  br label %for.inc
253
254for.inc:                                          ; preds = %__try.cont
255  %6 = load i32, ptr %i, align 4
256  %inc = add nsw i32 %6, 1
257  store i32 %inc, ptr %i, align 4
258  br label %for.cond
259
260invoke.cont2:                                     ; preds = %invoke.cont1
261  br label %__try.cont
262
263for.end:                                          ; preds = %for.cond
264  ret i32 0
265}
266
267declare dso_local i32 @__C_specific_handler(...)
268
269; Function Attrs: nounwind willreturn
270declare dso_local void @llvm.seh.try.end() #2
271
272; Function Attrs: nounwind readnone
273declare i32 @llvm.eh.exceptioncode(token) #3
274
275attributes #0 = { noinline nounwind optnone "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "frame-pointer"="none" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-features"="+cx8,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
276attributes #1 = { noinline optnone "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "frame-pointer"="none" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-features"="+cx8,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
277attributes #2 = { nounwind willreturn }
278attributes #3 = { nounwind readnone }
279attributes #4 = { "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "frame-pointer"="none" "less-precise-fpmad"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-features"="+cx8,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
280attributes #5 = { noinline norecurse optnone "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "frame-pointer"="none" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-features"="+cx8,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
281attributes #6 = { nounwind }
282attributes #7 = { noreturn }
283attributes #8 = { noinline }
284
285!llvm.module.flags = !{!0, !1}
286
287!0 = !{i32 1, !"wchar_size", i32 2}
288!1 = !{i32 2, !"eh-asynch", i32 1}
289
290
291