1 ; RUN: llc -mtriple arm-unknown-linux-gnueabi -filetype asm -o - %s | FileCheck %s --check-prefix=CHECK-FP
2 ; RUN: llc -mtriple arm-unknown-linux-gnueabi -filetype asm -o - %s -frame-pointer=all | FileCheck %s --check-prefix=CHECK-FP-ELIM
3 ; RUN: llc -mtriple thumb-unknown-linux-gnueabi -filetype asm -o - %s | FileCheck %s --check-prefix=CHECK-THUMB-FP
4 ; RUN: llc -mtriple thumb-unknown-linux-gnueabi -filetype asm -o - %s -frame-pointer=all | FileCheck %s --check-prefix=CHECK-THUMB-FP-ELIM
6 ; Tests that the initial space allocated to the varargs on the stack is
7 ; taken into account in the .cfi_ directives.
9 ; Generated from the C program:
12 ; extern int foo(int);
14 ; int sum(int count, ...) {
16 ; va_start(vl, count);
18 ; for (int i = 0; i < count; i++) {
19 ; sum += foo(va_arg(vl, int));
25 !llvm.module.flags = !{!9, !10}
28 !0 = distinct !DICompileUnit(language: DW_LANG_C99, producer: "clang version 3.5 ", isOptimized: false, emissionKind: FullDebug, file: !1, enums: !2, retainedTypes: !2, globals: !2, imports: !2)
29 !1 = !DIFile(filename: "var.c", directory: "/tmp")
31 !4 = distinct !DISubprogram(name: "sum", line: 5, isLocal: false, isDefinition: true, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: false, unit: !0, scopeLine: 5, file: !1, scope: !5, type: !6, retainedNodes: !2)
32 !5 = !DIFile(filename: "var.c", directory: "/tmp")
33 !6 = !DISubroutineType(types: !7)
35 !8 = !DIBasicType(tag: DW_TAG_base_type, name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
36 !9 = !{i32 2, !"Dwarf Version", i32 4}
37 !10 = !{i32 1, !"Debug Info Version", i32 3}
38 !11 = !{!"clang version 3.5 "}
39 !12 = !DILocalVariable(name: "count", line: 5, arg: 1, scope: !4, file: !5, type: !8)
40 !13 = !DILocation(line: 5, scope: !4)
41 !14 = !DILocalVariable(name: "vl", line: 6, scope: !4, file: !5, type: !15)
42 !15 = !DIDerivedType(tag: DW_TAG_typedef, name: "va_list", line: 30, file: !16, baseType: !17)
43 !16 = !DIFile(filename: "/linux-x86_64-high/gcc_4.7.2/dbg/llvm/bin/../lib/clang/3.5/include/stdarg.h", directory: "/tmp")
44 !17 = !DIDerivedType(tag: DW_TAG_typedef, name: "__builtin_va_list", line: 6, file: !1, baseType: !18)
45 !18 = !DICompositeType(tag: DW_TAG_structure_type, name: "__va_list", line: 6, size: 32, align: 32, file: !1, elements: !19)
47 !20 = !DIDerivedType(tag: DW_TAG_member, name: "__ap", line: 6, size: 32, align: 32, file: !1, scope: !18, baseType: !21)
48 !21 = !DIDerivedType(tag: DW_TAG_pointer_type, size: 32, align: 32, baseType: null)
49 !22 = !DILocation(line: 6, scope: !4)
50 !23 = !DILocation(line: 7, scope: !4)
51 !24 = !DILocalVariable(name: "sum", line: 8, scope: !4, file: !5, type: !8)
52 !25 = !DILocation(line: 8, scope: !4)
53 !26 = !DILocalVariable(name: "i", line: 9, scope: !27, file: !5, type: !8)
54 !27 = distinct !DILexicalBlock(line: 9, column: 0, file: !1, scope: !4)
55 !28 = !DILocation(line: 9, scope: !27)
56 !29 = !DILocation(line: 10, scope: !30)
57 !30 = distinct !DILexicalBlock(line: 9, column: 0, file: !1, scope: !27)
58 !31 = !DILocation(line: 11, scope: !30)
59 !32 = !DILocation(line: 12, scope: !4)
60 !33 = !DILocation(line: 13, scope: !4)
63 ; CHECK-FP: .cfi_startproc
64 ; CHECK-FP: sub sp, sp, #12
65 ; CHECK-FP: .cfi_def_cfa_offset 12
66 ; CHECK-FP: push {r4, lr}
67 ; CHECK-FP: .cfi_def_cfa_offset 20
68 ; CHECK-FP: .cfi_offset lr, -16
69 ; CHECK-FP: .cfi_offset r4, -20
70 ; CHECK-FP: sub sp, sp, #4
71 ; CHECK-FP: .cfi_def_cfa_offset 24
73 ; CHECK-FP-ELIM-LABEL: sum
74 ; CHECK-FP-ELIM: .cfi_startproc
75 ; CHECK-FP-ELIM: sub sp, sp, #12
76 ; CHECK-FP-ELIM: .cfi_def_cfa_offset 12
77 ; CHECK-FP-ELIM: push {r4, r10, r11, lr}
78 ; CHECK-FP-ELIM: .cfi_def_cfa_offset 28
79 ; CHECK-FP-ELIM: .cfi_offset lr, -16
80 ; CHECK-FP-ELIM: .cfi_offset r11, -20
81 ; CHECK-FP-ELIM: .cfi_offset r10, -24
82 ; CHECK-FP-ELIM: .cfi_offset r4, -28
83 ; CHECK-FP-ELIM: add r11, sp, #8
84 ; CHECK-FP-ELIM: .cfi_def_cfa r11, 20
86 ; CHECK-THUMB-FP-LABEL: sum
87 ; CHECK-THUMB-FP: .cfi_startproc
88 ; CHECK-THUMB-FP: sub sp, #12
89 ; CHECK-THUMB-FP: .cfi_def_cfa_offset 12
90 ; CHECK-THUMB-FP: push {r4, lr}
91 ; CHECK-THUMB-FP: .cfi_def_cfa_offset 20
92 ; CHECK-THUMB-FP: .cfi_offset lr, -16
93 ; CHECK-THUMB-FP: .cfi_offset r4, -20
94 ; CHECK-THUMB-FP: sub sp, #4
95 ; CHECK-THUMB-FP: .cfi_def_cfa_offset 24
97 ; CHECK-THUMB-FP-ELIM-LABEL: sum
98 ; CHECK-THUMB-FP-ELIM: .cfi_startproc
99 ; CHECK-THUMB-FP-ELIM: sub sp, #12
100 ; CHECK-THUMB-FP-ELIM: .cfi_def_cfa_offset 12
101 ; CHECK-THUMB-FP-ELIM: push {r4, r6, r7, lr}
102 ; CHECK-THUMB-FP-ELIM: .cfi_def_cfa_offset 28
103 ; CHECK-THUMB-FP-ELIM: .cfi_offset lr, -16
104 ; CHECK-THUMB-FP-ELIM: .cfi_offset r7, -20
105 ; CHECK-THUMB-FP-ELIM: .cfi_offset r6, -24
106 ; CHECK-THUMB-FP-ELIM: .cfi_offset r4, -28
107 ; CHECK-THUMB-FP-ELIM: add r7, sp, #8
108 ; CHECK-THUMB-FP-ELIM: .cfi_def_cfa r7, 20
110 define i32 @sum(i32 %count, ...) !dbg !4 {
112 %vl = alloca ptr, align 4
113 call void @llvm.va_start(ptr %vl)
114 %cmp4 = icmp sgt i32 %count, 0
115 br i1 %cmp4, label %for.body, label %for.end
117 for.body: ; preds = %entry, %for.body
118 %i.05 = phi i32 [ %inc, %for.body ], [ 0, %entry ]
119 %ap.cur = load ptr, ptr %vl, align 4
120 %ap.next = getelementptr i8, ptr %ap.cur, i32 4
121 store ptr %ap.next, ptr %vl, align 4
122 %0 = load i32, ptr %ap.cur, align 4
123 %call = call i32 @foo(i32 %0) #1
124 %inc = add nsw i32 %i.05, 1
125 %exitcond = icmp eq i32 %inc, %count
126 br i1 %exitcond, label %for.end, label %for.body
128 for.end: ; preds = %for.body, %entry
129 call void @llvm.va_end(ptr %vl)
133 declare void @llvm.va_start(ptr) nounwind
135 declare i32 @foo(i32)
137 declare void @llvm.va_end(ptr) nounwind