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