9b6916554e5d2dbe4f83da90102fad30e4b34d1b
[oota-llvm.git] / test / CodeGen / X86 / win-mixed-ehpersonality.ll
1 ; RUN: llc -mtriple x86_64-pc-windows-msvc < %s | FileCheck %s
2
3 declare void @maybe_throw()
4
5 @_ZTIi = external constant i8*
6 @g = external global i32
7
8 declare i32 @__C_specific_handler(...)
9 declare i32 @__gxx_personality_seh0(...)
10 declare i32 @llvm.eh.typeid.for(i8*) readnone nounwind
11
12 define i32 @use_seh() personality i32 (...)* @__C_specific_handler {
13 entry:
14   invoke void @maybe_throw()
15       to label %cont unwind label %lpad
16
17 cont:
18   ret i32 0
19
20 lpad:
21   %p = catchpad [i8* bitcast (i32 (i8*, i8*)* @filt_g to i8*)]
22       to label %catch unwind label %endpad
23 catch:
24   catchret %p to label %ret1
25 endpad:
26   catchendpad unwind to caller
27
28 ret1:
29   ret i32 1
30 }
31
32 define internal i32 @filt_g(i8*, i8*) {
33   %g = load i32, i32* @g
34   ret i32 %g
35 }
36
37 ; CHECK-LABEL: use_seh:
38 ; CHECK: callq maybe_throw
39 ; CHECK: xorl %eax, %eax
40 ; CHECK: .LBB0_[[epilogue:[0-9]+]]
41 ; CHECK: retq
42 ; CHECK: # %lpad
43 ; CHECK: movl $1, %eax
44 ; CHECK: jmp .LBB0_[[epilogue]]
45
46 ; A MinGW64-ish EH style. It could happen if a binary uses both MSVC CRT and
47 ; mingw CRT and is linked with LTO.
48 define i32 @use_gcc() personality i32 (...)* @__gxx_personality_seh0 {
49 entry:
50   invoke void @maybe_throw()
51       to label %cont unwind label %lpad
52
53 cont:
54   ret i32 0
55
56 lpad:
57   %ehvals = landingpad { i8*, i32 }
58       cleanup
59       catch i8* bitcast (i8** @_ZTIi to i8*)
60   %ehsel = extractvalue { i8*, i32 } %ehvals, 1
61   %filt_g_sel = call i32 @llvm.eh.typeid.for(i8* bitcast (i32 (i8*, i8*)* @filt_g to i8*))
62   %matches = icmp eq i32 %ehsel, %filt_g_sel
63   br i1 %matches, label %ret1, label %eh.resume
64
65 ret1:
66   ret i32 1
67
68 eh.resume:
69   resume { i8*, i32 } %ehvals
70 }
71
72 ; CHECK-LABEL: use_gcc:
73 ; CHECK: callq maybe_throw
74 ; CHECK: xorl %eax, %eax
75 ;
76 ; CHECK: # %lpad
77 ; CHECK: cmpl $2, %edx
78 ; CHECK: jne
79 ;
80 ; CHECK: # %ret1
81 ; CHECK: movl $1, %eax
82 ;
83 ; CHECK: callq _Unwind_Resume