blob: 893ca93a994423c821e08f9943669cd377dfc8d1 [file] [log] [blame]
Matthias Braun372ee592017-04-19 23:10:43 +00001; RUN: llc -o - %s | FileCheck %s
Reid Kleckner3a363ff2017-05-09 16:02:20 +00002; RUN: llc -filetype=obj -o - %s | llvm-dwarfdump - | FileCheck %s --check-prefix=DWARF
Matthias Braun372ee592017-04-19 23:10:43 +00003; This test checks that parameters on the stack pointer are correctly
4; referenced by debug info.
5target triple = "x86_64--"
6
7@glob = external global i64
8@ptr = external global i32*
9%struct.s = type { i32, i32, i32, i32, i32 }
10
Reid Kleckner3a363ff2017-05-09 16:02:20 +000011; Simple case: no FP, use offset from RSP.
12
Matthias Braun372ee592017-04-19 23:10:43 +000013; CHECK-LABEL: f0:
Reid Kleckner3a363ff2017-05-09 16:02:20 +000014; CHECK-NOT: pushq
15; CHECK: movl $42, %eax
16; CHECK: retq
Matthias Braun372ee592017-04-19 23:10:43 +000017define i32 @f0(%struct.s* byval align 8 %input) !dbg !8 {
18 call void @llvm.dbg.declare(metadata %struct.s* %input, metadata !4, metadata !17), !dbg !18
Reid Kleckner3a363ff2017-05-09 16:02:20 +000019 ret i32 42, !dbg !18
Matthias Braun372ee592017-04-19 23:10:43 +000020}
21
Reid Kleckner3a363ff2017-05-09 16:02:20 +000022; DWARF-LABEL: .debug_info contents:
23
24; DWARF-LABEL: DW_TAG_subprogram
25; DWARF: DW_AT_frame_base [DW_FORM_exprloc] (<0x1> 57 )
26; 0x57 -> RSP
27; DWARF: DW_AT_name [DW_FORM_strp] ( {{.*}}"f0")
28; DWARF: DW_TAG_formal_parameter
29; DWARF-NEXT: DW_AT_location [DW_FORM_exprloc] (<0x2> 91 08 )
30; DW_OP_fbreg (0x91) 0x08
31; DWARF-NEXT: DW_AT_name [DW_FORM_strp] ( {{.*}}"input")
32
33
34; Dynamic alloca forces the use of RBP as the base pointer
35
Matthias Braun372ee592017-04-19 23:10:43 +000036; CHECK-LABEL: f1:
Reid Kleckner3a363ff2017-05-09 16:02:20 +000037; CHECK: pushq %rbp
38; CHECK: movl $42, %eax
39; CHECK: popq %rbp
40; CHECK: retq
Adrian Prantldefc99a2017-05-04 16:24:31 +000041define i32 @f1(%struct.s* byval align 8 %input) !dbg !19 {
Matthias Braun372ee592017-04-19 23:10:43 +000042 %val = load i64, i64* @glob
43 ; this alloca should force FP usage.
44 %stackspace = alloca i32, i64 %val, align 1
45 store i32* %stackspace, i32** @ptr
Adrian Prantldefc99a2017-05-04 16:24:31 +000046 call void @llvm.dbg.declare(metadata %struct.s* %input, metadata !20, metadata !17), !dbg !21
Reid Kleckner3a363ff2017-05-09 16:02:20 +000047 ret i32 42, !dbg !21
Matthias Braun372ee592017-04-19 23:10:43 +000048}
49
Reid Kleckner3a363ff2017-05-09 16:02:20 +000050; DWARF-LABEL: DW_TAG_subprogram
51; DWARF: DW_AT_frame_base [DW_FORM_exprloc] (<0x1> 56 )
52; 0x56 -> RBP
53; DWARF: DW_AT_name [DW_FORM_strp] ( {{.*}}"f1")
54; DWARF: DW_TAG_formal_parameter
55; DWARF-NEXT: DW_AT_location [DW_FORM_exprloc] (<0x2> 91 10 )
56; DW_OP_fbreg (0x91) 0x10
57; DWARF-NEXT: DW_AT_name [DW_FORM_strp] ( {{.*}}"input")
58
Matthias Braun372ee592017-04-19 23:10:43 +000059; CHECK-LABEL: f2:
60; Just check that we are indeed aligning the stack and setting up a base pointer
61; in RBX.
62; CHECK: pushq %rbp
63; CHECK: movq %rsp, %rbp
64; CHECK: pushq %rbx
65; CHECK: andq $-64, %rsp
66; CHECK: subq $64, %rsp
67; CHECK: movq %rsp, %rbx
Adrian Prantldefc99a2017-05-04 16:24:31 +000068define i32 @f2(%struct.s* byval align 8 %input) !dbg !22 {
Matthias Braun372ee592017-04-19 23:10:43 +000069 %val = load i64, i64* @glob
70 %stackspace = alloca i32, i64 %val, align 64
71 store i32* %stackspace, i32** @ptr
Adrian Prantldefc99a2017-05-04 16:24:31 +000072 call void @llvm.dbg.declare(metadata %struct.s* %input, metadata !23, metadata !17), !dbg !24
Reid Kleckner3a363ff2017-05-09 16:02:20 +000073 ret i32 42, !dbg !24
Matthias Braun372ee592017-04-19 23:10:43 +000074}
75
Reid Kleckner3a363ff2017-05-09 16:02:20 +000076; "input" should still be referred to through RBP.
77; DWARF-LABEL: DW_TAG_subprogram
78; DWARF: DW_AT_frame_base [DW_FORM_exprloc] (<0x1> 56 )
79; 0x56 -> RBP
80; DWARF: DW_AT_name [DW_FORM_strp] ( {{.*}}"f2")
81; DWARF: DW_TAG_formal_parameter
82; DWARF-NEXT: DW_AT_location [DW_FORM_exprloc] (<0x2> 91 10 )
83; DW_OP_fbreg (0x91) 0x10
84; DWARF-NEXT: DW_AT_name [DW_FORM_strp] ( {{.*}}"input")
85
Matthias Braun372ee592017-04-19 23:10:43 +000086declare void @llvm.dbg.declare(metadata, metadata, metadata)
87
88!llvm.dbg.cu = !{!2}
89!llvm.module.flags = !{!0, !1}
90
91!0 = !{i32 2, !"Dwarf Version", i32 4}
92!1 = !{i32 2, !"Debug Info Version", i32 3}
Reid Kleckner3a363ff2017-05-09 16:02:20 +000093!2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, emissionKind: FullDebug)
Matthias Braun372ee592017-04-19 23:10:43 +000094!3 = !DIFile(filename: "dbg-baseptr.ll", directory: "/")
95!4 = !DILocalVariable(name: "input", arg: 1, scope: !8, file: !3, line: 5, type: !9)
96!5 = !{}
97
98!6 = !DISubroutineType(types: !7)
99!7 = !{!10, !9}
100
Reid Kleckner3a363ff2017-05-09 16:02:20 +0000101!8 = distinct !DISubprogram(name: "f0", file: !3, line: 5, type: !6, isLocal: false, isDefinition: true, unit: !2, variables: !5)
Matthias Braun372ee592017-04-19 23:10:43 +0000102
103!9 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "s", elements: !11)
104!10 = !DIBasicType(name: "unsigned int", size: 32, encoding: DW_ATE_unsigned)
105!11 = !{!12, !13, !14, !15, !16}
106!12 = !DIDerivedType(tag: DW_TAG_member, name: "a", baseType: !10, size: 32)
107!13 = !DIDerivedType(tag: DW_TAG_member, name: "b", baseType: !10, size: 32, offset: 32)
108!14 = !DIDerivedType(tag: DW_TAG_member, name: "c", baseType: !10, size: 32, offset: 64)
109!15 = !DIDerivedType(tag: DW_TAG_member, name: "d", baseType: !10, size: 32, offset: 96)
110!16 = !DIDerivedType(tag: DW_TAG_member, name: "e", baseType: !10, size: 32, offset: 128)
111
112!17 = !DIExpression()
113!18 = !DILocation(line: 5, scope: !8)
Adrian Prantldefc99a2017-05-04 16:24:31 +0000114
Reid Kleckner3a363ff2017-05-09 16:02:20 +0000115!19 = distinct !DISubprogram(name: "f1", file: !3, line: 5, type: !6, isLocal: false, isDefinition: true, flags: DIFlagPrototyped, unit: !2, variables: !5)
Adrian Prantldefc99a2017-05-04 16:24:31 +0000116!20 = !DILocalVariable(name: "input", arg: 1, scope: !19, file: !3, line: 5, type: !9)
117!21 = !DILocation(line: 5, scope: !19)
Reid Kleckner3a363ff2017-05-09 16:02:20 +0000118!22 = distinct !DISubprogram(name: "f2", file: !3, line: 5, type: !6, isLocal: false, isDefinition: true, flags: DIFlagPrototyped, unit: !2, variables: !5)
Adrian Prantldefc99a2017-05-04 16:24:31 +0000119!23 = !DILocalVariable(name: "input", arg: 1, scope: !22, file: !3, line: 5, type: !9)
120!24 = !DILocation(line: 5, scope: !22)