blob: 4d017fde862d27cdf4d3026ebf2794571ceed3f3 [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 (...) {
10; handle_exception();
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 = 'catch-all.cpp'
18target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
19target triple = "x86_64-pc-windows-msvc"
20
Andrew Kaylor6b67d422015-03-11 23:22:06 +000021; The function entry in this case remains unchanged.
David Majnemercde33032015-03-30 22:58:10 +000022; CHECK: define void @_Z4testv()
Andrew Kaylor6b67d422015-03-11 23:22:06 +000023; CHECK: entry:
24; CHECK: invoke void @_Z9may_throwv()
25; CHECK: to label %invoke.cont unwind label %[[LPAD_LABEL:lpad[0-9]+]]
26
Andrew Kaylor1476e6d2015-02-24 20:49:35 +000027; Function Attrs: uwtable
28define void @_Z4testv() #0 {
29entry:
30 %exn.slot = alloca i8*
31 %ehselector.slot = alloca i32
32 invoke void @_Z9may_throwv()
33 to label %invoke.cont unwind label %lpad
34
35invoke.cont: ; preds = %entry
36 br label %try.cont
37
Andrew Kaylor6b67d422015-03-11 23:22:06 +000038; CHECK: [[LPAD_LABEL]]:{{[ ]+}}; preds = %entry
Reid Klecknerc759fe92015-03-19 22:31:02 +000039; CHECK: landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*)
Reid Klecknere1b22ec2015-03-12 01:38:48 +000040; CHECK-NEXT: catch i8* null
David Blaikie23af6482015-04-16 23:24:18 +000041; CHECK-NEXT: [[RECOVER:\%.+]] = call i8* (...) @llvm.eh.actions(i32 1, i8* null, i32 -1, i8* (i8*, i8*)* @_Z4testv.catch)
Reid Klecknere1b22ec2015-03-12 01:38:48 +000042; CHECK-NEXT: indirectbr i8* [[RECOVER]], [label %try.cont]
Andrew Kaylor6b67d422015-03-11 23:22:06 +000043
Andrew Kaylor1476e6d2015-02-24 20:49:35 +000044lpad: ; preds = %entry
Reid Kleckner6f0e4b82015-03-03 00:05:35 +000045 %tmp = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*)
Andrew Kaylor1476e6d2015-02-24 20:49:35 +000046 catch i8* null
Reid Kleckner6f0e4b82015-03-03 00:05:35 +000047 %tmp1 = extractvalue { i8*, i32 } %tmp, 0
48 store i8* %tmp1, i8** %exn.slot
49 %tmp2 = extractvalue { i8*, i32 } %tmp, 1
50 store i32 %tmp2, i32* %ehselector.slot
Andrew Kaylor1476e6d2015-02-24 20:49:35 +000051 br label %catch
52
Andrew Kaylor6b67d422015-03-11 23:22:06 +000053; CHECK-NOT: catch:
54
Andrew Kaylor1476e6d2015-02-24 20:49:35 +000055catch: ; preds = %lpad
David Blaikiea79ac142015-02-27 21:17:42 +000056 %exn = load i8*, i8** %exn.slot
Reid Kleckner2f05d4c2015-03-03 17:41:09 +000057 call void @llvm.eh.begincatch(i8* %exn, i8* null) #2
Andrew Kaylor1476e6d2015-02-24 20:49:35 +000058 call void @_Z16handle_exceptionv()
59 br label %invoke.cont2
60
Andrew Kaylor6b67d422015-03-11 23:22:06 +000061; CHECK-NOT: invoke.cont2:
62
Andrew Kaylor1476e6d2015-02-24 20:49:35 +000063invoke.cont2: ; preds = %catch
64 call void @llvm.eh.endcatch()
65 br label %try.cont
66
67try.cont: ; preds = %invoke.cont2, %invoke.cont
68 ret void
Andrew Kaylor6b67d422015-03-11 23:22:06 +000069
70; CHECK: }
Andrew Kaylor1476e6d2015-02-24 20:49:35 +000071}
72
David Majnemercde33032015-03-30 22:58:10 +000073; CHECK: define internal i8* @_Z4testv.catch(i8*, i8*)
Andrew Kaylorf0f5e462015-03-03 20:00:16 +000074; CHECK: entry:
Andrew Kaylor1476e6d2015-02-24 20:49:35 +000075; CHECK: call void @_Z16handle_exceptionv()
76; CHECK: ret i8* blockaddress(@_Z4testv, %try.cont)
77; CHECK: }
78
79declare void @_Z9may_throwv() #1
80
81declare i32 @__CxxFrameHandler3(...)
82
Reid Kleckner2f05d4c2015-03-03 17:41:09 +000083declare void @llvm.eh.begincatch(i8*, i8*)
Andrew Kaylor1476e6d2015-02-24 20:49:35 +000084
85declare void @_Z16handle_exceptionv() #1
86
87declare void @llvm.eh.endcatch()
88
89attributes #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" }
90attributes #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" }
91attributes #2 = { noinline noreturn nounwind }
92attributes #3 = { nounwind }
93attributes #4 = { noreturn nounwind }
94
95!llvm.ident = !{!0}
96
97!0 = !{!"clang version 3.7.0 (trunk 226027)"}