Avoid copying LiveInterval, this could lead to a double-delete
[oota-llvm.git] / test / CodeGen / X86 / 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 ; This structure should be created for the frame allocation.
22 ; CHECK: %struct._Z4testv.ehdata = type { i32, i8*, %class.SomeClass }
23
24 %class.SomeClass = type { [28 x i32] }
25
26 ; The function entry should be rewritten like this.
27 ; CHECK: define void @_Z4testv() #0 {
28 ; CHECK: entry:
29 ; CHECK:   %frame.alloc = call i8* @llvm.frameallocate(i32 128)
30 ; CHECK:   %eh.data = bitcast i8* %frame.alloc to %struct._Z4testv.ehdata*
31 ; CHECK-NOT:  %obj = alloca %class.SomeClass, align 4
32 ; CHECK:   %obj = getelementptr inbounds %struct._Z4testv.ehdata, %struct._Z4testv.ehdata* %eh.data, i32 0, i32 2
33
34 ; Function Attrs: uwtable
35 define void @_Z4testv() #0 {
36 entry:
37   %obj = alloca %class.SomeClass, align 4
38   %exn.slot = alloca i8*
39   %ehselector.slot = alloca i32
40   call void @_ZN9SomeClassC1Ev(%class.SomeClass* %obj)
41   invoke void @_Z9may_throwv()
42           to label %invoke.cont unwind label %lpad
43
44 invoke.cont:                                      ; preds = %entry
45   call void @_ZN9SomeClassD1Ev(%class.SomeClass* %obj)
46   ret void
47
48 lpad:                                             ; preds = %entry
49   %tmp = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*)
50           cleanup
51   %tmp1 = extractvalue { i8*, i32 } %tmp, 0
52   store i8* %tmp1, i8** %exn.slot
53   %tmp2 = extractvalue { i8*, i32 } %tmp, 1
54   store i32 %tmp2, i32* %ehselector.slot
55   call void @_ZN9SomeClassD1Ev(%class.SomeClass* %obj)
56   br label %eh.resume
57
58 eh.resume:                                        ; preds = %lpad
59   %exn = load i8*, i8** %exn.slot
60   %sel = load i32, i32* %ehselector.slot
61   %lpad.val = insertvalue { i8*, i32 } undef, i8* %exn, 0
62   %lpad.val2 = insertvalue { i8*, i32 } %lpad.val, i32 %sel, 1
63   resume { i8*, i32 } %lpad.val2
64 }
65
66 ; This cleanup handler should be outlined.
67 ; CHECK: define internal void @_Z4testv.cleanup(i8*, i8*) {
68 ; CHECK: entry:
69 ; CHECK:   %eh.alloc = call i8* @llvm.framerecover(i8* bitcast (void ()* @_Z4testv to i8*), i8* %1)
70 ; CHECK:   %eh.data = bitcast i8* %eh.alloc to %struct._Z4testv.ehdata*
71 ; CHECK:   %obj = getelementptr inbounds %struct._Z4testv.ehdata, %struct._Z4testv.ehdata* %eh.data, i32 0, i32 2
72 ; CHECK:   call void @_ZN9SomeClassD1Ev(%class.SomeClass* %obj)
73 ; CHECK:   ret void
74 ; CHECK: }
75
76 declare void @_ZN9SomeClassC1Ev(%class.SomeClass*) #1
77
78 declare void @_Z9may_throwv() #1
79
80 declare i32 @__CxxFrameHandler3(...)
81
82 declare void @_ZN9SomeClassD1Ev(%class.SomeClass*) #1
83
84 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" }
85 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" }
86 attributes #2 = { noinline noreturn nounwind }
87 attributes #3 = { noreturn nounwind }
88 attributes #4 = { nounwind }
89
90 !llvm.ident = !{!0}
91
92 !0 = !{!"clang version 3.7.0 (trunk 226027)"}