xref: /llvm-project/llvm/test/CodeGen/X86/debug-loclists.ll (revision eb00e79bd97446c2dd16f9937c299ef7919ecb60)
1; RUN: llc -mtriple=x86_64-pc-linux -filetype=obj -function-sections -o %t -experimental-debug-variable-locations=true < %s
2; RUN: llvm-dwarfdump -v -debug-info -debug-loclists %t | \
3; RUN:   FileCheck %s --check-prefixes=CHECK,DWARF32
4
5; RUN: llc -dwarf64 -mtriple=x86_64-pc-linux -filetype=obj -function-sections -o %t -experimental-debug-variable-locations=true < %s
6; RUN: llvm-dwarfdump -v -debug-info -debug-loclists %t | \
7; RUN:   FileCheck %s --check-prefixes=CHECK,DWARF64
8
9; RUN: llc -dwarf-version=5 -split-dwarf-file=foo.dwo -mtriple=x86_64-pc-linux -filetype=obj -function-sections -o %t -experimental-debug-variable-locations=true < %s
10; RUN: llvm-dwarfdump -v -debug-info -debug-loclists %t | \
11; RUN:   FileCheck %s --check-prefixes=DWO,DWO32
12
13; RUN: llc -dwarf64 -dwarf-version=5 -split-dwarf-file=foo.dwo -mtriple=x86_64-pc-linux -filetype=obj -function-sections -o %t -experimental-debug-variable-locations=true < %s
14; RUN: llvm-dwarfdump -v -debug-info -debug-loclists %t | \
15; RUN:   FileCheck %s --check-prefixes=DWO,DWO64
16
17; CHECK:        DW_TAG_variable
18; DWARF32-NEXT:   DW_AT_location [DW_FORM_loclistx]   (indexed (0x0) loclist = 0x00000018:
19; DWARF64-NEXT:   DW_AT_location [DW_FORM_loclistx]   (indexed (0x0) loclist = 0x0000002c:
20; CHECK-NEXT:       [0x0000000000000000, 0x0000000000000003) ".text._Z2f1ii": DW_OP_consts +5, DW_OP_stack_value)
21; CHECK-NEXT:     DW_AT_name {{.*}} "x"
22
23; CHECK:        DW_TAG_variable
24; DWARF32-NEXT:   DW_AT_location [DW_FORM_loclistx]   (indexed (0x1) loclist = 0x00000020:
25; DWARF64-NEXT:   DW_AT_location [DW_FORM_loclistx]   (indexed (0x1) loclist = 0x00000034:
26; CHECK-NEXT:       [0x0000000000000000, 0x0000000000000003) ".text._Z2f1ii": DW_OP_consts +3, DW_OP_stack_value
27; CHECK-NEXT:       [0x0000000000000003, 0x0000000000000004) ".text._Z2f1ii": DW_OP_consts +4, DW_OP_stack_value)
28; CHECK-NEXT:     DW_AT_name {{.*}} "y"
29
30; CHECK:        DW_TAG_variable
31; DWARF32-NEXT:   DW_AT_location [DW_FORM_loclistx]   (indexed (0x2) loclist = 0x00000031:
32; DWARF64-NEXT:   DW_AT_location [DW_FORM_loclistx]	(indexed (0x2) loclist = 0x00000045:
33; CHECK-NEXT:       [0x0000000000000003, 0x0000000000000004) ".text._Z2f1ii": DW_OP_reg0 RAX)
34; CHECK-NEXT:     DW_AT_name {{.*}} "r"
35
36; CHECK:        .debug_loclists contents:
37; DWARF32-NEXT: 0x00000000: locations list header: length = 0x00000035, format = DWARF32, version = 0x0005, addr_size = 0x08, seg_size = 0x00, offset_entry_count = 0x00000003
38; DWARF64-NEXT: 0x00000000: locations list header: length = 0x0000000000000041, format = DWARF64, version = 0x0005, addr_size = 0x08, seg_size = 0x00, offset_entry_count = 0x00000003
39
40; DWO:      .debug_loclists.dwo contents:
41; DWO32-NEXT: 0x00000000: locations list header: length = 0x00000035, format = DWARF32, version = 0x0005, addr_size = 0x08, seg_size = 0x00, offset_entry_count = 0x00000003
42; DWO64-NEXT: 0x00000000: locations list header: length = 0x0000000000000041, format = DWARF64, version = 0x0005, addr_size = 0x08, seg_size = 0x00, offset_entry_count = 0x00000003
43
44; CHECK-NEXT:   offsets: [
45; DWARF32-NEXT: 0x0000000c => 0x00000018
46; DWARF32-NEXT: 0x00000014 => 0x00000020
47; DWARF32-NEXT: 0x00000025 => 0x00000031
48; DWARF64-NEXT: 0x0000000000000018 => 0x0000002c
49; DWARF64-NEXT: 0x0000000000000020 => 0x00000034
50; DWARF64-NEXT: 0x0000000000000031 => 0x00000045
51; CHECK-NEXT:   ]
52
53; DWARF32-NEXT: 0x00000018:
54; DWARF64-NEXT: 0x0000002c:
55
56; Show that startx_length can be used when the address range starts at the start of the function.
57
58; CHECK-NEXT:             DW_LLE_startx_length (0x0000000000000000, 0x0000000000000003): DW_OP_consts +5, DW_OP_stack_value
59; CHECK-NEXT:             DW_LLE_end_of_list   ()
60
61; Don't use startx_length if there's more than one entry, because the shared
62; base address will be useful for both the range that does start at the start of
63; the function, and the one that doesn't.
64
65; DWARF32:      0x00000020:
66; DWARF64:      0x00000034:
67
68; CHECK-NEXT:             DW_LLE_base_addressx (0x0000000000000000)
69; CHECK-NEXT:             DW_LLE_offset_pair   (0x0000000000000000, 0x0000000000000003): DW_OP_consts +3, DW_OP_stack_value
70; CHECK-NEXT:             DW_LLE_offset_pair   (0x0000000000000003, 0x0000000000000004): DW_OP_consts +4, DW_OP_stack_value
71; CHECK-NEXT:             DW_LLE_end_of_list   ()
72
73; And use a base address when the range doesn't start at an existing/useful
74; address in the pool.
75
76; DWARF32:      0x00000031:
77; DWARF64:      0x00000045:
78; CHECK-NEXT:             DW_LLE_base_addressx (0x0000000000000000)
79; CHECK-NEXT:             DW_LLE_offset_pair   (0x0000000000000003, 0x0000000000000004): DW_OP_reg0 RAX
80; CHECK-NEXT:             DW_LLE_end_of_list   ()
81
82; Built with clang -O3 -ffunction-sections from source:
83;
84; int f1(int i, int j) {
85;   int x = 5;
86;   int y = 3;
87;   int r = i + j;
88;   int undef;
89;   x = undef;
90;   y = 4;
91;   return r;
92; }
93; void f2() {
94; }
95
96; Function Attrs: norecurse nounwind readnone uwtable
97define dso_local i32 @_Z2f1ii(i32 %i, i32 %j) local_unnamed_addr !dbg !7 {
98entry:
99  call void @llvm.dbg.value(metadata i32 %i, metadata !12, metadata !DIExpression()), !dbg !18
100  call void @llvm.dbg.value(metadata i32 %j, metadata !13, metadata !DIExpression()), !dbg !18
101  call void @llvm.dbg.value(metadata i32 5, metadata !14, metadata !DIExpression()), !dbg !18
102  call void @llvm.dbg.value(metadata i32 3, metadata !15, metadata !DIExpression()), !dbg !18
103  %add = add nsw i32 %j, %i, !dbg !19
104  call void @llvm.dbg.value(metadata i32 %add, metadata !16, metadata !DIExpression()), !dbg !18
105  call void @llvm.dbg.value(metadata i32 undef, metadata !14, metadata !DIExpression()), !dbg !18
106  call void @llvm.dbg.value(metadata i32 4, metadata !15, metadata !DIExpression()), !dbg !18
107  ret i32 %add, !dbg !20
108}
109
110; Function Attrs: norecurse nounwind readnone uwtable
111define dso_local void @_Z2f2v() local_unnamed_addr !dbg !21 {
112entry:
113  ret void, !dbg !24
114}
115
116; Function Attrs: nounwind readnone speculatable willreturn
117declare void @llvm.dbg.value(metadata, metadata, metadata)
118
119!llvm.dbg.cu = !{!0}
120!llvm.module.flags = !{!3, !4, !5}
121!llvm.ident = !{!6}
122
123!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 10.0.0 (trunk 374581) (llvm/trunk 374579)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, nameTableKind: None)
124!1 = !DIFile(filename: "loc2.cpp", directory: "/usr/local/google/home/blaikie/dev/scratch", checksumkind: CSK_MD5, checksum: "91e0069c680e2a63f4f885ec93f5d07e")
125!2 = !{}
126!3 = !{i32 2, !"Dwarf Version", i32 5}
127!4 = !{i32 2, !"Debug Info Version", i32 3}
128!5 = !{i32 1, !"wchar_size", i32 4}
129!6 = !{!"clang version 10.0.0 (trunk 374581) (llvm/trunk 374579)"}
130!7 = distinct !DISubprogram(name: "f1", linkageName: "_Z2f1ii", scope: !1, file: !1, line: 1, type: !8, scopeLine: 1, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !11)
131!8 = !DISubroutineType(types: !9)
132!9 = !{!10, !10, !10}
133!10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
134!11 = !{!12, !13, !14, !15, !16, !17}
135!12 = !DILocalVariable(name: "i", arg: 1, scope: !7, file: !1, line: 1, type: !10)
136!13 = !DILocalVariable(name: "j", arg: 2, scope: !7, file: !1, line: 1, type: !10)
137!14 = !DILocalVariable(name: "x", scope: !7, file: !1, line: 2, type: !10)
138!15 = !DILocalVariable(name: "y", scope: !7, file: !1, line: 3, type: !10)
139!16 = !DILocalVariable(name: "r", scope: !7, file: !1, line: 4, type: !10)
140!17 = !DILocalVariable(name: "undef", scope: !7, file: !1, line: 5, type: !10)
141!18 = !DILocation(line: 0, scope: !7)
142!19 = !DILocation(line: 4, column: 13, scope: !7)
143!20 = !DILocation(line: 8, column: 3, scope: !7)
144!21 = distinct !DISubprogram(name: "f2", linkageName: "_Z2f2v", scope: !1, file: !1, line: 10, type: !22, scopeLine: 10, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !2)
145!22 = !DISubroutineType(types: !23)
146!23 = !{null}
147!24 = !DILocation(line: 11, column: 1, scope: !21)
148