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