blob: b5f40c3f9447b30636a44742c1ed8f4e6cfcdbc0 [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
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
57catch.dispatch: ; preds = %lpad
David Blaikiea79ac142015-02-27 21:17:42 +000058 %sel = load i32, i32* %ehselector.slot
Andrew Kaylor1476e6d2015-02-24 20:49:35 +000059 %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
63catch: ; preds = %catch.dispatch
David Blaikiea79ac142015-02-27 21:17:42 +000064 %exn11 = load i8*, i8** %exn.slot
Andrew Kaylor1476e6d2015-02-24 20:49:35 +000065 %4 = call i8* @llvm.eh.begincatch(i8* %exn11) #3
66 %5 = bitcast i8* %4 to i32*
David Blaikiea79ac142015-02-27 21:17:42 +000067 %6 = load i32, i32* %5, align 4
Andrew Kaylor1476e6d2015-02-24 20:49:35 +000068 store i32 %6, i32* %i, align 4
David Blaikiea79ac142015-02-27 21:17:42 +000069 %7 = load i32, i32* %i, align 4
Andrew Kaylor1476e6d2015-02-24 20:49:35 +000070 call void @_Z10handle_inti(i32 %7)
71 br label %invoke.cont2
72
73invoke.cont2: ; preds = %catch
74 call void @llvm.eh.endcatch() #3
75 br label %try.cont
76
77try.cont: ; preds = %invoke.cont2, %invoke.cont
78 ret void
79
80eh.resume: ; preds = %catch.dispatch
David Blaikiea79ac142015-02-27 21:17:42 +000081 %exn3 = load i8*, i8** %exn.slot
82 %sel4 = load i32, i32* %ehselector.slot
Andrew Kaylor1476e6d2015-02-24 20:49:35 +000083 %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 Blaikie79e6c742015-02-27 19:29:02 +000092; 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 +000093; CHECK: %eh.obj = load i8*, i8** %eh.obj.ptr
David Blaikie79e6c742015-02-27 19:29:02 +000094; CHECK: %i = getelementptr inbounds %struct._Z4testv.ehdata, %struct._Z4testv.ehdata* %eh.data, i32 0, i32 2
Andrew Kaylor1476e6d2015-02-24 20:49:35 +000095; CHECK: %2 = bitcast i8* %eh.obj to i32*
David Blaikiea79ac142015-02-27 21:17:42 +000096; CHECK: %3 = load i32, i32* %2, align 4
Andrew Kaylor1476e6d2015-02-24 20:49:35 +000097; CHECK: store i32 %3, i32* %i, align 4
David Blaikiea79ac142015-02-27 21:17:42 +000098; CHECK: %4 = load i32, i32* %i, align 4
Andrew Kaylor1476e6d2015-02-24 20:49:35 +000099; CHECK: call void @_Z10handle_inti(i32 %4)
100; CHECK: ret i8* blockaddress(@_Z4testv, %try.cont)
101; CHECK: }
102
103declare void @_Z9may_throwv() #1
104
105declare i32 @__CxxFrameHandler3(...)
106
107; Function Attrs: nounwind readnone
108declare i32 @llvm.eh.typeid.for(i8*) #2
109
110declare i8* @llvm.eh.begincatch(i8*)
111
112declare void @llvm.eh.endcatch()
113
114declare void @_Z10handle_inti(i32) #1
115
116attributes #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" }
117attributes #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" }
118attributes #2 = { nounwind readnone }
119attributes #3 = { nounwind }
120
121!llvm.ident = !{!0}
122
123!0 = !{!"clang version 3.7.0 (trunk 227474) (llvm/trunk 227508)"}