blob: 927aeed3b6f3773b60c00a4344842ed16693acb7 [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.
David Majnemercde33032015-03-30 22:58:10 +000039; CHECK: define i32 @"\01?test@@YAHUA@@@Z"(<{ %struct.A }>* inalloca)
Andrew Kaylor72029c62015-03-03 00:41:03 +000040; CHECK: entry:
Andrew Kaylor6b67d422015-03-11 23:22:06 +000041; CHECK: [[TMP_REGMEM:\%.+]] = alloca <{ %struct.A }>*
Reid Klecknerfd7df282015-04-22 21:05:21 +000042; CHECK: store <{ %struct.A }>* %0, <{ %struct.A }>** [[TMP_REGMEM]]
Andrew Kaylor6b67d422015-03-11 23:22:06 +000043; CHECK: [[RETVAL:\%.+]] = alloca i32, align 4
44; CHECK: [[E_PTR:\%.+]] = alloca i32, align 4
45; CHECK: [[CLEANUP_SLOT:\%.+]] = alloca i32
David Blaikie23af6482015-04-16 23:24:18 +000046; CHECK: call void (...) @llvm.frameescape(i32* %e, <{ %struct.A }>** [[TMP_REGMEM]], i32* [[RETVAL]], i32* [[CLEANUP_SLOT]])
Andrew Kaylor72029c62015-03-03 00:41:03 +000047; CHECK: invoke void @"\01?may_throw@@YAXXZ"()
Andrew Kaylor6b67d422015-03-11 23:22:06 +000048; CHECK: to label %invoke.cont unwind label %[[LPAD_LABEL:lpad[0-9]*]]
Andrew Kaylor72029c62015-03-03 00:41:03 +000049
50define i32 @"\01?test@@YAHUA@@@Z"(<{ %struct.A }>* inalloca) #0 {
51entry:
52 %retval = alloca i32, align 4
53 %exn.slot = alloca i8*
54 %ehselector.slot = alloca i32
55 %e = alloca i32, align 4
56 %cleanup.dest.slot = alloca i32
57 invoke void @"\01?may_throw@@YAXXZ"()
58 to label %invoke.cont unwind label %lpad
59
60invoke.cont: ; preds = %entry
61 br label %try.cont
62
Andrew Kaylor6b67d422015-03-11 23:22:06 +000063; CHECK: [[LPAD_LABEL]]:{{[ ]+}}; preds = %entry
Reid Klecknerc759fe92015-03-19 22:31:02 +000064; CHECK: landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*)
Reid Klecknere1b22ec2015-03-12 01:38:48 +000065; CHECK-NEXT: cleanup
66; CHECK-NEXT: catch i8* bitcast (%rtti.TypeDescriptor2* @"\01??_R0H@8" to i8*)
David Blaikie23af6482015-04-16 23:24:18 +000067; CHECK-NEXT: [[RECOVER:\%recover.*]] = call i8* (...) @llvm.eh.actions(i32 1, i8* bitcast (%rtti.TypeDescriptor2* @"\01??_R0H@8" to i8*), i32 0, 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 +000068; CHECK-NEXT: indirectbr i8* [[RECOVER]], [label %cleanup]
Andrew Kaylor6b67d422015-03-11 23:22:06 +000069
Andrew Kaylor72029c62015-03-03 00:41:03 +000070lpad: ; preds = %entry
71 %1 = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*)
72 cleanup
73 catch i8* bitcast (%rtti.TypeDescriptor2* @"\01??_R0H@8" to i8*)
74 %2 = extractvalue { i8*, i32 } %1, 0
75 store i8* %2, i8** %exn.slot
76 %3 = extractvalue { i8*, i32 } %1, 1
77 store i32 %3, i32* %ehselector.slot
78 br label %catch.dispatch
79
Andrew Kaylor6b67d422015-03-11 23:22:06 +000080; CHECK-NOT: catch.dispatch:
81
Andrew Kaylor72029c62015-03-03 00:41:03 +000082catch.dispatch: ; preds = %lpad
Reid Kleckner1d2c3f92015-03-03 01:04:39 +000083 %sel = load i32, i32* %ehselector.slot
Andrew Kaylor72029c62015-03-03 00:41:03 +000084 %4 = call i32 @llvm.eh.typeid.for(i8* bitcast (%rtti.TypeDescriptor2* @"\01??_R0H@8" to i8*)) #3
85 %matches = icmp eq i32 %sel, %4
86 br i1 %matches, label %catch, label %ehcleanup
87
Andrew Kaylor6b67d422015-03-11 23:22:06 +000088; CHECK-NOT: catch:
89
Andrew Kaylor72029c62015-03-03 00:41:03 +000090catch: ; preds = %catch.dispatch
Reid Kleckner1d2c3f92015-03-03 01:04:39 +000091 %exn = load i8*, i8** %exn.slot
Reid Kleckner2f05d4c2015-03-03 17:41:09 +000092 %e.i8 = bitcast i32* %e to i8*
93 call void @llvm.eh.begincatch(i8* %exn, i8* %e.i8) #3
Reid Kleckner1d2c3f92015-03-03 01:04:39 +000094 %a = getelementptr inbounds <{ %struct.A }>, <{ %struct.A }>* %0, i32 0, i32 0
95 %a1 = getelementptr inbounds %struct.A, %struct.A* %a, i32 0, i32 0
Reid Kleckner2f05d4c2015-03-03 17:41:09 +000096 %tmp8 = load i32, i32* %a1, align 4
97 %tmp9 = load i32, i32* %e, align 4
98 %add = add nsw i32 %tmp8, %tmp9
Andrew Kaylor72029c62015-03-03 00:41:03 +000099 store i32 %add, i32* %retval
100 store i32 1, i32* %cleanup.dest.slot
101 call void @llvm.eh.endcatch() #3
102 br label %cleanup
103
104try.cont: ; preds = %invoke.cont
105 store i32 0, i32* %retval
106 store i32 1, i32* %cleanup.dest.slot
107 br label %cleanup
108
109; The cleanup block should be re-written like this.
Andrew Kaylor6b67d422015-03-11 23:22:06 +0000110; CHECK: cleanup:{{[ ]+}}; preds = %[[LPAD_LABEL]], %try.cont
Reid Klecknerfd7df282015-04-22 21:05:21 +0000111; CHECK: %a2 = getelementptr inbounds <{ %struct.A }>, <{ %struct.A }>* %0, i32 0, i32 0
112; CHECK: call x86_thiscallcc void @"\01??1A@@QAE@XZ"(%struct.A* %a2)
Andrew Kaylor6b67d422015-03-11 23:22:06 +0000113; CHECK: [[TMP1:\%.+]] = load i32, i32* [[RETVAL]]
114; CHECK: ret i32 [[TMP1]]
Andrew Kaylor72029c62015-03-03 00:41:03 +0000115
116cleanup: ; preds = %try.cont, %catch
Reid Kleckner1d2c3f92015-03-03 01:04:39 +0000117 %a2 = 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* %a2) #3
Reid Kleckner2f05d4c2015-03-03 17:41:09 +0000119 %tmp10 = load i32, i32* %retval
120 ret i32 %tmp10
Andrew Kaylor72029c62015-03-03 00:41:03 +0000121
Andrew Kaylor6b67d422015-03-11 23:22:06 +0000122; CHECK-NOT: ehcleanup:
123
Andrew Kaylor72029c62015-03-03 00:41:03 +0000124ehcleanup: ; preds = %catch.dispatch
Reid Kleckner1d2c3f92015-03-03 01:04:39 +0000125 %a3 = getelementptr inbounds <{ %struct.A }>, <{ %struct.A }>* %0, i32 0, i32 0
Andrew Kaylor72029c62015-03-03 00:41:03 +0000126 call x86_thiscallcc void @"\01??1A@@QAE@XZ"(%struct.A* %a3) #3
127 br label %eh.resume
128
Andrew Kaylor6b67d422015-03-11 23:22:06 +0000129; CHECK-NOT: eh.resume:
130
Andrew Kaylor72029c62015-03-03 00:41:03 +0000131eh.resume: ; preds = %ehcleanup
Reid Kleckner1d2c3f92015-03-03 01:04:39 +0000132 %exn2 = load i8*, i8** %exn.slot
133 %sel3 = load i32, i32* %ehselector.slot
Andrew Kaylor72029c62015-03-03 00:41:03 +0000134 %lpad.val = insertvalue { i8*, i32 } undef, i8* %exn2, 0
135 %lpad.val4 = insertvalue { i8*, i32 } %lpad.val, i32 %sel3, 1
136 resume { i8*, i32 } %lpad.val4
Andrew Kaylor6b67d422015-03-11 23:22:06 +0000137
138; CHECK: }
Andrew Kaylor72029c62015-03-03 00:41:03 +0000139}
140
141; The following catch handler should be outlined.
David Majnemercde33032015-03-30 22:58:10 +0000142; CHECK: define internal i8* @"\01?test@@YAHUA@@@Z.catch"(i8*, i8*)
Andrew Kaylorf0f5e462015-03-03 20:00:16 +0000143; CHECK: entry:
Andrew Kaylor6b67d422015-03-11 23:22:06 +0000144; CHECK: [[RECOVER_E:\%.+]] = call i8* @llvm.framerecover(i8* bitcast (i32 (<{ %struct.A }>*)* @"\01?test@@YAHUA@@@Z" to i8*), i8* %1, i32 0)
145; CHECK: [[E_PTR:\%.+]] = bitcast i8* [[RECOVER_E]] to i32*
146; CHECK: [[RECOVER_EH_TEMP:\%.+]] = call i8* @llvm.framerecover(i8* bitcast (i32 (<{ %struct.A }>*)* @"\01?test@@YAHUA@@@Z" to i8*), i8* %1, i32 1)
147; CHECK: [[EH_TEMP:\%.+]] = bitcast i8* [[RECOVER_EH_TEMP]] to <{ %struct.A }>**
Andrew Kaylor6b67d422015-03-11 23:22:06 +0000148; CHECK: [[RECOVER_RETVAL:\%.+]] = call i8* @llvm.framerecover(i8* bitcast (i32 (<{ %struct.A }>*)* @"\01?test@@YAHUA@@@Z" to i8*), i8* %1, i32 2)
149; CHECK: [[RETVAL1:\%.+]] = bitcast i8* [[RECOVER_RETVAL]] to i32*
150; CHECK: [[RECOVER_CLEANUPSLOT:\%.+]] = call i8* @llvm.framerecover(i8* bitcast (i32 (<{ %struct.A }>*)* @"\01?test@@YAHUA@@@Z" to i8*), i8* %1, i32 3)
151; CHECK: [[CLEANUPSLOT1:\%.+]] = bitcast i8* [[RECOVER_CLEANUPSLOT]] to i32*
152; CHECK: [[E_I8PTR:\%.+]] = bitcast i32* [[E_PTR]] to i8*
Reid Klecknerfd7df282015-04-22 21:05:21 +0000153; CHECK: [[TMP_RELOAD:\%.+]] = load <{ %struct.A }>*, <{ %struct.A }>** [[EH_TEMP]]
Andrew Kaylor6b67d422015-03-11 23:22:06 +0000154; CHECK: [[RECOVER_A:\%.+]] = getelementptr inbounds <{ %struct.A }>, <{ %struct.A }>* [[TMP_RELOAD]], i32 0, i32 0
155; CHECK: [[A1:\%.+]] = getelementptr inbounds %struct.A, %struct.A* [[RECOVER_A]], i32 0, i32 0
156; CHECK: [[TMP2:\%.+]] = load i32, i32* [[A1]], align 4
157; CHECK: [[TMP3:\%.+]] = load i32, i32* [[E_PTR]], align 4
158; CHECK: [[ADD:\%.+]] = add nsw i32 [[TMP2]], [[TMP3]]
159; CHECK: store i32 [[ADD]], i32* [[RETVAL1]]
160; CHECK: store i32 1, i32* [[CLEANUPSLOT1]]
Andrew Kaylor72029c62015-03-03 00:41:03 +0000161; CHECK: ret i8* blockaddress(@"\01?test@@YAHUA@@@Z", %cleanup)
162; CHECK: }
163
Andrew Kaylor6b67d422015-03-11 23:22:06 +0000164; The following cleanup handler should be outlined.
David Majnemercde33032015-03-30 22:58:10 +0000165; CHECK: define internal void @"\01?test@@YAHUA@@@Z.cleanup"(i8*, i8*)
Andrew Kaylor6b67d422015-03-11 23:22:06 +0000166; CHECK: entry:
167; CHECK: [[RECOVER_EH_TEMP1:\%.+]] = call i8* @llvm.framerecover(i8* bitcast (i32 (<{ %struct.A }>*)* @"\01?test@@YAHUA@@@Z" to i8*), i8* %1, i32 1)
168; CHECK: [[EH_TEMP1:\%.+]] = bitcast i8* [[RECOVER_EH_TEMP]] to <{ %struct.A }>**
169; CHECK: [[TMP_RELOAD1:\%.+]] = load <{ %struct.A }>*, <{ %struct.A }>** [[EH_TEMP1]]
170; CHECK: [[A3:\%.+]] = getelementptr inbounds <{ %struct.A }>, <{ %struct.A }>* [[TMP_RELOAD1]], i32 0, i32 0
171; CHECK: call x86_thiscallcc void @"\01??1A@@QAE@XZ"(%struct.A* [[A3]])
172; CHECK: ret void
173; CHECK: }
174
Andrew Kaylor72029c62015-03-03 00:41:03 +0000175declare void @"\01?may_throw@@YAXXZ"() #0
176
177declare i32 @__CxxFrameHandler3(...)
178
179; Function Attrs: nounwind readnone
180declare i32 @llvm.eh.typeid.for(i8*) #1
181
Reid Kleckner2f05d4c2015-03-03 17:41:09 +0000182declare void @llvm.eh.begincatch(i8*, i8*)
Andrew Kaylor72029c62015-03-03 00:41:03 +0000183
184declare void @llvm.eh.endcatch()
185
186; Function Attrs: nounwind
187declare x86_thiscallcc void @"\01??1A@@QAE@XZ"(%struct.A*) #2
188
189attributes #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" }
190attributes #1 = { nounwind readnone }
191attributes #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" }
192attributes #3 = { nounwind }
193
194!llvm.ident = !{!0}
195
196!0 = !{!"clang version 3.7.0 (trunk 228868)"}