| Andrew Kaylor | 64622aa | 2015-04-01 17:21:25 +0000 | [diff] [blame] | 1 | ; RUN: opt -mtriple=x86_64-pc-windows-msvc -winehprepare -S -o - < %s | FileCheck %s |
| 2 | |
| 3 | ; This test is based on the following code: |
| 4 | ; |
| 5 | ; void test() |
| 6 | ; { |
| 7 | ; try { |
| 8 | ; may_throw(); |
| 9 | ; } catch (int i) { |
| 10 | ; handle_int(i); |
| 11 | ; } catch (long long ll) { |
| 12 | ; handle_long_long(ll); |
| 13 | ; } catch (SomeClass &obj) { |
| 14 | ; handle_obj(&obj); |
| 15 | ; } catch (...) { |
| 16 | ; handle_exception(); |
| 17 | ; } |
| 18 | ; } |
| 19 | ; |
| 20 | ; The catch handlers were edited to insert 'ret void' after the endcatch call. |
| 21 | |
| 22 | ; ModuleID = 'catch-with-type.cpp' |
| 23 | target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128" |
| 24 | target triple = "x86_64-pc-windows-msvc" |
| 25 | |
| 26 | %rtti.TypeDescriptor2 = type { i8**, i8*, [3 x i8] } |
| 27 | %eh.HandlerMapEntry = type { i32, i32 } |
| 28 | %rtti.TypeDescriptor3 = type { i8**, i8*, [4 x i8] } |
| 29 | %rtti.TypeDescriptor15 = type { i8**, i8*, [16 x i8] } |
| 30 | %class.SomeClass = type { i8 } |
| 31 | |
| 32 | $"\01??_R0H@8" = comdat any |
| 33 | |
| 34 | $"\01??_R0_J@8" = comdat any |
| 35 | |
| 36 | $"\01??_R0?AVSomeClass@@@8" = comdat any |
| 37 | |
| 38 | @"\01??_7type_info@@6B@" = external constant i8* |
| 39 | @"\01??_R0H@8" = linkonce_odr global %rtti.TypeDescriptor2 { i8** @"\01??_7type_info@@6B@", i8* null, [3 x i8] c".H\00" }, comdat |
| 40 | @__ImageBase = external constant i8 |
| 41 | @llvm.eh.handlermapentry.H = private unnamed_addr constant %eh.HandlerMapEntry { i32 0, i32 trunc (i64 sub nuw nsw (i64 ptrtoint (%rtti.TypeDescriptor2* @"\01??_R0H@8" to i64), i64 ptrtoint (i8* @__ImageBase to i64)) to i32) }, section "llvm.metadata" |
| 42 | @"\01??_R0_J@8" = linkonce_odr global %rtti.TypeDescriptor3 { i8** @"\01??_7type_info@@6B@", i8* null, [4 x i8] c"._J\00" }, comdat |
| 43 | @llvm.eh.handlermapentry._J = private unnamed_addr constant %eh.HandlerMapEntry { i32 0, i32 trunc (i64 sub nuw nsw (i64 ptrtoint (%rtti.TypeDescriptor3* @"\01??_R0_J@8" to i64), i64 ptrtoint (i8* @__ImageBase to i64)) to i32) }, section "llvm.metadata" |
| 44 | @"\01??_R0?AVSomeClass@@@8" = linkonce_odr global %rtti.TypeDescriptor15 { i8** @"\01??_7type_info@@6B@", i8* null, [16 x i8] c".?AVSomeClass@@\00" }, comdat |
| 45 | @"llvm.eh.handlermapentry.reference.?AVSomeClass@@" = private unnamed_addr constant %eh.HandlerMapEntry { i32 8, i32 trunc (i64 sub nuw nsw (i64 ptrtoint (%rtti.TypeDescriptor15* @"\01??_R0?AVSomeClass@@@8" to i64), i64 ptrtoint (i8* @__ImageBase to i64)) to i32) }, section "llvm.metadata" |
| 46 | |
| 47 | |
| David Majnemer | 7fddecc | 2015-06-17 20:52:32 +0000 | [diff] [blame^] | 48 | ; CHECK: define void @"\01?test@@YAXXZ"() #0 personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*) { |
| Andrew Kaylor | 64622aa | 2015-04-01 17:21:25 +0000 | [diff] [blame] | 49 | ; CHECK: entry: |
| Andrew Kaylor | 64622aa | 2015-04-01 17:21:25 +0000 | [diff] [blame] | 50 | ; CHECK: [[OBJ_PTR:\%.+]] = alloca %class.SomeClass*, align 8 |
| 51 | ; CHECK: [[LL_PTR:\%.+]] = alloca i64, align 8 |
| 52 | ; CHECK: [[I_PTR:\%.+]] = alloca i32, align 4 |
| David Blaikie | 23af648 | 2015-04-16 23:24:18 +0000 | [diff] [blame] | 53 | ; CHECK: call void (...) @llvm.frameescape(i32* [[I_PTR]], i64* [[LL_PTR]], %class.SomeClass** [[OBJ_PTR]]) |
| Andrew Kaylor | 64622aa | 2015-04-01 17:21:25 +0000 | [diff] [blame] | 54 | ; CHECK: invoke void @"\01?may_throw@@YAXXZ"() |
| Reid Kleckner | 2c3ccaa | 2015-04-24 16:22:19 +0000 | [diff] [blame] | 55 | ; CHECK: to label %invoke.cont unwind label %[[LPAD_LABEL:lpad[0-9]*]] |
| Andrew Kaylor | 64622aa | 2015-04-01 17:21:25 +0000 | [diff] [blame] | 56 | |
| 57 | ; Function Attrs: uwtable |
| David Majnemer | 7fddecc | 2015-06-17 20:52:32 +0000 | [diff] [blame^] | 58 | define void @"\01?test@@YAXXZ"() #0 personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*) { |
| Andrew Kaylor | 64622aa | 2015-04-01 17:21:25 +0000 | [diff] [blame] | 59 | entry: |
| 60 | %exn.slot = alloca i8* |
| 61 | %ehselector.slot = alloca i32 |
| 62 | %obj = alloca %class.SomeClass*, align 8 |
| 63 | %ll = alloca i64, align 8 |
| 64 | %i = alloca i32, align 4 |
| 65 | invoke void @"\01?may_throw@@YAXXZ"() |
| 66 | to label %invoke.cont unwind label %lpad |
| 67 | |
| 68 | invoke.cont: ; preds = %entry |
| 69 | br label %try.cont |
| 70 | |
| 71 | ; CHECK: [[LPAD_LABEL]]:{{[ ]+}}; preds = %entry |
| David Majnemer | 7fddecc | 2015-06-17 20:52:32 +0000 | [diff] [blame^] | 72 | ; CHECK: landingpad { i8*, i32 } |
| Andrew Kaylor | 64622aa | 2015-04-01 17:21:25 +0000 | [diff] [blame] | 73 | ; CHECK-NEXT: catch %eh.HandlerMapEntry* @llvm.eh.handlermapentry.H |
| 74 | ; CHECK-NEXT: catch %eh.HandlerMapEntry* @llvm.eh.handlermapentry._J |
| 75 | ; CHECK-NEXT: catch %eh.HandlerMapEntry* @"llvm.eh.handlermapentry.reference.?AVSomeClass@@" |
| 76 | ; CHECK-NEXT: catch i8* null |
| David Blaikie | 23af648 | 2015-04-16 23:24:18 +0000 | [diff] [blame] | 77 | ; CHECK-NEXT: [[RECOVER:\%.+]] = call i8* (...) @llvm.eh.actions( |
| Reid Kleckner | 3567d27 | 2015-04-02 21:13:31 +0000 | [diff] [blame] | 78 | ; CHECK-SAME: i32 1, i8* bitcast (%eh.HandlerMapEntry* @llvm.eh.handlermapentry.H to i8*), i32 0, i8* (i8*, i8*)* @"\01?test@@YAXXZ.catch", |
| Sunil Srivastava | d79dfcb | 2015-05-12 16:47:30 +0000 | [diff] [blame] | 79 | ; CHECK-SAME: i32 1, i8* bitcast (%eh.HandlerMapEntry* @llvm.eh.handlermapentry._J to i8*), i32 1, i8* (i8*, i8*)* @"\01?test@@YAXXZ.catch.1", |
| 80 | ; CHECK-SAME: i32 1, i8* bitcast (%eh.HandlerMapEntry* @"llvm.eh.handlermapentry.reference.?AVSomeClass@@" to i8*), i32 2, i8* (i8*, i8*)* @"\01?test@@YAXXZ.catch.2", |
| 81 | ; CHECK-SAME: i32 1, i8* null, i32 -1, i8* (i8*, i8*)* @"\01?test@@YAXXZ.catch.3") |
| Reid Kleckner | fd7df28 | 2015-04-22 21:05:21 +0000 | [diff] [blame] | 82 | ; CHECK-NEXT: indirectbr i8* [[RECOVER]], [label %ret] |
| Andrew Kaylor | 64622aa | 2015-04-01 17:21:25 +0000 | [diff] [blame] | 83 | |
| 84 | lpad: ; preds = %entry |
| David Majnemer | 7fddecc | 2015-06-17 20:52:32 +0000 | [diff] [blame^] | 85 | %0 = landingpad { i8*, i32 } |
| Andrew Kaylor | 64622aa | 2015-04-01 17:21:25 +0000 | [diff] [blame] | 86 | catch %eh.HandlerMapEntry* @llvm.eh.handlermapentry.H |
| 87 | catch %eh.HandlerMapEntry* @llvm.eh.handlermapentry._J |
| 88 | catch %eh.HandlerMapEntry* @"llvm.eh.handlermapentry.reference.?AVSomeClass@@" |
| 89 | catch i8* null |
| 90 | %1 = extractvalue { i8*, i32 } %0, 0 |
| 91 | store i8* %1, i8** %exn.slot |
| 92 | %2 = extractvalue { i8*, i32 } %0, 1 |
| 93 | store i32 %2, i32* %ehselector.slot |
| 94 | br label %catch.dispatch |
| 95 | |
| 96 | ; CHECK-NOT: catch.dispatch: |
| 97 | catch.dispatch: ; preds = %lpad |
| 98 | %sel = load i32, i32* %ehselector.slot |
| 99 | %3 = call i32 @llvm.eh.typeid.for(i8* bitcast (%eh.HandlerMapEntry* @llvm.eh.handlermapentry.H to i8*)) #3 |
| 100 | %matches = icmp eq i32 %sel, %3 |
| 101 | br i1 %matches, label %catch14, label %catch.fallthrough |
| 102 | |
| Reid Kleckner | fd7df28 | 2015-04-22 21:05:21 +0000 | [diff] [blame] | 103 | ret: |
| 104 | ret void |
| 105 | |
| Andrew Kaylor | 64622aa | 2015-04-01 17:21:25 +0000 | [diff] [blame] | 106 | ; CHECK-NOT: catch14: |
| Reid Kleckner | fd7df28 | 2015-04-22 21:05:21 +0000 | [diff] [blame] | 107 | ; CHECK: ret: |
| Andrew Kaylor | 64622aa | 2015-04-01 17:21:25 +0000 | [diff] [blame] | 108 | ; CHECK-NEXT: ret void |
| 109 | catch14: ; preds = %catch.dispatch |
| 110 | %exn15 = load i8*, i8** %exn.slot |
| 111 | %4 = bitcast i32* %i to i8* |
| 112 | call void @llvm.eh.begincatch(i8* %exn15, i8* %4) #3 |
| 113 | %5 = load i32, i32* %i, align 4 |
| 114 | call void @"\01?handle_int@@YAXH@Z"(i32 %5) |
| 115 | call void @llvm.eh.endcatch() #3 |
| Reid Kleckner | fd7df28 | 2015-04-22 21:05:21 +0000 | [diff] [blame] | 116 | br label %ret |
| Andrew Kaylor | 64622aa | 2015-04-01 17:21:25 +0000 | [diff] [blame] | 117 | |
| 118 | try.cont: ; preds = %invoke.cont |
| Reid Kleckner | fd7df28 | 2015-04-22 21:05:21 +0000 | [diff] [blame] | 119 | br label %ret |
| Andrew Kaylor | 64622aa | 2015-04-01 17:21:25 +0000 | [diff] [blame] | 120 | |
| 121 | ; CHECK-NOT: catch.fallthrough: |
| 122 | catch.fallthrough: ; preds = %catch.dispatch |
| 123 | %6 = call i32 @llvm.eh.typeid.for(i8* bitcast (%eh.HandlerMapEntry* @llvm.eh.handlermapentry._J to i8*)) #3 |
| 124 | %matches1 = icmp eq i32 %sel, %6 |
| 125 | br i1 %matches1, label %catch10, label %catch.fallthrough2 |
| 126 | |
| 127 | ; CHECK-NOT: catch10: |
| Andrew Kaylor | 64622aa | 2015-04-01 17:21:25 +0000 | [diff] [blame] | 128 | catch10: ; preds = %catch.fallthrough |
| 129 | %exn11 = load i8*, i8** %exn.slot |
| 130 | %7 = bitcast i64* %ll to i8* |
| 131 | call void @llvm.eh.begincatch(i8* %exn11, i8* %7) #3 |
| 132 | %8 = load i64, i64* %ll, align 8 |
| 133 | call void @"\01?handle_long_long@@YAX_J@Z"(i64 %8) |
| 134 | call void @llvm.eh.endcatch() #3 |
| Reid Kleckner | fd7df28 | 2015-04-22 21:05:21 +0000 | [diff] [blame] | 135 | br label %ret |
| Andrew Kaylor | 64622aa | 2015-04-01 17:21:25 +0000 | [diff] [blame] | 136 | |
| 137 | ; CHECK-NOT: catch.fallthrough2: |
| 138 | catch.fallthrough2: ; preds = %catch.fallthrough |
| 139 | %9 = call i32 @llvm.eh.typeid.for(i8* bitcast (%eh.HandlerMapEntry* @"llvm.eh.handlermapentry.reference.?AVSomeClass@@" to i8*)) #3 |
| 140 | %matches3 = icmp eq i32 %sel, %9 |
| 141 | br i1 %matches3, label %catch6, label %catch |
| 142 | |
| 143 | ; CHECK-NOT: catch6: |
| Andrew Kaylor | 64622aa | 2015-04-01 17:21:25 +0000 | [diff] [blame] | 144 | catch6: ; preds = %catch.fallthrough2 |
| 145 | %exn7 = load i8*, i8** %exn.slot |
| 146 | %10 = bitcast %class.SomeClass** %obj to i8* |
| 147 | call void @llvm.eh.begincatch(i8* %exn7, i8* %10) #3 |
| 148 | %11 = load %class.SomeClass*, %class.SomeClass** %obj, align 8 |
| 149 | call void @"\01?handle_obj@@YAXPEAVSomeClass@@@Z"(%class.SomeClass* %11) |
| 150 | call void @llvm.eh.endcatch() #3 |
| Reid Kleckner | fd7df28 | 2015-04-22 21:05:21 +0000 | [diff] [blame] | 151 | br label %ret |
| Andrew Kaylor | 64622aa | 2015-04-01 17:21:25 +0000 | [diff] [blame] | 152 | |
| 153 | ; CHECK-NOT: catch: |
| Andrew Kaylor | 64622aa | 2015-04-01 17:21:25 +0000 | [diff] [blame] | 154 | catch: ; preds = %catch.fallthrough2 |
| 155 | %exn = load i8*, i8** %exn.slot |
| 156 | call void @llvm.eh.begincatch(i8* %exn, i8* null) #3 |
| 157 | call void @"\01?handle_exception@@YAXXZ"() call void @llvm.eh.endcatch() #3 |
| Reid Kleckner | fd7df28 | 2015-04-22 21:05:21 +0000 | [diff] [blame] | 158 | br label %ret |
| Andrew Kaylor | 64622aa | 2015-04-01 17:21:25 +0000 | [diff] [blame] | 159 | ; CHECK: } |
| 160 | } |
| 161 | |
| 162 | ; CHECK-LABEL: define internal i8* @"\01?test@@YAXXZ.catch"(i8*, i8*) |
| 163 | ; CHECK: entry: |
| 164 | ; CHECK: [[RECOVER_I:\%.+]] = call i8* @llvm.framerecover(i8* bitcast (void ()* @"\01?test@@YAXXZ" to i8*), i8* %1, i32 0) |
| 165 | ; CHECK: [[I_PTR:\%.+]] = bitcast i8* [[RECOVER_I]] to i32* |
| 166 | ; CHECK: [[TMP1:\%.+]] = load i32, i32* [[I_PTR]], align 4 |
| 167 | ; CHECK: call void @"\01?handle_int@@YAXH@Z"(i32 [[TMP1]]) |
| Reid Kleckner | fd7df28 | 2015-04-22 21:05:21 +0000 | [diff] [blame] | 168 | ; CHECK: ret i8* blockaddress(@"\01?test@@YAXXZ", %ret) |
| Andrew Kaylor | 64622aa | 2015-04-01 17:21:25 +0000 | [diff] [blame] | 169 | ; CHECK: } |
| 170 | |
| Sunil Srivastava | d79dfcb | 2015-05-12 16:47:30 +0000 | [diff] [blame] | 171 | ; CHECK-LABEL: define internal i8* @"\01?test@@YAXXZ.catch.1"(i8*, i8*) |
| Andrew Kaylor | 64622aa | 2015-04-01 17:21:25 +0000 | [diff] [blame] | 172 | ; CHECK: entry: |
| 173 | ; CHECK: [[RECOVER_LL:\%.+]] = call i8* @llvm.framerecover(i8* bitcast (void ()* @"\01?test@@YAXXZ" to i8*), i8* %1, i32 1) |
| 174 | ; CHECK: [[LL_PTR:\%.+]] = bitcast i8* [[RECOVER_LL]] to i64* |
| 175 | ; CHECK: [[TMP2:\%.+]] = load i64, i64* [[LL_PTR]], align 8 |
| 176 | ; CHECK: call void @"\01?handle_long_long@@YAX_J@Z"(i64 [[TMP2]]) |
| Reid Kleckner | fd7df28 | 2015-04-22 21:05:21 +0000 | [diff] [blame] | 177 | ; CHECK: ret i8* blockaddress(@"\01?test@@YAXXZ", %ret) |
| Andrew Kaylor | 64622aa | 2015-04-01 17:21:25 +0000 | [diff] [blame] | 178 | ; CHECK: } |
| 179 | |
| Sunil Srivastava | d79dfcb | 2015-05-12 16:47:30 +0000 | [diff] [blame] | 180 | ; CHECK-LABEL: define internal i8* @"\01?test@@YAXXZ.catch.2"(i8*, i8*) |
| Andrew Kaylor | 64622aa | 2015-04-01 17:21:25 +0000 | [diff] [blame] | 181 | ; CHECK: entry: |
| 182 | ; CHECK: [[RECOVER_OBJ:\%.+]] = call i8* @llvm.framerecover(i8* bitcast (void ()* @"\01?test@@YAXXZ" to i8*), i8* %1, i32 2) |
| 183 | ; CHECK: [[OBJ_PTR:\%.+]] = bitcast i8* [[RECOVER_OBJ]] to %class.SomeClass** |
| 184 | ; CHECK: [[TMP3:\%.+]] = load %class.SomeClass*, %class.SomeClass** [[OBJ_PTR]], align 8 |
| 185 | ; CHECK: call void @"\01?handle_obj@@YAXPEAVSomeClass@@@Z"(%class.SomeClass* [[TMP3]]) |
| Reid Kleckner | fd7df28 | 2015-04-22 21:05:21 +0000 | [diff] [blame] | 186 | ; CHECK: ret i8* blockaddress(@"\01?test@@YAXXZ", %ret) |
| Andrew Kaylor | 64622aa | 2015-04-01 17:21:25 +0000 | [diff] [blame] | 187 | ; CHECK: } |
| 188 | |
| Sunil Srivastava | d79dfcb | 2015-05-12 16:47:30 +0000 | [diff] [blame] | 189 | ; CHECK-LABEL: define internal i8* @"\01?test@@YAXXZ.catch.3"(i8*, i8*) |
| Andrew Kaylor | 64622aa | 2015-04-01 17:21:25 +0000 | [diff] [blame] | 190 | ; CHECK: entry: |
| 191 | ; CHECK: call void @"\01?handle_exception@@YAXXZ"() |
| Reid Kleckner | fd7df28 | 2015-04-22 21:05:21 +0000 | [diff] [blame] | 192 | ; CHECK: ret i8* blockaddress(@"\01?test@@YAXXZ", %ret) |
| Andrew Kaylor | 64622aa | 2015-04-01 17:21:25 +0000 | [diff] [blame] | 193 | ; CHECK: } |
| 194 | |
| 195 | |
| 196 | declare void @"\01?may_throw@@YAXXZ"() #1 |
| 197 | |
| 198 | declare i32 @__CxxFrameHandler3(...) |
| 199 | |
| 200 | ; Function Attrs: nounwind readnone |
| 201 | declare i32 @llvm.eh.typeid.for(i8*) #2 |
| 202 | |
| 203 | ; Function Attrs: nounwind |
| 204 | declare void @llvm.eh.begincatch(i8* nocapture, i8* nocapture) #3 |
| 205 | |
| 206 | declare void @"\01?handle_exception@@YAXXZ"() #1 |
| 207 | |
| 208 | ; Function Attrs: nounwind |
| 209 | declare void @llvm.eh.endcatch() #3 |
| 210 | |
| 211 | declare void @"\01?handle_obj@@YAXPEAVSomeClass@@@Z"(%class.SomeClass*) #1 |
| 212 | |
| 213 | declare void @"\01?handle_long_long@@YAX_J@Z"(i64) #1 |
| 214 | |
| 215 | declare void @"\01?handle_int@@YAXH@Z"(i32) #1 |
| 216 | |
| 217 | attributes #0 = { 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" "unsafe-fp-math"="false" "use-soft-float"="false" } |
| 218 | attributes #1 = { "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" } |
| 219 | attributes #2 = { nounwind readnone } |
| 220 | attributes #3 = { nounwind } |
| 221 | |
| 222 | !llvm.module.flags = !{!0} |
| 223 | !llvm.ident = !{!1} |
| 224 | |
| 225 | !0 = !{i32 1, !"PIC Level", i32 2} |
| 226 | !1 = !{!"clang version 3.7.0 (trunk 233155) (llvm/trunk 233153)"} |