Home | History | Annotate | Download | only in X86
      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   %cs = catchswitch within none [label %catch] unwind to caller
     22 catch:
     23   %p = catchpad within %cs [i8* bitcast (i32 (i8*, i8*)* @filt_g to i8*)]
     24   catchret from %p to label %ret1
     25 
     26 ret1:
     27   ret i32 1
     28 }
     29 
     30 define internal i32 @filt_g(i8*, i8*) {
     31   %g = load i32, i32* @g
     32   ret i32 %g
     33 }
     34 
     35 ; CHECK-LABEL: use_seh:
     36 ; CHECK: callq maybe_throw
     37 ; CHECK: xorl %eax, %eax
     38 ; CHECK: .LBB0_[[epilogue:[0-9]+]]
     39 ; CHECK: retq
     40 ; CHECK: # %catch{{$}}
     41 ; CHECK: movl $1, %eax
     42 ; CHECK: jmp .LBB0_[[epilogue]]
     43 
     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 {
     47 entry:
     48   invoke void @maybe_throw()
     49       to label %cont unwind label %lpad
     50 
     51 cont:
     52   ret i32 0
     53 
     54 lpad:
     55   %ehvals = landingpad { i8*, i32 }
     56       cleanup
     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
     62 
     63 ret1:
     64   ret i32 1
     65 
     66 eh.resume:
     67   resume { i8*, i32 } %ehvals
     68 }
     69 
     70 ; CHECK-LABEL: use_gcc:
     71 ; CHECK: callq maybe_throw
     72 ; CHECK: xorl %eax, %eax
     73 ;
     74 ; CHECK: # %lpad
     75 ; CHECK: cmpl $2, %edx
     76 ; CHECK: jne
     77 ;
     78 ; CHECK: # %ret1
     79 ; CHECK: movl $1, %eax
     80 ;
     81 ; CHECK: callq _Unwind_Resume
     82