1 ; RUN: llc -mtriple x86_64-pc-windows-msvc < %s | FileCheck %s
3 declare void @maybe_throw()
5 @_ZTIi = external constant i8*
6 @g = external global i32
8 declare i32 @__C_specific_handler(...)
9 declare i32 @__gxx_personality_seh0(...)
10 declare i32 @llvm.eh.typeid.for(i8*) readnone nounwind
12 define i32 @use_seh() personality i32 (...)* @__C_specific_handler {
14 invoke void @maybe_throw()
15 to label %cont unwind label %lpad
21 %cs = catchswitch within none [label %catch] unwind to caller
23 %p = catchpad within %cs [i8* bitcast (i32 (i8*, i8*)* @filt_g to i8*)]
24 catchret from %p to label %ret1
30 define internal i32 @filt_g(i8*, i8*) {
31 %g = load i32, i32* @g
35 ; CHECK-LABEL: use_seh:
36 ; CHECK: callq maybe_throw
37 ; CHECK: xorl %eax, %eax
38 ; CHECK: .LBB0_[[epilogue:[0-9]+]]
40 ; CHECK: # %catch{{$}}
41 ; CHECK: movl $1, %eax
42 ; CHECK: jmp .LBB0_[[epilogue]]
44 ; A MinGW64-ish EH style. It could happen if a binary uses both MSVC CRT and
45 ; mingw CRT and is linked with LTO.
46 define i32 @use_gcc() personality i32 (...)* @__gxx_personality_seh0 {
48 invoke void @maybe_throw()
49 to label %cont unwind label %lpad
55 %ehvals = landingpad { i8*, i32 }
57 catch i8* bitcast (i8** @_ZTIi to i8*)
58 %ehsel = extractvalue { i8*, i32 } %ehvals, 1
59 %filt_g_sel = call i32 @llvm.eh.typeid.for(i8* bitcast (i32 (i8*, i8*)* @filt_g to i8*))
60 %matches = icmp eq i32 %ehsel, %filt_g_sel
61 br i1 %matches, label %ret1, label %eh.resume
67 resume { i8*, i32 } %ehvals
70 ; CHECK-LABEL: use_gcc:
71 ; CHECK: callq maybe_throw
72 ; CHECK: xorl %eax, %eax
75 ; CHECK: cmpl $2, %edx
79 ; CHECK: movl $1, %eax
81 ; CHECK: callq _Unwind_Resume