blob: 279c4bf6fc7dc93a07503add801acdeb309b3047 [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
Andrew Kaylor1476e6d2015-02-24 20:49:35 +000021@_ZTIi = external constant i8*
22
23; The function entry will be rewritten like this.
David Majnemercde33032015-03-30 22:58:10 +000024; CHECK: define void @_Z4testv()
Andrew Kaylor1476e6d2015-02-24 20:49:35 +000025; CHECK: entry:
Andrew Kaylor6b67d422015-03-11 23:22:06 +000026; CHECK: [[I_PTR:\%.+]] = alloca i32, align 4
27; CHECK: call void (...)* @llvm.frameescape(i32* [[I_PTR]])
Reid Klecknercfb9ce52015-03-05 18:26:34 +000028; CHECK: invoke void @_Z9may_throwv()
Andrew Kaylor6b67d422015-03-11 23:22:06 +000029; CHECK: to label %invoke.cont unwind label %[[LPAD_LABEL:lpad[0-9]+]]
Andrew Kaylor1476e6d2015-02-24 20:49:35 +000030
31; Function Attrs: uwtable
32define void @_Z4testv() #0 {
33entry:
34 %exn.slot = alloca i8*
35 %ehselector.slot = alloca i32
36 %i = alloca i32, align 4
37 invoke void @_Z9may_throwv()
38 to label %invoke.cont unwind label %lpad
39
40invoke.cont: ; preds = %entry
41 br label %try.cont
42
Andrew Kaylor6b67d422015-03-11 23:22:06 +000043; CHECK: [[LPAD_LABEL]]:{{[ ]+}}; preds = %entry
Reid Klecknerc759fe92015-03-19 22:31:02 +000044; CHECK: landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*)
Reid Klecknere1b22ec2015-03-12 01:38:48 +000045; CHECK-NEXT: catch i8* bitcast (i8** @_ZTIi to i8*)
Reid Kleckner3567d272015-04-02 21:13:31 +000046; CHECK-NEXT: [[RECOVER:\%.+]] = call i8* (...)* @llvm.eh.actions(i32 1, i8* bitcast (i8** @_ZTIi to i8*), i32 0, i8* (i8*, i8*)* @_Z4testv.catch)
Reid Klecknere1b22ec2015-03-12 01:38:48 +000047; CHECK-NEXT: indirectbr i8* [[RECOVER]], [label %try.cont]
Andrew Kaylor6b67d422015-03-11 23:22:06 +000048
Andrew Kaylor1476e6d2015-02-24 20:49:35 +000049lpad: ; preds = %entry
Reid Kleckner6f0e4b82015-03-03 00:05:35 +000050 %tmp = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*)
Andrew Kaylor1476e6d2015-02-24 20:49:35 +000051 catch i8* bitcast (i8** @_ZTIi to i8*)
Reid Kleckner6f0e4b82015-03-03 00:05:35 +000052 %tmp1 = extractvalue { i8*, i32 } %tmp, 0
53 store i8* %tmp1, i8** %exn.slot
54 %tmp2 = extractvalue { i8*, i32 } %tmp, 1
55 store i32 %tmp2, i32* %ehselector.slot
Andrew Kaylor1476e6d2015-02-24 20:49:35 +000056 br label %catch.dispatch
57
Andrew Kaylor6b67d422015-03-11 23:22:06 +000058; CHECK-NOT: catch-dispatch:
59
Andrew Kaylor1476e6d2015-02-24 20:49:35 +000060catch.dispatch: ; preds = %lpad
David Blaikiea79ac142015-02-27 21:17:42 +000061 %sel = load i32, i32* %ehselector.slot
Reid Kleckner6f0e4b82015-03-03 00:05:35 +000062 %tmp3 = call i32 @llvm.eh.typeid.for(i8* bitcast (i8** @_ZTIi to i8*)) #3
63 %matches = icmp eq i32 %sel, %tmp3
Andrew Kaylor1476e6d2015-02-24 20:49:35 +000064 br i1 %matches, label %catch, label %eh.resume
65
Andrew Kaylor6b67d422015-03-11 23:22:06 +000066; CHECK-NOT: catch:
67
Andrew Kaylor1476e6d2015-02-24 20:49:35 +000068catch: ; preds = %catch.dispatch
David Blaikiea79ac142015-02-27 21:17:42 +000069 %exn11 = load i8*, i8** %exn.slot
Reid Kleckner2f05d4c2015-03-03 17:41:09 +000070 %i.i8 = bitcast i32* %i to i8*
71 call void @llvm.eh.begincatch(i8* %exn11, i8* %i.i8) #3
Reid Kleckner6f0e4b82015-03-03 00:05:35 +000072 %tmp7 = load i32, i32* %i, align 4
73 call void @_Z10handle_inti(i32 %tmp7)
Andrew Kaylor1476e6d2015-02-24 20:49:35 +000074 br label %invoke.cont2
75
Andrew Kaylor6b67d422015-03-11 23:22:06 +000076; CHECK-NOT: invoke.cont2:
77
Andrew Kaylor1476e6d2015-02-24 20:49:35 +000078invoke.cont2: ; preds = %catch
79 call void @llvm.eh.endcatch() #3
80 br label %try.cont
81
82try.cont: ; preds = %invoke.cont2, %invoke.cont
83 ret void
84
Andrew Kaylor6b67d422015-03-11 23:22:06 +000085; CHECK-NOT: eh.resume:
86
Andrew Kaylor1476e6d2015-02-24 20:49:35 +000087eh.resume: ; preds = %catch.dispatch
David Blaikiea79ac142015-02-27 21:17:42 +000088 %exn3 = load i8*, i8** %exn.slot
89 %sel4 = load i32, i32* %ehselector.slot
Andrew Kaylor1476e6d2015-02-24 20:49:35 +000090 %lpad.val = insertvalue { i8*, i32 } undef, i8* %exn3, 0
91 %lpad.val5 = insertvalue { i8*, i32 } %lpad.val, i32 %sel4, 1
92 resume { i8*, i32 } %lpad.val5
Andrew Kaylor6b67d422015-03-11 23:22:06 +000093
94; CHECK: }
Andrew Kaylor1476e6d2015-02-24 20:49:35 +000095}
96
David Majnemercde33032015-03-30 22:58:10 +000097; CHECK: define internal i8* @_Z4testv.catch(i8*, i8*)
Andrew Kaylorf0f5e462015-03-03 20:00:16 +000098; CHECK: entry:
Andrew Kaylor6b67d422015-03-11 23:22:06 +000099; CHECK: [[RECOVER_I:\%.+]] = call i8* @llvm.framerecover(i8* bitcast (void ()* @_Z4testv to i8*), i8* %1, i32 0)
100; CHECK: [[I_PTR1:\%.+]] = bitcast i8* [[RECOVER_I]] to i32*
101; CHECK: [[TMP:\%.+]] = load i32, i32* [[I_PTR1]], align 4
102; CHECK: call void @_Z10handle_inti(i32 [[TMP]])
Andrew Kaylor1476e6d2015-02-24 20:49:35 +0000103; CHECK: ret i8* blockaddress(@_Z4testv, %try.cont)
104; CHECK: }
105
106declare void @_Z9may_throwv() #1
107
108declare i32 @__CxxFrameHandler3(...)
109
110; Function Attrs: nounwind readnone
111declare i32 @llvm.eh.typeid.for(i8*) #2
112
Reid Kleckner2f05d4c2015-03-03 17:41:09 +0000113declare void @llvm.eh.begincatch(i8*, i8*)
Andrew Kaylor1476e6d2015-02-24 20:49:35 +0000114
115declare void @llvm.eh.endcatch()
116
117declare void @_Z10handle_inti(i32) #1
118
119attributes #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" }
120attributes #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" }
121attributes #2 = { nounwind readnone }
122attributes #3 = { nounwind }
123
124!llvm.ident = !{!0}
125
126!0 = !{!"clang version 3.7.0 (trunk 227474) (llvm/trunk 227508)"}