[WinEH] Add an EH registration and state insertion pass for 32-bit x86
[oota-llvm.git] / test / CodeGen / X86 / win32-eh.ll
1 ; RUN: llc -mtriple=i686-pc-windows-msvc < %s | FileCheck %s
2
3 declare void @may_throw_or_crash()
4 declare i32 @_except_handler3(...)
5 declare i32 @_except_handler4(...)
6 declare i32 @__CxxFrameHandler3(...)
7 declare void @llvm.eh.begincatch(i8*, i8*)
8 declare void @llvm.eh.endcatch()
9
10 define void @use_except_handler3() {
11   invoke void @may_throw_or_crash()
12       to label %cont unwind label %catchall
13 cont:
14   ret void
15 catchall:
16   landingpad { i8*, i32 } personality i32 (...)* @_except_handler3
17       catch i8* null
18   br label %cont
19 }
20
21 ; CHECK-LABEL: _use_except_handler3:
22 ; CHECK: subl ${{[0-9]+}}, %esp
23 ; CHECK: movl %fs:0, %[[next:[^ ,]*]]
24 ; CHECK: movl %[[next]], (%esp)
25 ; CHECK: leal (%esp), %[[node:[^ ,]*]]
26 ; CHECK: movl %[[node]], %fs:0
27 ; CHECK: calll _may_throw_or_crash
28 ; CHECK: movl (%esp), %[[next:[^ ,]*]]
29 ; CHECK: movl %[[next]], %fs:0
30 ; CHECK: retl
31
32 define void @use_except_handler4() {
33   invoke void @may_throw_or_crash()
34       to label %cont unwind label %catchall
35 cont:
36   ret void
37 catchall:
38   landingpad { i8*, i32 } personality i32 (...)* @_except_handler4
39       catch i8* null
40   br label %cont
41 }
42
43 ; CHECK-LABEL: _use_except_handler4:
44 ; CHECK: subl ${{[0-9]+}}, %esp
45 ; CHECK: leal 8(%esp), %[[node:[^ ,]*]]
46 ; CHECK: movl %fs:0, %[[next:[^ ,]*]]
47 ; CHECK: movl %[[next]], 8(%esp)
48 ; CHECK: movl %[[node]], %fs:0
49 ; CHECK: calll _may_throw_or_crash
50 ; CHECK: movl 8(%esp), %[[next:[^ ,]*]]
51 ; CHECK: movl %[[next]], %fs:0
52 ; CHECK: retl
53
54 define void @use_CxxFrameHandler3() {
55   invoke void @may_throw_or_crash()
56       to label %cont unwind label %catchall
57 cont:
58   ret void
59 catchall:
60   %ehvals = landingpad { i8*, i32 } personality i32 (...)* @__CxxFrameHandler3
61       catch i8* null
62   %ehptr = extractvalue { i8*, i32 } %ehvals, 0
63   call void @llvm.eh.begincatch(i8* %ehptr, i8* null)
64   call void @llvm.eh.endcatch()
65   br label %cont
66 }
67
68 ; CHECK-LABEL: _use_CxxFrameHandler3:
69 ; CHECK: subl ${{[0-9]+}}, %esp
70 ; CHECK: leal 4(%esp), %[[node:[^ ,]*]]
71 ; CHECK: movl %fs:0, %[[next:[^ ,]*]]
72 ; CHECK: movl %[[next]], 4(%esp)
73 ; CHECK: movl %[[node]], %fs:0
74 ; CHECK: calll _may_throw_or_crash
75 ; CHECK: movl 4(%esp), %[[next:[^ ,]*]]
76 ; CHECK: movl %[[next]], %fs:0
77 ; CHECK: retl