cb7b053e14de9e6caaa83a676cc25caf2f4014f0
[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.1
37
38 invoke.cont:                                      ; preds = %entry
39   invoke void @may_throw(i32 2)
40           to label %try.cont.9 unwind label %lpad
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   %p1 = catchpad [%rtti.TypeDescriptor2* @"\01??_R0H@8", i32 0, i8* null]
50       to label %catch unwind label %end.inner.catch
51
52 catch:                                            ; preds = %lpad.1
53   invoke void @may_throw(i32 3)
54           to label %invoke.cont.3 unwind label %end.inner.catch
55
56 invoke.cont.3:                                    ; preds = %catch
57   catchret %p1 to label %try.cont.9
58
59
60 end.inner.catch:
61   catchendpad unwind label %lpad.1
62
63 lpad.1:                                           ; preds = %invoke.cont
64   %p2 = catchpad [%rtti.TypeDescriptor2* @"\01??_R0H@8", i32 0, i8* null]
65       to label %catch.7 unwind label %eh.resume
66
67 catch.7:
68   invoke void @may_throw(i32 4)
69           to label %invoke.cont.10 unwind label %eh.resume
70
71 invoke.cont.10:
72   catchret %p2 to label %try.cont.9
73
74 eh.resume:                                        ; preds = %catch.dispatch.4
75   catchendpad unwind to caller
76 }
77
78 ; CHECK-LABEL: _f:
79 ; CHECK: movl $-1, [[state:[-0-9]+]](%ebp)
80 ; CHECK: movl $___ehhandler$f, {{.*}}
81 ;
82 ; CHECK: movl $0, [[state]](%ebp)
83 ; CHECK: movl $1, (%esp)
84 ; CHECK: calll _may_throw
85 ;
86 ; CHECK: movl $1, [[state]](%ebp)
87 ; CHECK: movl $2, (%esp)
88 ; CHECK: calll _may_throw
89 ;
90 ; CHECK: movl $2, [[state]](%ebp)
91 ; CHECK: movl $3, (%esp)
92 ; CHECK: calll _may_throw
93 ;
94 ; CHECK: movl $3, [[state]](%ebp)
95 ; CHECK: movl $4, (%esp)
96 ; CHECK: calll _may_throw
97
98 ; CHECK: .safeseh ___ehhandler$f