Andrew Kaylor | 1476e6d | 2015-02-24 20:49:35 +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 | ; } |
| 12 | ; } |
| 13 | ; |
| 14 | ; Parts of the IR have been hand-edited to simplify the test case. |
| 15 | ; The full IR will be restored when Windows C++ EH support is complete. |
| 16 | |
| 17 | ;ModuleID = 'cppeh-catch-scalar.cpp' |
| 18 | target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" |
| 19 | target triple = "x86_64-pc-windows-msvc" |
| 20 | |
Andrew Kaylor | 1476e6d | 2015-02-24 20:49:35 +0000 | [diff] [blame] | 21 | @_ZTIi = external constant i8* |
| 22 | |
| 23 | ; The function entry will be rewritten like this. |
| 24 | ; CHECK: define void @_Z4testv() #0 { |
| 25 | ; CHECK: entry: |
Andrew Kaylor | 6b67d42 | 2015-03-11 23:22:06 +0000 | [diff] [blame] | 26 | ; CHECK: [[I_PTR:\%.+]] = alloca i32, align 4 |
| 27 | ; CHECK: call void (...)* @llvm.frameescape(i32* [[I_PTR]]) |
Reid Kleckner | cfb9ce5 | 2015-03-05 18:26:34 +0000 | [diff] [blame] | 28 | ; CHECK: invoke void @_Z9may_throwv() |
Andrew Kaylor | 6b67d42 | 2015-03-11 23:22:06 +0000 | [diff] [blame] | 29 | ; CHECK: to label %invoke.cont unwind label %[[LPAD_LABEL:lpad[0-9]+]] |
Andrew Kaylor | 1476e6d | 2015-02-24 20:49:35 +0000 | [diff] [blame] | 30 | |
| 31 | ; Function Attrs: uwtable |
| 32 | define void @_Z4testv() #0 { |
| 33 | entry: |
| 34 | %exn.slot = alloca i8* |
| 35 | %ehselector.slot = alloca i32 |
| 36 | %i = alloca i32, align 4 |
| 37 | invoke void @_Z9may_throwv() |
| 38 | to label %invoke.cont unwind label %lpad |
| 39 | |
| 40 | invoke.cont: ; preds = %entry |
| 41 | br label %try.cont |
| 42 | |
Andrew Kaylor | 6b67d42 | 2015-03-11 23:22:06 +0000 | [diff] [blame] | 43 | ; CHECK: [[LPAD_LABEL]]:{{[ ]+}}; preds = %entry |
| 44 | ; CHECK: [[LPAD_VAL:\%.+]] = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*) |
| 45 | ; CHECK: catch i8* bitcast (i8** @_ZTIi to i8*) |
| 46 | ; CHECK-NOT: extractvalue { i8*, i32 } |
| 47 | ; CHECK-NOT: store i8* |
| 48 | ; CHECK-NOT: store i32 |
| 49 | ; CHECK-NOT: br label |
| 50 | ; CHECK: [[RECOVER:\%.+]] = call i8* (...)* @llvm.eh.actions({ i8*, i32 } [[LPAD_VAL]], i32 0, i8* bitcast (i8** @_ZTIi to i8*), i32* %i, i8* bitcast (i8* (i8*, i8*)* @_Z4testv.catch to i8*)) |
| 51 | ; CHECK: indirectbr i8* [[RECOVER]], [label %try.cont] |
| 52 | |
Andrew Kaylor | 1476e6d | 2015-02-24 20:49:35 +0000 | [diff] [blame] | 53 | lpad: ; preds = %entry |
Reid Kleckner | 6f0e4b8 | 2015-03-03 00:05:35 +0000 | [diff] [blame] | 54 | %tmp = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*) |
Andrew Kaylor | 1476e6d | 2015-02-24 20:49:35 +0000 | [diff] [blame] | 55 | catch i8* bitcast (i8** @_ZTIi to i8*) |
Reid Kleckner | 6f0e4b8 | 2015-03-03 00:05:35 +0000 | [diff] [blame] | 56 | %tmp1 = extractvalue { i8*, i32 } %tmp, 0 |
| 57 | store i8* %tmp1, i8** %exn.slot |
| 58 | %tmp2 = extractvalue { i8*, i32 } %tmp, 1 |
| 59 | store i32 %tmp2, i32* %ehselector.slot |
Andrew Kaylor | 1476e6d | 2015-02-24 20:49:35 +0000 | [diff] [blame] | 60 | br label %catch.dispatch |
| 61 | |
Andrew Kaylor | 6b67d42 | 2015-03-11 23:22:06 +0000 | [diff] [blame] | 62 | ; CHECK-NOT: catch-dispatch: |
| 63 | |
Andrew Kaylor | 1476e6d | 2015-02-24 20:49:35 +0000 | [diff] [blame] | 64 | catch.dispatch: ; preds = %lpad |
David Blaikie | a79ac14 | 2015-02-27 21:17:42 +0000 | [diff] [blame] | 65 | %sel = load i32, i32* %ehselector.slot |
Reid Kleckner | 6f0e4b8 | 2015-03-03 00:05:35 +0000 | [diff] [blame] | 66 | %tmp3 = call i32 @llvm.eh.typeid.for(i8* bitcast (i8** @_ZTIi to i8*)) #3 |
| 67 | %matches = icmp eq i32 %sel, %tmp3 |
Andrew Kaylor | 1476e6d | 2015-02-24 20:49:35 +0000 | [diff] [blame] | 68 | br i1 %matches, label %catch, label %eh.resume |
| 69 | |
Andrew Kaylor | 6b67d42 | 2015-03-11 23:22:06 +0000 | [diff] [blame] | 70 | ; CHECK-NOT: catch: |
| 71 | |
Andrew Kaylor | 1476e6d | 2015-02-24 20:49:35 +0000 | [diff] [blame] | 72 | catch: ; preds = %catch.dispatch |
David Blaikie | a79ac14 | 2015-02-27 21:17:42 +0000 | [diff] [blame] | 73 | %exn11 = load i8*, i8** %exn.slot |
Reid Kleckner | 2f05d4c | 2015-03-03 17:41:09 +0000 | [diff] [blame] | 74 | %i.i8 = bitcast i32* %i to i8* |
| 75 | call void @llvm.eh.begincatch(i8* %exn11, i8* %i.i8) #3 |
Reid Kleckner | 6f0e4b8 | 2015-03-03 00:05:35 +0000 | [diff] [blame] | 76 | %tmp7 = load i32, i32* %i, align 4 |
| 77 | call void @_Z10handle_inti(i32 %tmp7) |
Andrew Kaylor | 1476e6d | 2015-02-24 20:49:35 +0000 | [diff] [blame] | 78 | br label %invoke.cont2 |
| 79 | |
Andrew Kaylor | 6b67d42 | 2015-03-11 23:22:06 +0000 | [diff] [blame] | 80 | ; CHECK-NOT: invoke.cont2: |
| 81 | |
Andrew Kaylor | 1476e6d | 2015-02-24 20:49:35 +0000 | [diff] [blame] | 82 | invoke.cont2: ; preds = %catch |
| 83 | call void @llvm.eh.endcatch() #3 |
| 84 | br label %try.cont |
| 85 | |
| 86 | try.cont: ; preds = %invoke.cont2, %invoke.cont |
| 87 | ret void |
| 88 | |
Andrew Kaylor | 6b67d42 | 2015-03-11 23:22:06 +0000 | [diff] [blame] | 89 | ; CHECK-NOT: eh.resume: |
| 90 | |
Andrew Kaylor | 1476e6d | 2015-02-24 20:49:35 +0000 | [diff] [blame] | 91 | eh.resume: ; preds = %catch.dispatch |
David Blaikie | a79ac14 | 2015-02-27 21:17:42 +0000 | [diff] [blame] | 92 | %exn3 = load i8*, i8** %exn.slot |
| 93 | %sel4 = load i32, i32* %ehselector.slot |
Andrew Kaylor | 1476e6d | 2015-02-24 20:49:35 +0000 | [diff] [blame] | 94 | %lpad.val = insertvalue { i8*, i32 } undef, i8* %exn3, 0 |
| 95 | %lpad.val5 = insertvalue { i8*, i32 } %lpad.val, i32 %sel4, 1 |
| 96 | resume { i8*, i32 } %lpad.val5 |
Andrew Kaylor | 6b67d42 | 2015-03-11 23:22:06 +0000 | [diff] [blame] | 97 | |
| 98 | ; CHECK: } |
Andrew Kaylor | 1476e6d | 2015-02-24 20:49:35 +0000 | [diff] [blame] | 99 | } |
| 100 | |
Andrew Kaylor | f0f5e46 | 2015-03-03 20:00:16 +0000 | [diff] [blame] | 101 | ; CHECK: define internal i8* @_Z4testv.catch(i8*, i8*) { |
| 102 | ; CHECK: entry: |
Andrew Kaylor | 6b67d42 | 2015-03-11 23:22:06 +0000 | [diff] [blame] | 103 | ; CHECK: [[RECOVER_I:\%.+]] = call i8* @llvm.framerecover(i8* bitcast (void ()* @_Z4testv to i8*), i8* %1, i32 0) |
| 104 | ; CHECK: [[I_PTR1:\%.+]] = bitcast i8* [[RECOVER_I]] to i32* |
| 105 | ; CHECK: [[TMP:\%.+]] = load i32, i32* [[I_PTR1]], align 4 |
| 106 | ; CHECK: call void @_Z10handle_inti(i32 [[TMP]]) |
Andrew Kaylor | 1476e6d | 2015-02-24 20:49:35 +0000 | [diff] [blame] | 107 | ; CHECK: ret i8* blockaddress(@_Z4testv, %try.cont) |
| 108 | ; CHECK: } |
| 109 | |
| 110 | declare void @_Z9may_throwv() #1 |
| 111 | |
| 112 | declare i32 @__CxxFrameHandler3(...) |
| 113 | |
| 114 | ; Function Attrs: nounwind readnone |
| 115 | declare i32 @llvm.eh.typeid.for(i8*) #2 |
| 116 | |
Reid Kleckner | 2f05d4c | 2015-03-03 17:41:09 +0000 | [diff] [blame] | 117 | declare void @llvm.eh.begincatch(i8*, i8*) |
Andrew Kaylor | 1476e6d | 2015-02-24 20:49:35 +0000 | [diff] [blame] | 118 | |
| 119 | declare void @llvm.eh.endcatch() |
| 120 | |
| 121 | declare void @_Z10handle_inti(i32) #1 |
| 122 | |
| 123 | attributes #0 = { uwtable "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" } |
| 124 | attributes #1 = { "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" } |
| 125 | attributes #2 = { nounwind readnone } |
| 126 | attributes #3 = { nounwind } |
| 127 | |
| 128 | !llvm.ident = !{!0} |
| 129 | |
| 130 | !0 = !{!"clang version 3.7.0 (trunk 227474) (llvm/trunk 227508)"} |