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 | |
| 21 | ; This is the structure that will get created for the frame allocation. |
| 22 | ; CHECK: %struct._Z4testv.ehdata = type { i32, i8*, i32 } |
| 23 | |
| 24 | @_ZTIi = external constant i8* |
| 25 | |
| 26 | ; The function entry will be rewritten like this. |
| 27 | ; CHECK: define void @_Z4testv() #0 { |
| 28 | ; CHECK: entry: |
| 29 | ; CHECK: %frame.alloc = call i8* @llvm.frameallocate(i32 24) |
| 30 | ; CHECK: %eh.data = bitcast i8* %frame.alloc to %struct._Z4testv.ehdata* |
| 31 | ; CHECK: %exn.slot = alloca i8* |
| 32 | ; CHECK: %ehselector.slot = alloca i32 |
| 33 | ; CHECK-NOT: %i = alloca i32, align 4 |
David Blaikie | 79e6c74 | 2015-02-27 19:29:02 +0000 | [diff] [blame] | 34 | ; CHECK: %i = getelementptr inbounds %struct._Z4testv.ehdata, %struct._Z4testv.ehdata* %eh.data, i32 0, i32 2 |
Andrew Kaylor | 1476e6d | 2015-02-24 20:49:35 +0000 | [diff] [blame] | 35 | |
| 36 | ; Function Attrs: uwtable |
| 37 | define void @_Z4testv() #0 { |
| 38 | entry: |
| 39 | %exn.slot = alloca i8* |
| 40 | %ehselector.slot = alloca i32 |
| 41 | %i = alloca i32, align 4 |
| 42 | invoke void @_Z9may_throwv() |
| 43 | to label %invoke.cont unwind label %lpad |
| 44 | |
| 45 | invoke.cont: ; preds = %entry |
| 46 | br label %try.cont |
| 47 | |
| 48 | lpad: ; preds = %entry |
| 49 | %0 = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*) |
| 50 | catch i8* bitcast (i8** @_ZTIi to i8*) |
| 51 | %1 = extractvalue { i8*, i32 } %0, 0 |
| 52 | store i8* %1, i8** %exn.slot |
| 53 | %2 = extractvalue { i8*, i32 } %0, 1 |
| 54 | store i32 %2, i32* %ehselector.slot |
| 55 | br label %catch.dispatch |
| 56 | |
| 57 | catch.dispatch: ; preds = %lpad |
David Blaikie | a79ac14 | 2015-02-27 21:17:42 +0000 | [diff] [blame^] | 58 | %sel = load i32, i32* %ehselector.slot |
Andrew Kaylor | 1476e6d | 2015-02-24 20:49:35 +0000 | [diff] [blame] | 59 | %3 = call i32 @llvm.eh.typeid.for(i8* bitcast (i8** @_ZTIi to i8*)) #3 |
| 60 | %matches = icmp eq i32 %sel, %3 |
| 61 | br i1 %matches, label %catch, label %eh.resume |
| 62 | |
| 63 | catch: ; preds = %catch.dispatch |
David Blaikie | a79ac14 | 2015-02-27 21:17:42 +0000 | [diff] [blame^] | 64 | %exn11 = load i8*, i8** %exn.slot |
Andrew Kaylor | 1476e6d | 2015-02-24 20:49:35 +0000 | [diff] [blame] | 65 | %4 = call i8* @llvm.eh.begincatch(i8* %exn11) #3 |
| 66 | %5 = bitcast i8* %4 to i32* |
David Blaikie | a79ac14 | 2015-02-27 21:17:42 +0000 | [diff] [blame^] | 67 | %6 = load i32, i32* %5, align 4 |
Andrew Kaylor | 1476e6d | 2015-02-24 20:49:35 +0000 | [diff] [blame] | 68 | store i32 %6, i32* %i, align 4 |
David Blaikie | a79ac14 | 2015-02-27 21:17:42 +0000 | [diff] [blame^] | 69 | %7 = load i32, i32* %i, align 4 |
Andrew Kaylor | 1476e6d | 2015-02-24 20:49:35 +0000 | [diff] [blame] | 70 | call void @_Z10handle_inti(i32 %7) |
| 71 | br label %invoke.cont2 |
| 72 | |
| 73 | invoke.cont2: ; preds = %catch |
| 74 | call void @llvm.eh.endcatch() #3 |
| 75 | br label %try.cont |
| 76 | |
| 77 | try.cont: ; preds = %invoke.cont2, %invoke.cont |
| 78 | ret void |
| 79 | |
| 80 | eh.resume: ; preds = %catch.dispatch |
David Blaikie | a79ac14 | 2015-02-27 21:17:42 +0000 | [diff] [blame^] | 81 | %exn3 = load i8*, i8** %exn.slot |
| 82 | %sel4 = load i32, i32* %ehselector.slot |
Andrew Kaylor | 1476e6d | 2015-02-24 20:49:35 +0000 | [diff] [blame] | 83 | %lpad.val = insertvalue { i8*, i32 } undef, i8* %exn3, 0 |
| 84 | %lpad.val5 = insertvalue { i8*, i32 } %lpad.val, i32 %sel4, 1 |
| 85 | resume { i8*, i32 } %lpad.val5 |
| 86 | } |
| 87 | |
| 88 | ; CHECK: define i8* @_Z4testv.catch(i8*, i8*) { |
| 89 | ; CHECK: catch.entry: |
| 90 | ; CHECK: %eh.alloc = call i8* @llvm.framerecover(i8* bitcast (void ()* @_Z4testv to i8*), i8* %1) |
| 91 | ; CHECK: %eh.data = bitcast i8* %eh.alloc to %struct._Z4testv.ehdata* |
David Blaikie | 79e6c74 | 2015-02-27 19:29:02 +0000 | [diff] [blame] | 92 | ; CHECK: %eh.obj.ptr = getelementptr inbounds %struct._Z4testv.ehdata, %struct._Z4testv.ehdata* %eh.data, i32 0, i32 1 |
David Blaikie | a79ac14 | 2015-02-27 21:17:42 +0000 | [diff] [blame^] | 93 | ; CHECK: %eh.obj = load i8*, i8** %eh.obj.ptr |
David Blaikie | 79e6c74 | 2015-02-27 19:29:02 +0000 | [diff] [blame] | 94 | ; CHECK: %i = getelementptr inbounds %struct._Z4testv.ehdata, %struct._Z4testv.ehdata* %eh.data, i32 0, i32 2 |
Andrew Kaylor | 1476e6d | 2015-02-24 20:49:35 +0000 | [diff] [blame] | 95 | ; CHECK: %2 = bitcast i8* %eh.obj to i32* |
David Blaikie | a79ac14 | 2015-02-27 21:17:42 +0000 | [diff] [blame^] | 96 | ; CHECK: %3 = load i32, i32* %2, align 4 |
Andrew Kaylor | 1476e6d | 2015-02-24 20:49:35 +0000 | [diff] [blame] | 97 | ; CHECK: store i32 %3, i32* %i, align 4 |
David Blaikie | a79ac14 | 2015-02-27 21:17:42 +0000 | [diff] [blame^] | 98 | ; CHECK: %4 = load i32, i32* %i, align 4 |
Andrew Kaylor | 1476e6d | 2015-02-24 20:49:35 +0000 | [diff] [blame] | 99 | ; CHECK: call void @_Z10handle_inti(i32 %4) |
| 100 | ; CHECK: ret i8* blockaddress(@_Z4testv, %try.cont) |
| 101 | ; CHECK: } |
| 102 | |
| 103 | declare void @_Z9may_throwv() #1 |
| 104 | |
| 105 | declare i32 @__CxxFrameHandler3(...) |
| 106 | |
| 107 | ; Function Attrs: nounwind readnone |
| 108 | declare i32 @llvm.eh.typeid.for(i8*) #2 |
| 109 | |
| 110 | declare i8* @llvm.eh.begincatch(i8*) |
| 111 | |
| 112 | declare void @llvm.eh.endcatch() |
| 113 | |
| 114 | declare void @_Z10handle_inti(i32) #1 |
| 115 | |
| 116 | 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" } |
| 117 | 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" } |
| 118 | attributes #2 = { nounwind readnone } |
| 119 | attributes #3 = { nounwind } |
| 120 | |
| 121 | !llvm.ident = !{!0} |
| 122 | |
| 123 | !0 = !{!"clang version 3.7.0 (trunk 227474) (llvm/trunk 227508)"} |