[WinEH] Ensure that funclets obey the x64 ABI
[oota-llvm.git] / test / CodeGen / X86 / win-funclet-cfi.ll
1 ; RUN: llc -mtriple=x86_64-windows-msvc < %s | FileCheck %s
2
3 target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
4 target triple = "x86_64-pc-windows-msvc"
5
6 define void @"\01?f@@YAXXZ"(i1 %B) personality i32 (...)* @__CxxFrameHandler3 {
7 entry:
8   invoke void @g()
9           to label %unreachable unwind label %cleanupblock
10
11 cleanupblock:
12   %cleanp = cleanuppad []
13   call void @g()
14   cleanupret %cleanp unwind label %catch.dispatch
15
16 catch.dispatch:
17   %cp = catchpad [i8* null, i32 64, i8* null]
18           to label %catch unwind label %catchendblock
19
20 catch:
21   call void @g()
22   catchret %cp to label %try.cont
23
24 try.cont:
25   ret void
26
27 catchendblock:
28   catchendpad unwind to caller
29
30 unreachable:
31   unreachable
32 }
33
34
35 declare void @g()
36
37 declare i32 @__CxxFrameHandler3(...)
38
39 ; Destructors need CFI but they shouldn't use the .seh_handler directive.
40 ; CHECK: "?dtor$[[cleanup:[0-9]+]]@?0??f@@YAXXZ@4HA":
41 ; CHECK: .seh_proc "?dtor$[[cleanup]]@?0??f@@YAXXZ@4HA"
42 ; CHECK-NOT: .seh_handler __CxxFrameHandler3
43 ; CHECK: LBB0_[[cleanup]]: # %cleanupblock{{$}}
44
45 ; Emit CFI for pushing RBP.
46 ; CHECK: movq    %rdx, 16(%rsp)
47 ; CHECK: pushq   %rbp
48 ; CHECK: .seh_pushreg 5
49
50 ; Emit CFI for allocating from the stack pointer.
51 ; CHECK: subq    $32, %rsp
52 ; CHECK: .seh_stackalloc 32
53
54 ; FIXME: This looks wrong...
55 ; CHECK: leaq    32(%rsp), %rbp
56 ; CHECK: .seh_setframe 5, 32
57
58 ; Prologue is done, emit the .seh_endprologue directive.
59 ; CHECK: .seh_endprologue
60
61 ; Make sure there is a nop after a call if the call precedes the epilogue.
62 ; CHECK: callq g
63 ; CHECK-NEXT: nop
64
65 ; Don't emit a reference to the LSDA.
66 ; CHECK: .seh_handlerdata
67 ; CHECK-NOT:  .long   ("$cppxdata$?f@@YAXXZ")@IMGREL
68 ; CHECK-NEXT: .text
69 ; CHECK: .seh_endproc
70
71 ; CHECK: "?catch$[[catch:[0-9]+]]@?0??f@@YAXXZ@4HA":
72 ; CHECK: .seh_proc "?catch$[[catch]]@?0??f@@YAXXZ@4HA"
73 ; CHECK-NEXT: .seh_handler __CxxFrameHandler3, @unwind, @except
74 ; CHECK: LBB0_[[catch]]: # %catch{{$}}
75
76 ; Emit CFI for pushing RBP.
77 ; CHECK: movq    %rdx, 16(%rsp)
78 ; CHECK: pushq   %rbp
79 ; CHECK: .seh_pushreg 5
80
81 ; Emit CFI for allocating from the stack pointer.
82 ; CHECK: subq    $32, %rsp
83 ; CHECK: .seh_stackalloc 32
84
85 ; FIXME: This looks wrong...
86 ; CHECK: leaq    32(%rsp), %rbp
87 ; CHECK: .seh_setframe 5, 32
88
89 ; Prologue is done, emit the .seh_endprologue directive.
90 ; CHECK: .seh_endprologue
91
92 ; Make sure there is at least one instruction after a call before the epilogue.
93 ; CHECK: callq g
94 ; CHECK-NEXT: leaq    .LBB0_{{[0-9]+}}(%rip), %rax
95
96 ; Emit a reference to the LSDA.
97 ; CHECK: .seh_handlerdata
98 ; CHECK-NEXT:  .long   ("$cppxdata$?f@@YAXXZ")@IMGREL
99 ; CHECK-NEXT: .text
100 ; CHECK: .seh_endproc