1; RUN: llc < %s | FileCheck %s
2
3; Verify that we get the right frame escape label when the catch comes after the
4; parent function.
5
6; This test case is equivalent to:
7; int main() {
8;   try {
9;     throw 42;
10;   } catch (int e) {
11;     printf("e: %d\n", e);
12;   }
13; }
14
15target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
16target triple = "x86_64-pc-windows-msvc"
17
18%rtti.TypeDescriptor2 = type { i8**, i8*, [3 x i8] }
19%eh.CatchableType = type { i32, i32, i32, i32, i32, i32, i32 }
20%eh.CatchableTypeArray.1 = type { i32, [1 x i32] }
21%eh.ThrowInfo = type { i32, i32, i32, i32 }
22%eh.CatchHandlerType = type { i32, i8* }
23
24$"\01??_R0H@8" = comdat any
25
26$"_CT??_R0H@84" = comdat any
27
28$_CTA1H = comdat any
29
30$_TI1H = comdat any
31
32$"\01??_C@_06PNOAJMHG@e?3?5?$CFd?6?$AA@" = comdat any
33
34@"\01??_7type_info@@6B@" = external constant i8*
35@"\01??_R0H@8" = linkonce_odr global %rtti.TypeDescriptor2 { i8** @"\01??_7type_info@@6B@", i8* null, [3 x i8] c".H\00" }, comdat
36@__ImageBase = external constant i8
37@"_CT??_R0H@84" = linkonce_odr unnamed_addr constant %eh.CatchableType { i32 1, i32 trunc (i64 sub nuw nsw (i64 ptrtoint (%rtti.TypeDescriptor2* @"\01??_R0H@8" to i64), i64 ptrtoint (i8* @__ImageBase to i64)) to i32), i32 0, i32 -1, i32 0, i32 4, i32 0 }, section ".xdata", comdat
38@_CTA1H = linkonce_odr unnamed_addr constant %eh.CatchableTypeArray.1 { i32 1, [1 x i32] [i32 trunc (i64 sub nuw nsw (i64 ptrtoint (%eh.CatchableType* @"_CT??_R0H@84" to i64), i64 ptrtoint (i8* @__ImageBase to i64)) to i32)] }, section ".xdata", comdat
39@_TI1H = linkonce_odr unnamed_addr constant %eh.ThrowInfo { i32 0, i32 0, i32 0, i32 trunc (i64 sub nuw nsw (i64 ptrtoint (%eh.CatchableTypeArray.1* @_CTA1H to i64), i64 ptrtoint (i8* @__ImageBase to i64)) to i32) }, section ".xdata", comdat
40@llvm.eh.handlertype.H.0 = private unnamed_addr constant %eh.CatchHandlerType { i32 0, i8* bitcast (%rtti.TypeDescriptor2* @"\01??_R0H@8" to i8*) }, section "llvm.metadata"
41@"\01??_C@_06PNOAJMHG@e?3?5?$CFd?6?$AA@" = linkonce_odr unnamed_addr constant [7 x i8] c"e: %d\0A\00", comdat, align 1
42
43declare void @_CxxThrowException(i8*, %eh.ThrowInfo*)
44
45; Function Attrs: uwtable
46define i32 @main() #1 {
47entry:
48  %tmp.i = alloca i32, align 4
49  %e = alloca i32, align 4
50  %0 = bitcast i32* %tmp.i to i8*
51  store i32 42, i32* %tmp.i, align 4, !tbaa !2
52  call void (...) @llvm.frameescape(i32* %e)
53  invoke void @_CxxThrowException(i8* %0, %eh.ThrowInfo* @_TI1H) #6
54          to label %.noexc unwind label %lpad1
55
56.noexc:                                           ; preds = %entry
57  unreachable
58
59lpad1:                                            ; preds = %entry
60  %1 = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*)
61          catch %eh.CatchHandlerType* @llvm.eh.handlertype.H.0
62  %recover = call i8* (...) @llvm.eh.actions(i32 1, i8* bitcast (%eh.CatchHandlerType* @llvm.eh.handlertype.H.0 to i8*), i32 0, i8* (i8*, i8*)* @main.catch)
63  indirectbr i8* %recover, [label %try.cont.split]
64
65try.cont.split:                                   ; preds = %lpad1
66  ret i32 0
67}
68
69; CHECK-LABEL: main:
70; CHECK:        .seh_handlerdata
71; CHECK:        .long   ($cppxdata$main)@IMGREL
72
73declare i32 @__CxxFrameHandler3(...)
74
75; Function Attrs: nounwind readnone
76declare i32 @llvm.eh.typeid.for(i8*) #2
77
78; Function Attrs: nounwind
79declare void @llvm.eh.begincatch(i8* nocapture, i8* nocapture) #3
80
81; Function Attrs: nounwind
82declare i32 @printf(i8* nocapture readonly, ...) #4
83
84; Function Attrs: nounwind
85declare void @llvm.eh.endcatch() #3
86
87; Function Attrs: nounwind
88declare void @llvm.lifetime.start(i64, i8* nocapture) #3
89
90; Function Attrs: nounwind
91declare i8* @llvm.eh.actions(...) #3
92
93define internal i8* @main.catch(i8*, i8*) #5 {
94entry:
95  %e.i8 = call i8* @llvm.framerecover(i8* bitcast (i32 ()* @main to i8*), i8* %1, i32 0)
96  %e = bitcast i8* %e.i8 to i32*
97  %2 = bitcast i32* %e to i8*
98  %3 = load i32, i32* %e, align 4, !tbaa !2
99  %call = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @"\01??_C@_06PNOAJMHG@e?3?5?$CFd?6?$AA@", i64 0, i64 0), i32 %3)
100  invoke void @llvm.donothing()
101          to label %entry.split unwind label %stub
102
103entry.split:                                      ; preds = %entry
104  ret i8* blockaddress(@main, %try.cont.split)
105
106stub:                                             ; preds = %entry
107  %4 = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*)
108          cleanup
109  unreachable
110}
111
112; CHECK-LABEL: main.catch:
113; CHECK:        .seh_handlerdata
114; CHECK:        .long   ($cppxdata$main)@IMGREL
115
116; CHECK-NEXT: $cppxdata$main:
117; CHECK-NEXT:         .long   429065506
118; CHECK-NEXT:         .long   2
119; CHECK-NEXT:         .long   ($stateUnwindMap$main)@IMGREL
120; CHECK-NEXT:         .long   1
121; CHECK-NEXT:         .long   ($tryMap$main)@IMGREL
122; CHECK-NEXT:         .long   1
123; CHECK-NEXT:         .long   ($ip2state$main)@IMGREL
124; CHECK-NEXT:         .long   40
125; CHECK-NEXT:         .long   0
126; CHECK-NEXT:         .long   1
127
128; Make sure we get the right frame escape label.
129
130; CHECK: $handlerMap$0$main:
131; CHECK-NEXT:         .long   0
132; CHECK-NEXT:         .long   "??_R0H@8"@IMGREL
133; CHECK-NEXT:         .long   .Lmain$frame_escape_0
134; CHECK-NEXT:         .long   main.catch@IMGREL
135; CHECK-NEXT:         .long   .Lmain.catch$parent_frame_offset
136
137; Function Attrs: nounwind readnone
138declare void @llvm.donothing() #2
139
140; Function Attrs: nounwind
141declare void @llvm.frameescape(...) #3
142
143; Function Attrs: nounwind readnone
144declare i8* @llvm.framerecover(i8*, i8*, i32) #2
145
146attributes #0 = { noreturn uwtable "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "unsafe-fp-math"="false" "use-soft-float"="false" }
147attributes #1 = { uwtable "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "unsafe-fp-math"="false" "use-soft-float"="false" "wineh-parent"="main" }
148attributes #2 = { nounwind readnone }
149attributes #3 = { nounwind }
150attributes #4 = { nounwind "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "unsafe-fp-math"="false" "use-soft-float"="false" }
151attributes #5 = { "wineh-parent"="main" }
152attributes #6 = { noreturn }
153
154!llvm.module.flags = !{!0}
155!llvm.ident = !{!1}
156
157!0 = !{i32 1, !"PIC Level", i32 2}
158!1 = !{!"clang version 3.7.0 "}
159!2 = !{!3, !3, i64 0}
160!3 = !{!"int", !4, i64 0}
161!4 = !{!"omnipotent char", !5, i64 0}
162!5 = !{!"Simple C/C++ TBAA"}
163
164