Move the personality function from LandingPadInst to Function
[oota-llvm.git] / test / CodeGen / X86 / win32-eh-states.ll
1 ; RUN: llc -mtriple=i686-pc-windows-msvc < %s | FileCheck %s
2
3 ; Based on this source:
4 ; extern "C" void may_throw(int);
5 ; void f() {
6 ;   try {
7 ;     may_throw(1);
8 ;     try {
9 ;       may_throw(2);
10 ;     } catch (int) {
11 ;       may_throw(3);
12 ;     }
13 ;   } catch (int) {
14 ;     may_throw(4);
15 ;   }
16 ; }
17
18 %rtti.TypeDescriptor2 = type { i8**, i8*, [3 x i8] }
19 %eh.CatchHandlerType = type { i32, i8* }
20
21 declare void @may_throw(i32)
22 declare i32 @__CxxFrameHandler3(...)
23 declare void @llvm.eh.begincatch(i8*, i8*)
24 declare void @llvm.eh.endcatch()
25 declare i32 @llvm.eh.typeid.for(i8*)
26
27 $"\01??_R0H@8" = comdat any
28
29 @"\01??_7type_info@@6B@" = external constant i8*
30 @"\01??_R0H@8" = linkonce_odr global %rtti.TypeDescriptor2 { i8** @"\01??_7type_info@@6B@", i8* null, [3 x i8] c".H\00" }, comdat
31 @llvm.eh.handlertype.H.0 = private unnamed_addr constant %eh.CatchHandlerType { i32 0, i8* bitcast (%rtti.TypeDescriptor2* @"\01??_R0H@8" to i8*) }, section "llvm.metadata"
32
33 define void @f() #0 personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*) {
34 entry:
35   invoke void @may_throw(i32 1)
36           to label %invoke.cont unwind label %lpad
37
38 invoke.cont:                                      ; preds = %entry
39   invoke void @may_throw(i32 2)
40           to label %try.cont.9 unwind label %lpad.1
41
42 try.cont.9:                                       ; preds = %invoke.cont.3, %invoke.cont, %catch.7
43   ; FIXME: Something about our CFG breaks TailDuplication. This empy asm blocks
44   ; it so we can focus on testing the state numbering.
45   call void asm sideeffect "", "~{dirflag},~{fpsr},~{flags}"()
46   ret void
47
48 lpad:                                             ; preds = %catch, %entry
49   %0 = landingpad { i8*, i32 }
50           catch %eh.CatchHandlerType* @llvm.eh.handlertype.H.0
51   %1 = extractvalue { i8*, i32 } %0, 0
52   %2 = extractvalue { i8*, i32 } %0, 1
53   br label %catch.dispatch.4
54
55 lpad.1:                                           ; preds = %invoke.cont
56   %3 = landingpad { i8*, i32 }
57           catch i8* bitcast (%eh.CatchHandlerType* @llvm.eh.handlertype.H.0 to i8*)
58   %4 = extractvalue { i8*, i32 } %3, 0
59   %5 = extractvalue { i8*, i32 } %3, 1
60   %6 = tail call i32 @llvm.eh.typeid.for(i8* bitcast (%eh.CatchHandlerType* @llvm.eh.handlertype.H.0 to i8*)) #3
61   %matches = icmp eq i32 %5, %6
62   br i1 %matches, label %catch, label %catch.dispatch.4
63
64 catch.dispatch.4:                                 ; preds = %lpad.1, %lpad
65   %exn.slot.0 = phi i8* [ %4, %lpad.1 ], [ %1, %lpad ]
66   %ehselector.slot.0 = phi i32 [ %5, %lpad.1 ], [ %2, %lpad ]
67   %.pre = tail call i32 @llvm.eh.typeid.for(i8* bitcast (%eh.CatchHandlerType* @llvm.eh.handlertype.H.0 to i8*)) #3
68   %matches6 = icmp eq i32 %ehselector.slot.0, %.pre
69   br i1 %matches6, label %catch.7, label %eh.resume
70
71 catch.7:                                          ; preds = %catch.dispatch.4
72   tail call void @llvm.eh.begincatch(i8* %exn.slot.0, i8* null) #3
73   tail call void @may_throw(i32 4)
74   tail call void @llvm.eh.endcatch() #3
75   br label %try.cont.9
76
77 catch:                                            ; preds = %lpad.1
78   tail call void @llvm.eh.begincatch(i8* %4, i8* null) #3
79   invoke void @may_throw(i32 3)
80           to label %invoke.cont.3 unwind label %lpad
81
82 invoke.cont.3:                                    ; preds = %catch
83   tail call void @llvm.eh.endcatch() #3
84   br label %try.cont.9
85
86 eh.resume:                                        ; preds = %catch.dispatch.4
87   %lpad.val = insertvalue { i8*, i32 } undef, i8* %exn.slot.0, 0
88   %lpad.val.12 = insertvalue { i8*, i32 } %lpad.val, i32 %ehselector.slot.0, 1
89   resume { i8*, i32 } %lpad.val.12
90 }
91
92 ; CHECK-LABEL: _f:
93 ; CHECK: movl $-1, [[state:[-0-9]+]](%ebp)
94 ; CHECK: movl $___ehhandler$f, {{.*}}
95 ;
96 ; CHECK: movl $0, [[state]](%ebp)
97 ; CHECK: movl $1, (%esp)
98 ; CHECK: calll _may_throw
99 ;
100 ; CHECK: movl $1, [[state]](%ebp)
101 ; CHECK: movl $2, (%esp)
102 ; CHECK: calll _may_throw
103
104 ; CHECK-LABEL: _f.catch:
105 ; CHECK: movl $4, Lf$frame_escape_{{[0-9]+.*}}
106 ; CHECK: movl $4, (%esp)
107 ; CHECK: calll _may_throw
108
109 ; CHECK-LABEL: _f.catch.1:
110 ; CHECK: movl $3, Lf$frame_escape_{{[0-9]+.*}}
111 ; CHECK: movl $3, (%esp)
112 ; CHECK: calll _may_throw
113
114 ; CHECK: .safeseh ___ehhandler$f