blob: f3f36318eb0279e4795fb6007afa8e28f7558b07 [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:
Andrew Kaylor6b67d422015-03-11 23:22:06 +000041; CHECK: [[TMP_REGMEM:\%.+]] = alloca <{ %struct.A }>*
42; CHECK: [[TMP:\%.+]] = select i1 true, <{ %struct.A }>* %0, <{ %struct.A }>* undef
43; CHECK: store <{ %struct.A }>* [[TMP]], <{ %struct.A }>** [[TMP_REGMEM]]
44; CHECK: [[RETVAL:\%.+]] = alloca i32, align 4
45; CHECK: [[E_PTR:\%.+]] = alloca i32, align 4
46; CHECK: [[CLEANUP_SLOT:\%.+]] = alloca i32
47; CHECK: call void (...)* @llvm.frameescape(i32* %e, <{ %struct.A }>** [[TMP_REGMEM]], i32* [[RETVAL]], i32* [[CLEANUP_SLOT]])
Andrew Kaylor72029c62015-03-03 00:41:03 +000048; CHECK: invoke void @"\01?may_throw@@YAXXZ"()
Andrew Kaylor6b67d422015-03-11 23:22:06 +000049; CHECK: to label %invoke.cont unwind label %[[LPAD_LABEL:lpad[0-9]*]]
Andrew Kaylor72029c62015-03-03 00:41:03 +000050
51define i32 @"\01?test@@YAHUA@@@Z"(<{ %struct.A }>* inalloca) #0 {
52entry:
53 %retval = alloca i32, align 4
54 %exn.slot = alloca i8*
55 %ehselector.slot = alloca i32
56 %e = alloca i32, align 4
57 %cleanup.dest.slot = alloca i32
58 invoke void @"\01?may_throw@@YAXXZ"()
59 to label %invoke.cont unwind label %lpad
60
61invoke.cont: ; preds = %entry
62 br label %try.cont
63
Andrew Kaylor6b67d422015-03-11 23:22:06 +000064; CHECK: [[LPAD_LABEL]]:{{[ ]+}}; preds = %entry
Reid Klecknerc759fe92015-03-19 22:31:02 +000065; CHECK: landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*)
Reid Klecknere1b22ec2015-03-12 01:38:48 +000066; CHECK-NEXT: cleanup
67; CHECK-NEXT: catch i8* bitcast (%rtti.TypeDescriptor2* @"\01??_R0H@8" to i8*)
Reid Klecknerc759fe92015-03-19 22:31:02 +000068; CHECK-NEXT: [[RECOVER:\%recover.*]] = call i8* (...)* @llvm.eh.actions(i32 1, i8* bitcast (%rtti.TypeDescriptor2* @"\01??_R0H@8" to i8*), i32* %e, i8* (i8*, i8*)* @"\01?test@@YAHUA@@@Z.catch", i32 0, void (i8*, i8*)* @"\01?test@@YAHUA@@@Z.cleanup")
Reid Klecknere1b22ec2015-03-12 01:38:48 +000069; CHECK-NEXT: indirectbr i8* [[RECOVER]], [label %cleanup]
Andrew Kaylor6b67d422015-03-11 23:22:06 +000070
Andrew Kaylor72029c62015-03-03 00:41:03 +000071lpad: ; preds = %entry
72 %1 = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*)
73 cleanup
74 catch i8* bitcast (%rtti.TypeDescriptor2* @"\01??_R0H@8" to i8*)
75 %2 = extractvalue { i8*, i32 } %1, 0
76 store i8* %2, i8** %exn.slot
77 %3 = extractvalue { i8*, i32 } %1, 1
78 store i32 %3, i32* %ehselector.slot
79 br label %catch.dispatch
80
Andrew Kaylor6b67d422015-03-11 23:22:06 +000081; CHECK-NOT: catch.dispatch:
82
Andrew Kaylor72029c62015-03-03 00:41:03 +000083catch.dispatch: ; preds = %lpad
Reid Kleckner1d2c3f92015-03-03 01:04:39 +000084 %sel = load i32, i32* %ehselector.slot
Andrew Kaylor72029c62015-03-03 00:41:03 +000085 %4 = call i32 @llvm.eh.typeid.for(i8* bitcast (%rtti.TypeDescriptor2* @"\01??_R0H@8" to i8*)) #3
86 %matches = icmp eq i32 %sel, %4
87 br i1 %matches, label %catch, label %ehcleanup
88
Andrew Kaylor6b67d422015-03-11 23:22:06 +000089; CHECK-NOT: catch:
90
Andrew Kaylor72029c62015-03-03 00:41:03 +000091catch: ; preds = %catch.dispatch
Reid Kleckner1d2c3f92015-03-03 01:04:39 +000092 %exn = load i8*, i8** %exn.slot
Reid Kleckner2f05d4c2015-03-03 17:41:09 +000093 %e.i8 = bitcast i32* %e to i8*
94 call void @llvm.eh.begincatch(i8* %exn, i8* %e.i8) #3
Reid Kleckner1d2c3f92015-03-03 01:04:39 +000095 %a = getelementptr inbounds <{ %struct.A }>, <{ %struct.A }>* %0, i32 0, i32 0
96 %a1 = getelementptr inbounds %struct.A, %struct.A* %a, i32 0, i32 0
Reid Kleckner2f05d4c2015-03-03 17:41:09 +000097 %tmp8 = load i32, i32* %a1, align 4
98 %tmp9 = load i32, i32* %e, align 4
99 %add = add nsw i32 %tmp8, %tmp9
Andrew Kaylor72029c62015-03-03 00:41:03 +0000100 store i32 %add, i32* %retval
101 store i32 1, i32* %cleanup.dest.slot
102 call void @llvm.eh.endcatch() #3
103 br label %cleanup
104
105try.cont: ; preds = %invoke.cont
106 store i32 0, i32* %retval
107 store i32 1, i32* %cleanup.dest.slot
108 br label %cleanup
109
110; The cleanup block should be re-written like this.
Andrew Kaylor6b67d422015-03-11 23:22:06 +0000111; CHECK: cleanup:{{[ ]+}}; preds = %[[LPAD_LABEL]], %try.cont
Reid Kleckner1d2c3f92015-03-03 01:04:39 +0000112; CHECK-NOT: %a2 = getelementptr inbounds <{ %struct.A }>, <{ %struct.A }>* %0, i32 0, i32 0
Andrew Kaylor6b67d422015-03-11 23:22:06 +0000113; CHECK: [[TMP_RELOAD:\%.+]] = load volatile <{ %struct.A }>*, <{ %struct.A }>** [[TMP_REGMEM]]
114; CHECK: [[A2:\%.+]] = getelementptr inbounds <{ %struct.A }>, <{ %struct.A }>* [[TMP_RELOAD]], i32 0, i32 0
115; CHECK: call x86_thiscallcc void @"\01??1A@@QAE@XZ"(%struct.A* [[A2]])
116; CHECK: [[TMP1:\%.+]] = load i32, i32* [[RETVAL]]
117; CHECK: ret i32 [[TMP1]]
Andrew Kaylor72029c62015-03-03 00:41:03 +0000118
119cleanup: ; preds = %try.cont, %catch
Reid Kleckner1d2c3f92015-03-03 01:04:39 +0000120 %a2 = getelementptr inbounds <{ %struct.A }>, <{ %struct.A }>* %0, i32 0, i32 0
Andrew Kaylor72029c62015-03-03 00:41:03 +0000121 call x86_thiscallcc void @"\01??1A@@QAE@XZ"(%struct.A* %a2) #3
Reid Kleckner2f05d4c2015-03-03 17:41:09 +0000122 %tmp10 = load i32, i32* %retval
123 ret i32 %tmp10
Andrew Kaylor72029c62015-03-03 00:41:03 +0000124
Andrew Kaylor6b67d422015-03-11 23:22:06 +0000125; CHECK-NOT: ehcleanup:
126
Andrew Kaylor72029c62015-03-03 00:41:03 +0000127ehcleanup: ; preds = %catch.dispatch
Reid Kleckner1d2c3f92015-03-03 01:04:39 +0000128 %a3 = getelementptr inbounds <{ %struct.A }>, <{ %struct.A }>* %0, i32 0, i32 0
Andrew Kaylor72029c62015-03-03 00:41:03 +0000129 call x86_thiscallcc void @"\01??1A@@QAE@XZ"(%struct.A* %a3) #3
130 br label %eh.resume
131
Andrew Kaylor6b67d422015-03-11 23:22:06 +0000132; CHECK-NOT: eh.resume:
133
Andrew Kaylor72029c62015-03-03 00:41:03 +0000134eh.resume: ; preds = %ehcleanup
Reid Kleckner1d2c3f92015-03-03 01:04:39 +0000135 %exn2 = load i8*, i8** %exn.slot
136 %sel3 = load i32, i32* %ehselector.slot
Andrew Kaylor72029c62015-03-03 00:41:03 +0000137 %lpad.val = insertvalue { i8*, i32 } undef, i8* %exn2, 0
138 %lpad.val4 = insertvalue { i8*, i32 } %lpad.val, i32 %sel3, 1
139 resume { i8*, i32 } %lpad.val4
Andrew Kaylor6b67d422015-03-11 23:22:06 +0000140
141; CHECK: }
Andrew Kaylor72029c62015-03-03 00:41:03 +0000142}
143
144; The following catch handler should be outlined.
Andrew Kaylorf0f5e462015-03-03 20:00:16 +0000145; CHECK: define internal i8* @"\01?test@@YAHUA@@@Z.catch"(i8*, i8*) {
146; CHECK: entry:
Andrew Kaylor6b67d422015-03-11 23:22:06 +0000147; CHECK: [[RECOVER_E:\%.+]] = call i8* @llvm.framerecover(i8* bitcast (i32 (<{ %struct.A }>*)* @"\01?test@@YAHUA@@@Z" to i8*), i8* %1, i32 0)
148; CHECK: [[E_PTR:\%.+]] = bitcast i8* [[RECOVER_E]] to i32*
149; CHECK: [[RECOVER_EH_TEMP:\%.+]] = call i8* @llvm.framerecover(i8* bitcast (i32 (<{ %struct.A }>*)* @"\01?test@@YAHUA@@@Z" to i8*), i8* %1, i32 1)
150; CHECK: [[EH_TEMP:\%.+]] = bitcast i8* [[RECOVER_EH_TEMP]] to <{ %struct.A }>**
151; CHECK: [[TMP_RELOAD:\%.+]] = load <{ %struct.A }>*, <{ %struct.A }>** [[EH_TEMP]]
152; CHECK: [[RECOVER_RETVAL:\%.+]] = call i8* @llvm.framerecover(i8* bitcast (i32 (<{ %struct.A }>*)* @"\01?test@@YAHUA@@@Z" to i8*), i8* %1, i32 2)
153; CHECK: [[RETVAL1:\%.+]] = bitcast i8* [[RECOVER_RETVAL]] to i32*
154; CHECK: [[RECOVER_CLEANUPSLOT:\%.+]] = call i8* @llvm.framerecover(i8* bitcast (i32 (<{ %struct.A }>*)* @"\01?test@@YAHUA@@@Z" to i8*), i8* %1, i32 3)
155; CHECK: [[CLEANUPSLOT1:\%.+]] = bitcast i8* [[RECOVER_CLEANUPSLOT]] to i32*
156; CHECK: [[E_I8PTR:\%.+]] = bitcast i32* [[E_PTR]] to i8*
157; CHECK: [[RECOVER_A:\%.+]] = getelementptr inbounds <{ %struct.A }>, <{ %struct.A }>* [[TMP_RELOAD]], i32 0, i32 0
158; CHECK: [[A1:\%.+]] = getelementptr inbounds %struct.A, %struct.A* [[RECOVER_A]], i32 0, i32 0
159; CHECK: [[TMP2:\%.+]] = load i32, i32* [[A1]], align 4
160; CHECK: [[TMP3:\%.+]] = load i32, i32* [[E_PTR]], align 4
161; CHECK: [[ADD:\%.+]] = add nsw i32 [[TMP2]], [[TMP3]]
162; CHECK: store i32 [[ADD]], i32* [[RETVAL1]]
163; CHECK: store i32 1, i32* [[CLEANUPSLOT1]]
Andrew Kaylor72029c62015-03-03 00:41:03 +0000164; CHECK: ret i8* blockaddress(@"\01?test@@YAHUA@@@Z", %cleanup)
165; CHECK: }
166
Andrew Kaylor6b67d422015-03-11 23:22:06 +0000167; The following cleanup handler should be outlined.
168; CHECK: define internal void @"\01?test@@YAHUA@@@Z.cleanup"(i8*, i8*) {
169; CHECK: entry:
170; CHECK: [[RECOVER_EH_TEMP1:\%.+]] = call i8* @llvm.framerecover(i8* bitcast (i32 (<{ %struct.A }>*)* @"\01?test@@YAHUA@@@Z" to i8*), i8* %1, i32 1)
171; CHECK: [[EH_TEMP1:\%.+]] = bitcast i8* [[RECOVER_EH_TEMP]] to <{ %struct.A }>**
172; CHECK: [[TMP_RELOAD1:\%.+]] = load <{ %struct.A }>*, <{ %struct.A }>** [[EH_TEMP1]]
173; CHECK: [[A3:\%.+]] = getelementptr inbounds <{ %struct.A }>, <{ %struct.A }>* [[TMP_RELOAD1]], i32 0, i32 0
174; CHECK: call x86_thiscallcc void @"\01??1A@@QAE@XZ"(%struct.A* [[A3]])
175; CHECK: ret void
176; CHECK: }
177
Andrew Kaylor72029c62015-03-03 00:41:03 +0000178declare void @"\01?may_throw@@YAXXZ"() #0
179
180declare i32 @__CxxFrameHandler3(...)
181
182; Function Attrs: nounwind readnone
183declare i32 @llvm.eh.typeid.for(i8*) #1
184
Reid Kleckner2f05d4c2015-03-03 17:41:09 +0000185declare void @llvm.eh.begincatch(i8*, i8*)
Andrew Kaylor72029c62015-03-03 00:41:03 +0000186
187declare void @llvm.eh.endcatch()
188
189; Function Attrs: nounwind
190declare x86_thiscallcc void @"\01??1A@@QAE@XZ"(%struct.A*) #2
191
192attributes #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" }
193attributes #1 = { nounwind readnone }
194attributes #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" }
195attributes #3 = { nounwind }
196
197!llvm.ident = !{!0}
198
199!0 = !{!"clang version 3.7.0 (trunk 228868)"}