1 ; RUN: llc --force-dwarf-frame-section %s -o - | FileCheck %s
2 ; RUN: llc --filetype=obj %s -o - | llvm-readelf --unwind - | FileCheck %s --check-prefix=UNWIND
3 target datalayout = "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64"
4 target triple = "thumbv8.1m.main-arm-none-eabi"
10 ; __builtin_va_list ap;
11 ; __builtin_va_start(ap, n);
13 ; for (int i = 0; i < n; ++i)
14 ; s += g(__builtin_va_arg(ap, int));
15 ; __builtin_va_end(ap);
19 %"struct.std::__va_list" = type { ptr }
21 define hidden i32 @_Z1fiz(i32 %n, ...) local_unnamed_addr #0 {
23 %ap = alloca %"struct.std::__va_list", align 4
24 call void @llvm.va_start(ptr nonnull %ap)
25 %cmp7 = icmp sgt i32 %n, 0
26 br i1 %cmp7, label %for.body.lr.ph, label %for.cond.cleanup
28 for.body.lr.ph: ; preds = %entry
31 for.cond.cleanup: ; preds = %for.body, %entry
32 %s.0.lcssa = phi i32 [ 0, %entry ], [ %add, %for.body ]
33 call void @llvm.va_end(ptr nonnull %ap)
36 for.body: ; preds = %for.body.lr.ph, %for.body
37 %i.09 = phi i32 [ 0, %for.body.lr.ph ], [ %inc, %for.body ]
38 %s.08 = phi i32 [ 0, %for.body.lr.ph ], [ %add, %for.body ]
39 %argp.cur = load ptr, ptr %ap, align 4
40 %argp.next = getelementptr inbounds i8, ptr %argp.cur, i32 4
41 store ptr %argp.next, ptr %ap, align 4
42 %0 = load i32, ptr %argp.cur, align 4
43 %call = call i32 @_Z1gi(i32 %0)
44 %add = add nsw i32 %call, %s.08
45 %inc = add nuw nsw i32 %i.09, 1
46 %exitcond.not = icmp eq i32 %inc, %n
47 br i1 %exitcond.not, label %for.cond.cleanup, label %for.body
50 ; CHECK-LABEL: _Z1fiz:
51 ; CHECK: pac r12, lr, sp
52 ; CHECK-NEXT: .pad #12
53 ; CHECK-NEXT: sub sp, #12
54 ; CHECK-NEXT: .cfi_def_cfa_offset 12
55 ; CHECK-NEXT: .save {r4, r5, r7, lr}
56 ; CHECK-NEXT: push {r4, r5, r7, lr}
57 ; CHECK-NEXT: .cfi_def_cfa_offset 28
58 ; CHECK-NEXT: .cfi_offset lr, -16
59 ; CHECK-NEXT: .cfi_offset r7, -20
60 ; CHECK-NEXT: .cfi_offset r5, -24
61 ; CHECK-NEXT: .cfi_offset r4, -28
62 ; CHECK-NEXT: .save {ra_auth_code}
63 ; CHECK-NEXT: str r12, [sp, #-4]!
64 ; CHECK-NEXT: .cfi_def_cfa_offset 32
65 ; CHECK-NEXT: .cfi_offset ra_auth_code, -32
67 ; CHECK-NEXT: sub sp, #8
68 ; CHECK-NEXT: .cfi_def_cfa_offset 40
70 ; CHECK: add r[[N:[0-9]*]], sp, #28
71 ; CHECK: stm r[[N]]!, {r1, r2, r3}
74 ; CHECK-NEXT: ldr r12, [sp], #4
75 ; CHECK-NEXT: pop.w {r4, r5, r7, lr}
76 ; CHECK-NEXT: add sp, #12
77 ; CHECK-NEXT: aut r12, lr, sp
80 declare void @llvm.va_start(ptr) #1
81 declare void @llvm.va_end(ptr) #1
83 declare dso_local i32 @_Z1gi(i32) local_unnamed_addr
85 attributes #0 = { optsize }
86 attributes #1 = { nounwind }
88 !llvm.module.flags = !{!0, !1, !2}
90 !0 = !{i32 8, !"branch-target-enforcement", i32 0}
91 !1 = !{i32 8, !"sign-return-address", i32 1}
92 !2 = !{i32 8, !"sign-return-address-all", i32 0}
94 ; UNWIND-LABEL: FunctionAddress
95 ; UNWIND: 0x01 ; vsp = vsp + 8
96 ; UNWIND-NEXT: 0xB4 ; pop ra_auth_code
97 ; UNWIND-NEXT: 0x84 0x0B ; pop {r4, r5, r7, lr}
98 ; UNWIND-NEXT: 0x02 ; vsp = vsp + 12