blob: 0b1d1772388f8cccaf20d7c87662da80fffa9a20 [file] [log] [blame]
Andrew Kaylor1476e6d2015-02-24 20:49:35 +00001; 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'
18target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
19target triple = "x86_64-pc-windows-msvc"
20
Andrew Kaylor1476e6d2015-02-24 20:49:35 +000021@_ZTIi = external constant i8*
22
23; The function entry will be rewritten like this.
24; CHECK: define void @_Z4testv() #0 {
25; CHECK: entry:
Andrew Kaylor1476e6d2015-02-24 20:49:35 +000026; CHECK: %exn.slot = alloca i8*
27; CHECK: %ehselector.slot = alloca i32
Reid Klecknercfb9ce52015-03-05 18:26:34 +000028; CHECK: %i = alloca i32, align 4
29; CHECK: call void (...)* @llvm.frameescape(i32* %i)
30; CHECK: invoke void @_Z9may_throwv()
31; CHECK: to label %invoke.cont unwind label %lpad
Andrew Kaylor1476e6d2015-02-24 20:49:35 +000032
33; Function Attrs: uwtable
34define void @_Z4testv() #0 {
35entry:
36 %exn.slot = alloca i8*
37 %ehselector.slot = alloca i32
38 %i = alloca i32, align 4
39 invoke void @_Z9may_throwv()
40 to label %invoke.cont unwind label %lpad
41
42invoke.cont: ; preds = %entry
43 br label %try.cont
44
45lpad: ; preds = %entry
Reid Kleckner6f0e4b82015-03-03 00:05:35 +000046 %tmp = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*)
Andrew Kaylor1476e6d2015-02-24 20:49:35 +000047 catch i8* bitcast (i8** @_ZTIi to i8*)
Reid Kleckner6f0e4b82015-03-03 00:05:35 +000048 %tmp1 = extractvalue { i8*, i32 } %tmp, 0
49 store i8* %tmp1, i8** %exn.slot
50 %tmp2 = extractvalue { i8*, i32 } %tmp, 1
51 store i32 %tmp2, i32* %ehselector.slot
Andrew Kaylor1476e6d2015-02-24 20:49:35 +000052 br label %catch.dispatch
53
54catch.dispatch: ; preds = %lpad
David Blaikiea79ac142015-02-27 21:17:42 +000055 %sel = load i32, i32* %ehselector.slot
Reid Kleckner6f0e4b82015-03-03 00:05:35 +000056 %tmp3 = call i32 @llvm.eh.typeid.for(i8* bitcast (i8** @_ZTIi to i8*)) #3
57 %matches = icmp eq i32 %sel, %tmp3
Andrew Kaylor1476e6d2015-02-24 20:49:35 +000058 br i1 %matches, label %catch, label %eh.resume
59
60catch: ; preds = %catch.dispatch
David Blaikiea79ac142015-02-27 21:17:42 +000061 %exn11 = load i8*, i8** %exn.slot
Reid Kleckner2f05d4c2015-03-03 17:41:09 +000062 %i.i8 = bitcast i32* %i to i8*
63 call void @llvm.eh.begincatch(i8* %exn11, i8* %i.i8) #3
Reid Kleckner6f0e4b82015-03-03 00:05:35 +000064 %tmp7 = load i32, i32* %i, align 4
65 call void @_Z10handle_inti(i32 %tmp7)
Andrew Kaylor1476e6d2015-02-24 20:49:35 +000066 br label %invoke.cont2
67
68invoke.cont2: ; preds = %catch
69 call void @llvm.eh.endcatch() #3
70 br label %try.cont
71
72try.cont: ; preds = %invoke.cont2, %invoke.cont
73 ret void
74
75eh.resume: ; preds = %catch.dispatch
David Blaikiea79ac142015-02-27 21:17:42 +000076 %exn3 = load i8*, i8** %exn.slot
77 %sel4 = load i32, i32* %ehselector.slot
Andrew Kaylor1476e6d2015-02-24 20:49:35 +000078 %lpad.val = insertvalue { i8*, i32 } undef, i8* %exn3, 0
79 %lpad.val5 = insertvalue { i8*, i32 } %lpad.val, i32 %sel4, 1
80 resume { i8*, i32 } %lpad.val5
81}
82
Andrew Kaylorf0f5e462015-03-03 20:00:16 +000083; CHECK: define internal i8* @_Z4testv.catch(i8*, i8*) {
84; CHECK: entry:
Reid Klecknercfb9ce52015-03-05 18:26:34 +000085; CHECK: %i.i81 = call i8* @llvm.framerecover(i8* bitcast (void ()* @_Z4testv to i8*), i8* %1, i32 0)
86; CHECK: %i = bitcast i8* %i.i81 to i32*
Reid Kleckner6f0e4b82015-03-03 00:05:35 +000087; CHECK: %tmp7 = load i32, i32* %i, align 4
88; CHECK: call void @_Z10handle_inti(i32 %tmp7)
Andrew Kaylor1476e6d2015-02-24 20:49:35 +000089; CHECK: ret i8* blockaddress(@_Z4testv, %try.cont)
90; CHECK: }
91
92declare void @_Z9may_throwv() #1
93
94declare i32 @__CxxFrameHandler3(...)
95
96; Function Attrs: nounwind readnone
97declare i32 @llvm.eh.typeid.for(i8*) #2
98
Reid Kleckner2f05d4c2015-03-03 17:41:09 +000099declare void @llvm.eh.begincatch(i8*, i8*)
Andrew Kaylor1476e6d2015-02-24 20:49:35 +0000100
101declare void @llvm.eh.endcatch()
102
103declare void @_Z10handle_inti(i32) #1
104
105attributes #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" }
106attributes #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" }
107attributes #2 = { nounwind readnone }
108attributes #3 = { nounwind }
109
110!llvm.ident = !{!0}
111
112!0 = !{!"clang version 3.7.0 (trunk 227474) (llvm/trunk 227508)"}