1 ; RUN: llc < %s | FileCheck %s
3 ; Verify that we get the right frame escape label when the catch comes after the
6 ; This test case is equivalent to:
11 ; printf("e: %d\n", e);
15 target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
16 target triple = "x86_64-pc-windows-msvc"
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* }
24 $"\01??_R0H@8" = comdat any
26 $"_CT??_R0H@84" = comdat any
32 $"\01??_C@_06PNOAJMHG@e?3?5?$CFd?6?$AA@" = comdat any
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
43 declare void @_CxxThrowException(i8*, %eh.ThrowInfo*)
45 ; Function Attrs: uwtable
46 define i32 @main() #1 personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*) {
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.localescape(i32* %e)
53 invoke void @_CxxThrowException(i8* %0, %eh.ThrowInfo* @_TI1H) #6
54 to label %.noexc unwind label %lpad1
56 .noexc: ; preds = %entry
59 lpad1: ; preds = %entry
60 %1 = landingpad { i8*, i32 }
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]
65 try.cont.split: ; preds = %lpad1
70 ; CHECK: .seh_handlerdata
71 ; CHECK: .long ($cppxdata$main)@IMGREL
73 declare i32 @__CxxFrameHandler3(...)
75 ; Function Attrs: nounwind readnone
76 declare i32 @llvm.eh.typeid.for(i8*) #2
78 ; Function Attrs: nounwind
79 declare void @llvm.eh.begincatch(i8* nocapture, i8* nocapture) #3
81 ; Function Attrs: nounwind
82 declare i32 @printf(i8* nocapture readonly, ...) #4
84 ; Function Attrs: nounwind
85 declare void @llvm.eh.endcatch() #3
87 ; Function Attrs: nounwind
88 declare void @llvm.lifetime.start(i64, i8* nocapture) #3
90 ; Function Attrs: nounwind
91 declare i8* @llvm.eh.actions(...) #3
93 define internal i8* @main.catch(i8*, i8*) #5 personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*) {
95 %e.i8 = call i8* @llvm.localrecover(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
103 entry.split: ; preds = %entry
104 ret i8* blockaddress(@main, %try.cont.split)
106 stub: ; preds = %entry
107 %4 = landingpad { i8*, i32 }
109 %recover = call i8* (...) @llvm.eh.actions()
113 ; CHECK-LABEL: main.catch:
114 ; CHECK: .seh_handlerdata
115 ; CHECK: .long ($cppxdata$main)@IMGREL
118 ; CHECK-NEXT: $cppxdata$main:
119 ; CHECK-NEXT: .long 429065506
120 ; CHECK-NEXT: .long 2
121 ; CHECK-NEXT: .long ($stateUnwindMap$main)@IMGREL
122 ; CHECK-NEXT: .long 1
123 ; CHECK-NEXT: .long ($tryMap$main)@IMGREL
124 ; CHECK-NEXT: .long 3
125 ; CHECK-NEXT: .long ($ip2state$main)@IMGREL
126 ; CHECK-NEXT: .long 40
127 ; CHECK-NEXT: .long 0
128 ; CHECK-NEXT: .long 1
130 ; Make sure we get the right frame escape label.
132 ; CHECK: $handlerMap$0$main:
133 ; CHECK-NEXT: .long 0
134 ; CHECK-NEXT: .long "??_R0H@8"@IMGREL
135 ; CHECK-NEXT: .long .Lmain$frame_escape_0
136 ; CHECK-NEXT: .long main.catch@IMGREL
137 ; CHECK-NEXT: .long .Lmain.catch$parent_frame_offset
139 ; Function Attrs: nounwind readnone
140 declare void @llvm.donothing() #2
142 ; Function Attrs: nounwind
143 declare void @llvm.localescape(...) #3
145 ; Function Attrs: nounwind readnone
146 declare i8* @llvm.localrecover(i8*, i8*, i32) #2
148 attributes #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" }
149 attributes #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" }
150 attributes #2 = { nounwind readnone }
151 attributes #3 = { nounwind }
152 attributes #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" }
153 attributes #5 = { "wineh-parent"="main" }
154 attributes #6 = { noreturn }
156 !llvm.module.flags = !{!0}
159 !0 = !{i32 1, !"PIC Level", i32 2}
160 !1 = !{!"clang version 3.7.0 "}
161 !2 = !{!3, !3, i64 0}
162 !3 = !{!"int", !4, i64 0}
163 !4 = !{!"omnipotent char", !5, i64 0}
164 !5 = !{!"Simple C/C++ TBAA"}