blob: 5595b0c82b66b918da285774b6e82a28afae7a9c [file] [log] [blame]
Andrew Kaylor72029c62015-03-03 00:41:03 +00001; RUN: opt -mtriple=i386-pc-windows-msvc -winehprepare -S -o - < %s | FileCheck %s
2
3; This test is built from the following code:
4; struct A {
5; A(int a);
6; A(const A &o);
7; ~A();
8; int a;
9; };
10;
11; void may_throw();
12;
13; int test(A a) {
14; try {
15; may_throw();
16; }
17; catch (int e) {
18; return a.a + e;
19; }
20; return 0;
21; }
22;
23; The test was built for a 32-bit Windows target and then the reference to
24; the inalloca instruction was manually sunk into the landingpad.
25
26; ModuleID = 'cppeh-inalloca.cpp'
27target datalayout = "e-m:w-p:32:32-i64:64-f80:32-n8:16:32-S32"
28target triple = "i386-pc-windows-msvc"
29
30%rtti.TypeDescriptor2 = type { i8**, i8*, [3 x i8] }
31%struct.A = type { i32 }
32
33$"\01??_R0H@8" = comdat any
34
35@"\01??_7type_info@@6B@" = external constant i8*
36@"\01??_R0H@8" = linkonce_odr global %rtti.TypeDescriptor2 { i8** @"\01??_7type_info@@6B@", i8* null, [3 x i8] c".H\00" }, comdat
37
38; The function entry should be rewritten like this.
39; CHECK: define i32 @"\01?test@@YAHUA@@@Z"(<{ %struct.A }>* inalloca) #0 {
40; CHECK: entry:
Reid Klecknercfb9ce52015-03-05 18:26:34 +000041; CHECK: %.tmp.reg2mem = alloca <{ %struct.A }>*
Andrew Kaylor72029c62015-03-03 00:41:03 +000042; CHECK: %.tmp = select i1 true, <{ %struct.A }>* %0, <{ %struct.A }>* undef
43; CHECK: store <{ %struct.A }>* %.tmp, <{ %struct.A }>** %.tmp.reg2mem
Reid Klecknercfb9ce52015-03-05 18:26:34 +000044; CHECK: %retval = alloca i32, align 4
Andrew Kaylor72029c62015-03-03 00:41:03 +000045; CHECK: %exn.slot = alloca i8*
46; CHECK: %ehselector.slot = alloca i32
Reid Klecknercfb9ce52015-03-05 18:26:34 +000047; CHECK: %e = alloca i32, align 4
48; CHECK: %cleanup.dest.slot = alloca i32
49; CHECK: call void (...)* @llvm.frameescape(i32* %e, <{ %struct.A }>** %.tmp.reg2mem, i32* %retval, i32* %cleanup.dest.slot)
Andrew Kaylor72029c62015-03-03 00:41:03 +000050; CHECK: invoke void @"\01?may_throw@@YAXXZ"()
51; CHECK: to label %invoke.cont unwind label %lpad
52
53define i32 @"\01?test@@YAHUA@@@Z"(<{ %struct.A }>* inalloca) #0 {
54entry:
55 %retval = alloca i32, align 4
56 %exn.slot = alloca i8*
57 %ehselector.slot = alloca i32
58 %e = alloca i32, align 4
59 %cleanup.dest.slot = alloca i32
60 invoke void @"\01?may_throw@@YAXXZ"()
61 to label %invoke.cont unwind label %lpad
62
63invoke.cont: ; preds = %entry
64 br label %try.cont
65
66lpad: ; preds = %entry
67 %1 = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*)
68 cleanup
69 catch i8* bitcast (%rtti.TypeDescriptor2* @"\01??_R0H@8" to i8*)
70 %2 = extractvalue { i8*, i32 } %1, 0
71 store i8* %2, i8** %exn.slot
72 %3 = extractvalue { i8*, i32 } %1, 1
73 store i32 %3, i32* %ehselector.slot
74 br label %catch.dispatch
75
76catch.dispatch: ; preds = %lpad
Reid Kleckner1d2c3f92015-03-03 01:04:39 +000077 %sel = load i32, i32* %ehselector.slot
Andrew Kaylor72029c62015-03-03 00:41:03 +000078 %4 = call i32 @llvm.eh.typeid.for(i8* bitcast (%rtti.TypeDescriptor2* @"\01??_R0H@8" to i8*)) #3
79 %matches = icmp eq i32 %sel, %4
80 br i1 %matches, label %catch, label %ehcleanup
81
82catch: ; preds = %catch.dispatch
Reid Kleckner1d2c3f92015-03-03 01:04:39 +000083 %exn = load i8*, i8** %exn.slot
Reid Kleckner2f05d4c2015-03-03 17:41:09 +000084 %e.i8 = bitcast i32* %e to i8*
85 call void @llvm.eh.begincatch(i8* %exn, i8* %e.i8) #3
Reid Kleckner1d2c3f92015-03-03 01:04:39 +000086 %a = getelementptr inbounds <{ %struct.A }>, <{ %struct.A }>* %0, i32 0, i32 0
87 %a1 = getelementptr inbounds %struct.A, %struct.A* %a, i32 0, i32 0
Reid Kleckner2f05d4c2015-03-03 17:41:09 +000088 %tmp8 = load i32, i32* %a1, align 4
89 %tmp9 = load i32, i32* %e, align 4
90 %add = add nsw i32 %tmp8, %tmp9
Andrew Kaylor72029c62015-03-03 00:41:03 +000091 store i32 %add, i32* %retval
92 store i32 1, i32* %cleanup.dest.slot
93 call void @llvm.eh.endcatch() #3
94 br label %cleanup
95
96try.cont: ; preds = %invoke.cont
97 store i32 0, i32* %retval
98 store i32 1, i32* %cleanup.dest.slot
99 br label %cleanup
100
101; The cleanup block should be re-written like this.
102; CHECK: cleanup: ; preds = %try.cont, %catch
Reid Kleckner1d2c3f92015-03-03 01:04:39 +0000103; CHECK-NOT: %a2 = getelementptr inbounds <{ %struct.A }>, <{ %struct.A }>* %0, i32 0, i32 0
104; CHECK: %.tmp.reload1 = load volatile <{ %struct.A }>*, <{ %struct.A }>** %.tmp.reg2mem
105; CHECK: %a2 = getelementptr inbounds <{ %struct.A }>, <{ %struct.A }>* %.tmp.reload1, i32 0, i32 0
Andrew Kaylor72029c62015-03-03 00:41:03 +0000106; CHECK: call x86_thiscallcc void @"\01??1A@@QAE@XZ"(%struct.A* %a2) #2
Reid Kleckner2f05d4c2015-03-03 17:41:09 +0000107; CHECK: %tmp10 = load i32, i32* %retval
108; CHECK: ret i32 %tmp10
Andrew Kaylor72029c62015-03-03 00:41:03 +0000109
110cleanup: ; preds = %try.cont, %catch
Reid Kleckner1d2c3f92015-03-03 01:04:39 +0000111 %a2 = getelementptr inbounds <{ %struct.A }>, <{ %struct.A }>* %0, i32 0, i32 0
Andrew Kaylor72029c62015-03-03 00:41:03 +0000112 call x86_thiscallcc void @"\01??1A@@QAE@XZ"(%struct.A* %a2) #3
Reid Kleckner2f05d4c2015-03-03 17:41:09 +0000113 %tmp10 = load i32, i32* %retval
114 ret i32 %tmp10
Andrew Kaylor72029c62015-03-03 00:41:03 +0000115
116ehcleanup: ; preds = %catch.dispatch
Reid Kleckner1d2c3f92015-03-03 01:04:39 +0000117 %a3 = getelementptr inbounds <{ %struct.A }>, <{ %struct.A }>* %0, i32 0, i32 0
Andrew Kaylor72029c62015-03-03 00:41:03 +0000118 call x86_thiscallcc void @"\01??1A@@QAE@XZ"(%struct.A* %a3) #3
119 br label %eh.resume
120
121eh.resume: ; preds = %ehcleanup
Reid Kleckner1d2c3f92015-03-03 01:04:39 +0000122 %exn2 = load i8*, i8** %exn.slot
123 %sel3 = load i32, i32* %ehselector.slot
Andrew Kaylor72029c62015-03-03 00:41:03 +0000124 %lpad.val = insertvalue { i8*, i32 } undef, i8* %exn2, 0
125 %lpad.val4 = insertvalue { i8*, i32 } %lpad.val, i32 %sel3, 1
126 resume { i8*, i32 } %lpad.val4
127}
128
129; The following catch handler should be outlined.
Andrew Kaylorf0f5e462015-03-03 20:00:16 +0000130; CHECK: define internal i8* @"\01?test@@YAHUA@@@Z.catch"(i8*, i8*) {
131; CHECK: entry:
Reid Klecknercfb9ce52015-03-05 18:26:34 +0000132; CHECK: %e.i81 = call i8* @llvm.framerecover(i8* bitcast (i32 (<{ %struct.A }>*)* @"\01?test@@YAHUA@@@Z" to i8*), i8* %1, i32 0)
133; CHECK: %e = bitcast i8* %e.i81 to i32*
134; CHECK: %eh.temp.alloca.i8 = call i8* @llvm.framerecover(i8* bitcast (i32 (<{ %struct.A }>*)* @"\01?test@@YAHUA@@@Z" to i8*), i8* %1, i32 1)
135; CHECK: %eh.temp.alloca = bitcast i8* %eh.temp.alloca.i8 to <{ %struct.A }>**
Reid Kleckner1d2c3f92015-03-03 01:04:39 +0000136; CHECK: %.reload = load <{ %struct.A }>*, <{ %struct.A }>** %eh.temp.alloca
Reid Klecknercfb9ce52015-03-05 18:26:34 +0000137; CHECK: %retval.i8 = call i8* @llvm.framerecover(i8* bitcast (i32 (<{ %struct.A }>*)* @"\01?test@@YAHUA@@@Z" to i8*), i8* %1, i32 2)
138; CHECK: %retval = bitcast i8* %retval.i8 to i32*
139; CHECK: %cleanup.dest.slot.i8 = call i8* @llvm.framerecover(i8* bitcast (i32 (<{ %struct.A }>*)* @"\01?test@@YAHUA@@@Z" to i8*), i8* %1, i32 3)
140; CHECK: %cleanup.dest.slot = bitcast i8* %cleanup.dest.slot.i8 to i32*
141; CHECK: %e.i8 = bitcast i32* %e to i8*
Reid Kleckner1d2c3f92015-03-03 01:04:39 +0000142; CHECK: %a = getelementptr inbounds <{ %struct.A }>, <{ %struct.A }>* %.reload, i32 0, i32 0
143; CHECK: %a1 = getelementptr inbounds %struct.A, %struct.A* %a, i32 0, i32 0
Reid Kleckner2f05d4c2015-03-03 17:41:09 +0000144; CHECK: %tmp8 = load i32, i32* %a1, align 4
145; CHECK: %tmp9 = load i32, i32* %e, align 4
146; CHECK: %add = add nsw i32 %tmp8, %tmp9
Andrew Kaylor72029c62015-03-03 00:41:03 +0000147; CHECK: store i32 %add, i32* %retval
148; CHECK: store i32 1, i32* %cleanup.dest.slot
149; CHECK: ret i8* blockaddress(@"\01?test@@YAHUA@@@Z", %cleanup)
150; CHECK: }
151
Andrew Kaylor72029c62015-03-03 00:41:03 +0000152declare void @"\01?may_throw@@YAXXZ"() #0
153
154declare i32 @__CxxFrameHandler3(...)
155
156; Function Attrs: nounwind readnone
157declare i32 @llvm.eh.typeid.for(i8*) #1
158
Reid Kleckner2f05d4c2015-03-03 17:41:09 +0000159declare void @llvm.eh.begincatch(i8*, i8*)
Andrew Kaylor72029c62015-03-03 00:41:03 +0000160
161declare void @llvm.eh.endcatch()
162
163; Function Attrs: nounwind
164declare x86_thiscallcc void @"\01??1A@@QAE@XZ"(%struct.A*) #2
165
166attributes #0 = { "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" }
167attributes #1 = { nounwind readnone }
168attributes #2 = { nounwind "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" }
169attributes #3 = { nounwind }
170
171!llvm.ident = !{!0}
172
173!0 = !{!"clang version 3.7.0 (trunk 228868)"}