Move the personality function from LandingPadInst to Function
[oota-llvm.git] / test / CodeGen / WinEH / cppeh-min-unwind.ll
1 ; RUN: opt -mtriple=x86_64-pc-windows-msvc -winehprepare -S -o - < %s | FileCheck %s
2
3 ; This test was generated from the following source:
4 ;
5 ; class SomeClass {
6 ; public:
7 ;   SomeClass();
8 ;   ~SomeClass();
9 ; };
10 ;
11 ; void test() {
12 ;   SomeClass obj;
13 ;   may_throw();
14 ; }
15
16
17 ; ModuleID = 'min-unwind.cpp'
18 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
19 target triple = "x86_64-pc-windows-msvc"
20
21 %class.SomeClass = type { [28 x i32] }
22
23 ; The function entry should be rewritten like this.
24 ; CHECK: define void @_Z4testv()
25 ; CHECK: entry:
26 ; CHECK:   [[OBJ_PTR:\%.+]] = alloca %class.SomeClass, align 4
27 ; CHECK:   call void @_ZN9SomeClassC1Ev(%class.SomeClass* [[OBJ_PTR]])
28 ; CHECK:   call void (...) @llvm.frameescape(%class.SomeClass* [[OBJ_PTR]])
29 ; CHECK:   invoke void @_Z9may_throwv()
30 ; CHECK:           to label %invoke.cont unwind label %[[LPAD_LABEL:lpad[0-9]*]]
31
32 ; Function Attrs: uwtable
33 define void @_Z4testv() #0 personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*) {
34 entry:
35   %obj = alloca %class.SomeClass, align 4
36   %exn.slot = alloca i8*
37   %ehselector.slot = alloca i32
38   call void @_ZN9SomeClassC1Ev(%class.SomeClass* %obj)
39   invoke void @_Z9may_throwv()
40           to label %invoke.cont unwind label %lpad
41
42 invoke.cont:                                      ; preds = %entry
43   call void @_ZN9SomeClassD1Ev(%class.SomeClass* %obj)
44   ret void
45
46 ; CHECK: [[LPAD_LABEL]]:{{[ ]+}}; preds = %entry
47 ; CHECK:   landingpad { i8*, i32 }
48 ; CHECK-NEXT:           cleanup
49 ; CHECK-NEXT:   [[RECOVER:\%.+]] = call i8* (...) @llvm.eh.actions(i32 0, void (i8*, i8*)* @_Z4testv.cleanup)
50 ; CHECK-NEXT:   indirectbr i8* [[RECOVER]], []
51
52 lpad:                                             ; preds = %entry
53   %tmp = landingpad { i8*, i32 }
54           cleanup
55   %tmp1 = extractvalue { i8*, i32 } %tmp, 0
56   store i8* %tmp1, i8** %exn.slot
57   %tmp2 = extractvalue { i8*, i32 } %tmp, 1
58   store i32 %tmp2, i32* %ehselector.slot
59   call void @_ZN9SomeClassD1Ev(%class.SomeClass* %obj)
60   br label %eh.resume
61
62 ; CHECK-NOT: eh.resume:
63
64 eh.resume:                                        ; preds = %lpad
65   %exn = load i8*, i8** %exn.slot
66   %sel = load i32, i32* %ehselector.slot
67   %lpad.val = insertvalue { i8*, i32 } undef, i8* %exn, 0
68   %lpad.val2 = insertvalue { i8*, i32 } %lpad.val, i32 %sel, 1
69   resume { i8*, i32 } %lpad.val2
70
71 ; CHECK: }
72 }
73
74 ; This cleanup handler should be outlined.
75 ; CHECK: define internal void @_Z4testv.cleanup(i8*, i8*)
76 ; CHECK: entry:
77 ; CHECK:   [[RECOVER_OBJ:\%.+]] = call i8* @llvm.framerecover(i8* bitcast (void ()* @_Z4testv to i8*), i8* %1, i32 0)
78 ; CHECK:   [[OBJ_PTR1:\%.+]] = bitcast i8* [[RECOVER_OBJ]] to %class.SomeClass*
79 ; CHECK:   call void @_ZN9SomeClassD1Ev(%class.SomeClass* [[OBJ_PTR1]])
80 ; CHECK:   ret void
81 ; CHECK: }
82
83 declare void @_ZN9SomeClassC1Ev(%class.SomeClass*) #1
84
85 declare void @_Z9may_throwv() #1
86
87 declare i32 @__CxxFrameHandler3(...)
88
89 declare void @_ZN9SomeClassD1Ev(%class.SomeClass*) #1
90
91 attributes #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" }
92 attributes #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" }
93 attributes #2 = { noinline noreturn nounwind }
94 attributes #3 = { noreturn nounwind }
95 attributes #4 = { nounwind }
96
97 !llvm.ident = !{!0}
98
99 !0 = !{!"clang version 3.7.0 (trunk 226027)"}