[WinEH] Setup RBP correctly in Win64 funclet prologues
[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 ; CHECK: leaq    48(%rdx), %rbp
55 ; CHECK-NOT: .seh_setframe
56
57 ; Prologue is done, emit the .seh_endprologue directive.
58 ; CHECK: .seh_endprologue
59
60 ; Make sure there is a nop after a call if the call precedes the epilogue.
61 ; CHECK: callq g
62 ; CHECK-NEXT: nop
63
64 ; Don't emit a reference to the LSDA.
65 ; CHECK: .seh_handlerdata
66 ; CHECK-NOT:  .long   ("$cppxdata$?f@@YAXXZ")@IMGREL
67 ; CHECK-NEXT: .text
68 ; CHECK: .seh_endproc
69
70 ; CHECK: "?catch$[[catch:[0-9]+]]@?0??f@@YAXXZ@4HA":
71 ; CHECK: .seh_proc "?catch$[[catch]]@?0??f@@YAXXZ@4HA"
72 ; CHECK-NEXT: .seh_handler __CxxFrameHandler3, @unwind, @except
73 ; CHECK: LBB0_[[catch]]: # %catch{{$}}
74
75 ; Emit CFI for pushing RBP.
76 ; CHECK: movq    %rdx, 16(%rsp)
77 ; CHECK: pushq   %rbp
78 ; CHECK: .seh_pushreg 5
79
80 ; Emit CFI for allocating from the stack pointer.
81 ; CHECK: subq    $32, %rsp
82 ; CHECK: .seh_stackalloc 32
83
84 ; CHECK: leaq    48(%rdx), %rbp
85 ; CHECK-NOT: .seh_setframe
86
87 ; Prologue is done, emit the .seh_endprologue directive.
88 ; CHECK: .seh_endprologue
89
90 ; Make sure there is at least one instruction after a call before the epilogue.
91 ; CHECK: callq g
92 ; CHECK-NEXT: leaq    .LBB0_{{[0-9]+}}(%rip), %rax
93
94 ; Emit a reference to the LSDA.
95 ; CHECK: .seh_handlerdata
96 ; CHECK-NEXT:  .long   ("$cppxdata$?f@@YAXXZ")@IMGREL
97 ; CHECK-NEXT: .text
98 ; CHECK: .seh_endproc