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