4463485f2093fc4eb5e9dc825dde52579b9e90c8
[oota-llvm.git] / test / CodeGen / X86 / seh-catch-all.ll
1 ; RUN: llc -mtriple=x86_64-windows-msvc < %s | FileCheck %s
2
3 @str = linkonce_odr unnamed_addr constant [27 x i8] c"GetExceptionCode(): 0x%lx\0A\00", align 1
4
5 declare i32 @llvm.eh.exceptioncode(token)
6 declare i32 @__C_specific_handler(...)
7 declare void @crash()
8 declare i32 @printf(i8* nocapture readonly, ...) nounwind
9
10 define i32 @main() personality i8* bitcast (i32 (...)* @__C_specific_handler to i8*) {
11 entry:
12   invoke void @crash()
13           to label %__try.cont unwind label %lpad
14
15 __try.cont:
16   ret i32 0
17
18 lpad:
19   %cs1 = catchswitch within none [label %catchall] unwind to caller
20
21 catchall:
22   %p = catchpad within %cs1 [i8* null, i32 64, i8* null]
23   %code = call i32 @llvm.eh.exceptioncode(token %p)
24   call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @str, i64 0, i64 0), i32 %code)
25   catchret from %p to label %__try.cont
26 }
27
28 ; Check that we can get the exception code from eax to the printf.
29
30 ; CHECK-LABEL: main:
31 ; CHECK: callq crash
32 ; CHECK: retq
33 ; CHECK: .LBB0_2: # %catchall
34 ; CHECK: leaq str(%rip), %rcx
35 ; CHECK: movl %eax, %edx
36 ; CHECK: callq printf
37
38 ; CHECK: .seh_handlerdata
39 ; CHECK-NEXT: .long (.Llsda_end0-.Llsda_begin0)/16
40 ; CHECK-NEXT: .Llsda_begin0:
41 ; CHECK-NEXT: .long .Ltmp{{[0-9]+}}@IMGREL
42 ; CHECK-NEXT: .long .Ltmp{{[0-9]+}}@IMGREL+1
43 ; CHECK-NEXT: .long 1
44 ; CHECK-NEXT: .long .LBB0_2@IMGREL
45 ; CHECK-NEXT: .Llsda_end0: