[SEH] Update SEH codegen tests to use the new IR
[oota-llvm.git] / test / CodeGen / WinEH / cppeh-catch-and-throw.ll
1 ; 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 ; class Obj {
6 ; public:
7 ;   ~Obj();
8 ; };
9 ;
10 ; void test(void)
11 ; {
12 ;   try {
13 ;     Obj o;
14 ;     throw 1;
15 ;   } catch (...) {
16 ;     throw;
17 ;   }
18 ; }
19
20 ; ModuleID = 'cppeh-catch-and-throw.cpp'
21 target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
22 target triple = "x86_64-pc-windows-msvc"
23
24 %rtti.TypeDescriptor2 = type { i8**, i8*, [3 x i8] }
25 %eh.CatchableType = type { i32, i32, i32, i32, i32, i32, i32 }
26 %eh.CatchableTypeArray.1 = type { i32, [1 x i32] }
27 %eh.ThrowInfo = type { i32, i32, i32, i32 }
28 %class.Obj = type { i8 }
29
30 $"\01??_R0H@8" = comdat any
31
32 $"_CT??_R0H@84" = comdat any
33
34 $_CTA1H = comdat any
35
36 $_TI1H = comdat any
37
38 @"\01??_7type_info@@6B@" = external constant i8*
39 @"\01??_R0H@8" = linkonce_odr global %rtti.TypeDescriptor2 { i8** @"\01??_7type_info@@6B@", i8* null, [3 x i8] c".H\00" }, comdat
40 @__ImageBase = external constant i8
41 @"_CT??_R0H@84" = linkonce_odr unnamed_addr constant %eh.CatchableType { i32 1, i32 trunc (i64 sub nuw nsw (i64 ptrtoint (%rtti.TypeDescriptor2* @"\01??_R0H@8" to i64), i64 ptrtoint (i8* @__ImageBase to i64)) to i32), i32 0, i32 -1, i32 0, i32 4, i32 0 }, section ".xdata", comdat
42 @_CTA1H = linkonce_odr unnamed_addr constant %eh.CatchableTypeArray.1 { i32 1, [1 x i32] [i32 trunc (i64 sub nuw nsw (i64 ptrtoint (%eh.CatchableType* @"_CT??_R0H@84" to i64), i64 ptrtoint (i8* @__ImageBase to i64)) to i32)] }, section ".xdata", comdat
43 @_TI1H = linkonce_odr unnamed_addr constant %eh.ThrowInfo { i32 0, i32 0, i32 0, i32 trunc (i64 sub nuw nsw (i64 ptrtoint (%eh.CatchableTypeArray.1* @_CTA1H to i64), i64 ptrtoint (i8* @__ImageBase to i64)) to i32) }, section ".xdata", comdat
44
45 ; This is just a minimal check to verify that main was handled by WinEHPrepare.
46 ; CHECK: define void @"\01?test@@YAXXZ"()
47 ; CHECK: entry:
48 ; CHECK:   call void (...) @llvm.localescape
49 ; CHECK:   invoke void @_CxxThrowException
50 ; CHECK: }
51
52 ; Function Attrs: uwtable
53 define void @"\01?test@@YAXXZ"() #0 personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*) {
54 entry:
55   %o = alloca %class.Obj, align 1
56   %tmp = alloca i32, align 4
57   %exn.slot = alloca i8*
58   %ehselector.slot = alloca i32
59   store i32 1, i32* %tmp
60   %0 = bitcast i32* %tmp to i8*
61   invoke void @_CxxThrowException(i8* %0, %eh.ThrowInfo* @_TI1H) #3
62           to label %unreachable unwind label %lpad
63
64 lpad:                                             ; preds = %entry
65   %1 = landingpad { i8*, i32 }
66           catch i8* null
67   %2 = extractvalue { i8*, i32 } %1, 0
68   store i8* %2, i8** %exn.slot
69   %3 = extractvalue { i8*, i32 } %1, 1
70   store i32 %3, i32* %ehselector.slot
71   call void @"\01??1Obj@@QEAA@XZ"(%class.Obj* %o) #2
72   br label %catch
73
74 catch:                                            ; preds = %lpad
75   %exn = load i8*, i8** %exn.slot
76   call void @llvm.eh.begincatch(i8* %exn, i8* null) #2
77   invoke void @_CxxThrowException(i8* null, %eh.ThrowInfo* null) #3
78           to label %unreachable unwind label %lpad1
79
80 lpad1:                                            ; preds = %catch
81   %4 = landingpad { i8*, i32 }
82           cleanup
83   %5 = extractvalue { i8*, i32 } %4, 0
84   store i8* %5, i8** %exn.slot
85   %6 = extractvalue { i8*, i32 } %4, 1
86   store i32 %6, i32* %ehselector.slot
87   call void @llvm.eh.endcatch() #2
88   br label %eh.resume
89
90 try.cont:                                         ; No predecessors!
91   ret void
92
93 eh.resume:                                        ; preds = %lpad1
94   %exn2 = load i8*, i8** %exn.slot
95   %sel = load i32, i32* %ehselector.slot
96   %lpad.val = insertvalue { i8*, i32 } undef, i8* %exn2, 0
97   %lpad.val3 = insertvalue { i8*, i32 } %lpad.val, i32 %sel, 1
98   resume { i8*, i32 } %lpad.val3
99
100 unreachable:                                      ; preds = %catch, %entry
101   unreachable
102 }
103
104 ; Verify that we inserted a stub invoke into the outlined cleanup handler.
105 ;
106 ; CHECK-LABEL: define internal void @"\01?test@@YAXXZ.cleanup"(i8*, i8*)
107 ; CHECK: entry:
108 ; CHECK:   call i8* @llvm.localrecover
109 ; CHECK:   call void @"\01??1Obj@@QEAA@XZ"
110 ; CHECK:   invoke void @llvm.donothing()
111 ; CHECK:           to label %[[SPLIT_LABEL:.+]] unwind label %[[LPAD_LABEL:.+]]
112 ;
113 ; CHECK: [[SPLIT_LABEL]]
114 ;
115 ; CHECK: [[LPAD_LABEL]]
116 ; CHECK:   landingpad { i8*, i32 }
117 ; CHECK:           cleanup
118 ; CHECK:   unreachable
119 ; CHECK: }
120
121 declare void @_CxxThrowException(i8*, %eh.ThrowInfo*)
122
123 declare i32 @__CxxFrameHandler3(...)
124
125 ; Function Attrs: nounwind
126 declare void @"\01??1Obj@@QEAA@XZ"(%class.Obj*) #1
127
128 ; Function Attrs: nounwind
129 declare void @llvm.eh.begincatch(i8* nocapture, i8* nocapture) #2
130
131 ; Function Attrs: nounwind
132 declare void @llvm.eh.endcatch() #2
133
134 attributes #0 = { uwtable "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "unsafe-fp-math"="false" "use-soft-float"="false" }
135 attributes #1 = { nounwind "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "unsafe-fp-math"="false" "use-soft-float"="false" }
136 attributes #2 = { nounwind }
137 attributes #3 = { noreturn }
138
139 !llvm.module.flags = !{!0}
140 !llvm.ident = !{!1}
141
142 !0 = !{i32 1, !"PIC Level", i32 2}
143 !1 = !{!"clang version 3.7.0 (trunk 235214) (llvm/trunk 235213)"}