| Reid Kleckner | 6e3b5d4 | 2015-04-15 17:47:26 +0000 | [diff] [blame] | 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 | |
| 15 | target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128" |
| 16 | target 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 | |
| 43 | declare void @_CxxThrowException(i8*, %eh.ThrowInfo*) |
| 44 | |
| 45 | ; Function Attrs: uwtable |
| 46 | define i32 @main() #1 { |
| 47 | entry: |
| 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 |
| David Blaikie | 23af648 | 2015-04-16 23:24:18 +0000 | [diff] [blame] | 52 | call void (...) @llvm.frameescape(i32* %e) |
| Reid Kleckner | 6e3b5d4 | 2015-04-15 17:47:26 +0000 | [diff] [blame] | 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 | |
| 59 | lpad1: ; preds = %entry |
| 60 | %1 = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*) |
| 61 | catch %eh.CatchHandlerType* @llvm.eh.handlertype.H.0 |
| David Blaikie | 23af648 | 2015-04-16 23:24:18 +0000 | [diff] [blame] | 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) |
| Reid Kleckner | 6e3b5d4 | 2015-04-15 17:47:26 +0000 | [diff] [blame] | 63 | indirectbr i8* %recover, [label %try.cont.split] |
| 64 | |
| 65 | try.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 | |
| 73 | declare i32 @__CxxFrameHandler3(...) |
| 74 | |
| 75 | ; Function Attrs: nounwind readnone |
| 76 | declare i32 @llvm.eh.typeid.for(i8*) #2 |
| 77 | |
| 78 | ; Function Attrs: nounwind |
| 79 | declare void @llvm.eh.begincatch(i8* nocapture, i8* nocapture) #3 |
| 80 | |
| 81 | ; Function Attrs: nounwind |
| 82 | declare i32 @printf(i8* nocapture readonly, ...) #4 |
| 83 | |
| 84 | ; Function Attrs: nounwind |
| 85 | declare void @llvm.eh.endcatch() #3 |
| 86 | |
| 87 | ; Function Attrs: nounwind |
| 88 | declare void @llvm.lifetime.start(i64, i8* nocapture) #3 |
| 89 | |
| 90 | ; Function Attrs: nounwind |
| 91 | declare i8* @llvm.eh.actions(...) #3 |
| 92 | |
| 93 | define internal i8* @main.catch(i8*, i8*) #5 { |
| 94 | entry: |
| 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 |
| David Blaikie | 23af648 | 2015-04-16 23:24:18 +0000 | [diff] [blame] | 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) |
| Reid Kleckner | 6e3b5d4 | 2015-04-15 17:47:26 +0000 | [diff] [blame] | 100 | invoke void @llvm.donothing() |
| 101 | to label %entry.split unwind label %stub |
| 102 | |
| 103 | entry.split: ; preds = %entry |
| 104 | ret i8* blockaddress(@main, %try.cont.split) |
| 105 | |
| 106 | stub: ; preds = %entry |
| 107 | %4 = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*) |
| 108 | cleanup |
| Andrew Kaylor | 43e1d76 | 2015-04-23 00:20:44 +0000 | [diff] [blame] | 109 | %recover = call i8* (...) @llvm.eh.actions() |
| Reid Kleckner | 6e3b5d4 | 2015-04-15 17:47:26 +0000 | [diff] [blame] | 110 | unreachable |
| 111 | } |
| 112 | |
| 113 | ; CHECK-LABEL: main.catch: |
| 114 | ; CHECK: .seh_handlerdata |
| 115 | ; CHECK: .long ($cppxdata$main)@IMGREL |
| 116 | |
| 117 | ; CHECK-NEXT: $cppxdata$main: |
| 118 | ; CHECK-NEXT: .long 429065506 |
| 119 | ; CHECK-NEXT: .long 2 |
| 120 | ; CHECK-NEXT: .long ($stateUnwindMap$main)@IMGREL |
| 121 | ; CHECK-NEXT: .long 1 |
| 122 | ; CHECK-NEXT: .long ($tryMap$main)@IMGREL |
| Andrew Kaylor | 762a6be | 2015-05-11 19:41:19 +0000 | [diff] [blame] | 123 | ; CHECK-NEXT: .long 3 |
| Reid Kleckner | 6e3b5d4 | 2015-04-15 17:47:26 +0000 | [diff] [blame] | 124 | ; CHECK-NEXT: .long ($ip2state$main)@IMGREL |
| 125 | ; CHECK-NEXT: .long 40 |
| 126 | ; CHECK-NEXT: .long 0 |
| 127 | ; CHECK-NEXT: .long 1 |
| 128 | |
| 129 | ; Make sure we get the right frame escape label. |
| 130 | |
| 131 | ; CHECK: $handlerMap$0$main: |
| 132 | ; CHECK-NEXT: .long 0 |
| 133 | ; CHECK-NEXT: .long "??_R0H@8"@IMGREL |
| 134 | ; CHECK-NEXT: .long .Lmain$frame_escape_0 |
| 135 | ; CHECK-NEXT: .long main.catch@IMGREL |
| 136 | ; CHECK-NEXT: .long .Lmain.catch$parent_frame_offset |
| 137 | |
| 138 | ; Function Attrs: nounwind readnone |
| 139 | declare void @llvm.donothing() #2 |
| 140 | |
| 141 | ; Function Attrs: nounwind |
| 142 | declare void @llvm.frameescape(...) #3 |
| 143 | |
| 144 | ; Function Attrs: nounwind readnone |
| 145 | declare i8* @llvm.framerecover(i8*, i8*, i32) #2 |
| 146 | |
| 147 | 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" } |
| 148 | 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" } |
| 149 | attributes #2 = { nounwind readnone } |
| 150 | attributes #3 = { nounwind } |
| 151 | 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" } |
| 152 | attributes #5 = { "wineh-parent"="main" } |
| 153 | attributes #6 = { noreturn } |
| 154 | |
| 155 | !llvm.module.flags = !{!0} |
| 156 | !llvm.ident = !{!1} |
| 157 | |
| 158 | !0 = !{i32 1, !"PIC Level", i32 2} |
| 159 | !1 = !{!"clang version 3.7.0 "} |
| 160 | !2 = !{!3, !3, i64 0} |
| 161 | !3 = !{!"int", !4, i64 0} |
| 162 | !4 = !{!"omnipotent char", !5, i64 0} |
| 163 | !5 = !{!"Simple C/C++ TBAA"} |
| 164 | |