blob: 9c16a9b09efaef307ea21209ffb3a9ed31d48e72 [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
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 Blaikie79e6c742015-02-27 19:29:02 +000034; CHECK: %i = getelementptr inbounds %struct._Z4testv.ehdata, %struct._Z4testv.ehdata* %eh.data, i32 0, i32 2
Andrew Kaylor1476e6d2015-02-24 20:49:35 +000035
36; Function Attrs: uwtable
37define void @_Z4testv() #0 {
38entry:
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
45invoke.cont: ; preds = %entry
46 br label %try.cont
47
48lpad: ; preds = %entry
Reid Kleckner6f0e4b82015-03-03 00:05:35 +000049 %tmp = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*)
Andrew Kaylor1476e6d2015-02-24 20:49:35 +000050 catch i8* bitcast (i8** @_ZTIi to i8*)
Reid Kleckner6f0e4b82015-03-03 00:05:35 +000051 %tmp1 = extractvalue { i8*, i32 } %tmp, 0
52 store i8* %tmp1, i8** %exn.slot
53 %tmp2 = extractvalue { i8*, i32 } %tmp, 1
54 store i32 %tmp2, i32* %ehselector.slot
Andrew Kaylor1476e6d2015-02-24 20:49:35 +000055 br label %catch.dispatch
56
57catch.dispatch: ; preds = %lpad
David Blaikiea79ac142015-02-27 21:17:42 +000058 %sel = load i32, i32* %ehselector.slot
Reid Kleckner6f0e4b82015-03-03 00:05:35 +000059 %tmp3 = call i32 @llvm.eh.typeid.for(i8* bitcast (i8** @_ZTIi to i8*)) #3
60 %matches = icmp eq i32 %sel, %tmp3
Andrew Kaylor1476e6d2015-02-24 20:49:35 +000061 br i1 %matches, label %catch, label %eh.resume
62
63catch: ; preds = %catch.dispatch
David Blaikiea79ac142015-02-27 21:17:42 +000064 %exn11 = load i8*, i8** %exn.slot
Reid Kleckner2f05d4c2015-03-03 17:41:09 +000065 %i.i8 = bitcast i32* %i to i8*
66 call void @llvm.eh.begincatch(i8* %exn11, i8* %i.i8) #3
Reid Kleckner6f0e4b82015-03-03 00:05:35 +000067 %tmp7 = load i32, i32* %i, align 4
68 call void @_Z10handle_inti(i32 %tmp7)
Andrew Kaylor1476e6d2015-02-24 20:49:35 +000069 br label %invoke.cont2
70
71invoke.cont2: ; preds = %catch
72 call void @llvm.eh.endcatch() #3
73 br label %try.cont
74
75try.cont: ; preds = %invoke.cont2, %invoke.cont
76 ret void
77
78eh.resume: ; preds = %catch.dispatch
David Blaikiea79ac142015-02-27 21:17:42 +000079 %exn3 = load i8*, i8** %exn.slot
80 %sel4 = load i32, i32* %ehselector.slot
Andrew Kaylor1476e6d2015-02-24 20:49:35 +000081 %lpad.val = insertvalue { i8*, i32 } undef, i8* %exn3, 0
82 %lpad.val5 = insertvalue { i8*, i32 } %lpad.val, i32 %sel4, 1
83 resume { i8*, i32 } %lpad.val5
84}
85
Reid Kleckner6f0e4b82015-03-03 00:05:35 +000086; CHECK-LABEL: define i8* @_Z4testv.catch(i8*, i8*) {
Andrew Kaylor1476e6d2015-02-24 20:49:35 +000087; CHECK: catch.entry:
88; CHECK: %eh.alloc = call i8* @llvm.framerecover(i8* bitcast (void ()* @_Z4testv to i8*), i8* %1)
89; CHECK: %eh.data = bitcast i8* %eh.alloc to %struct._Z4testv.ehdata*
David Blaikie79e6c742015-02-27 19:29:02 +000090; CHECK: %eh.obj.ptr = getelementptr inbounds %struct._Z4testv.ehdata, %struct._Z4testv.ehdata* %eh.data, i32 0, i32 1
David Blaikiea79ac142015-02-27 21:17:42 +000091; CHECK: %eh.obj = load i8*, i8** %eh.obj.ptr
David Blaikie79e6c742015-02-27 19:29:02 +000092; CHECK: %i = getelementptr inbounds %struct._Z4testv.ehdata, %struct._Z4testv.ehdata* %eh.data, i32 0, i32 2
Reid Kleckner6f0e4b82015-03-03 00:05:35 +000093; CHECK: %tmp7 = load i32, i32* %i, align 4
94; CHECK: call void @_Z10handle_inti(i32 %tmp7)
Andrew Kaylor1476e6d2015-02-24 20:49:35 +000095; CHECK: ret i8* blockaddress(@_Z4testv, %try.cont)
96; CHECK: }
97
98declare void @_Z9may_throwv() #1
99
100declare i32 @__CxxFrameHandler3(...)
101
102; Function Attrs: nounwind readnone
103declare i32 @llvm.eh.typeid.for(i8*) #2
104
Reid Kleckner2f05d4c2015-03-03 17:41:09 +0000105declare void @llvm.eh.begincatch(i8*, i8*)
Andrew Kaylor1476e6d2015-02-24 20:49:35 +0000106
107declare void @llvm.eh.endcatch()
108
109declare void @_Z10handle_inti(i32) #1
110
111attributes #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" }
112attributes #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" }
113attributes #2 = { nounwind readnone }
114attributes #3 = { nounwind }
115
116!llvm.ident = !{!0}
117
118!0 = !{!"clang version 3.7.0 (trunk 227474) (llvm/trunk 227508)"}