1; RUN: llc -mtriple=x86_64-pc-linux -filetype=obj -function-sections -o %t < %s
2; RUN: llvm-dwarfdump -v -debug-info -debug-loclists %t | FileCheck %s
3
4; CHECK:      DW_TAG_variable
5; FIXME: Use DW_FORM_loclistx to reduce relocations
6; CHECK-NEXT:   DW_AT_location [DW_FORM_sec_offset]   (0x0000000c
7; CHECK-NEXT:     [0x0000000000000000, 0x0000000000000003): DW_OP_consts +3, DW_OP_stack_value
8; CHECK-NEXT:     [0x0000000000000003, 0x0000000000000004): DW_OP_consts +4, DW_OP_stack_value)
9; CHECK-NEXT:   DW_AT_name {{.*}} "y"
10
11; CHECK:      DW_TAG_variable
12; FIXME: Use DW_FORM_loclistx to reduce relocations
13; CHECK-NEXT:   DW_AT_location [DW_FORM_sec_offset]   (0x0000001d
14; CHECK-NEXT:     Addr idx 0 (w/ length 3): DW_OP_consts +5, DW_OP_stack_value)
15; CHECK-NEXT:   DW_AT_name {{.*}} "x"
16
17; CHECK:      DW_TAG_variable
18; FIXME: Use DW_FORM_loclistx to reduce relocations
19; CHECK-NEXT:   DW_AT_location [DW_FORM_sec_offset]   (0x00000025
20; CHECK-NEXT:     [0x0000000000000003, 0x0000000000000004): DW_OP_reg0 RAX)
21; CHECK-NEXT:   DW_AT_name {{.*}} "r"
22
23; CHECK:      .debug_loclists contents:
24; CHECK-NEXT: 0x00000000: locations list header: length = 0x00000029, version = 0x0005, addr_size = 0x08, seg_size = 0x00, offset_entry_count = 0x00000000
25
26; Don't use startx_length if there's more than one entry, because the shared
27; base address will be useful for both the range that does start at the start of
28; the function, and the one that doesn't.
29
30; CHECK-NEXT: 0x0000000c:
31; CHECK-NEXT:             DW_LLE_base_addressx (0x0000000000000000)
32; CHECK-NEXT:             DW_LLE_offset_pair   (0x0000000000000000, 0x0000000000000003)
33; CHECK-NEXT:                              => [0x0000000000000000, 0x0000000000000003): DW_OP_consts +3, DW_OP_stack_value
34; CHECK-NEXT:             DW_LLE_offset_pair   (0x0000000000000003, 0x0000000000000004)
35; CHECK-NEXT:                              => [0x0000000000000003, 0x0000000000000004): DW_OP_consts +4, DW_OP_stack_value
36; CHECK-NEXT:             DW_LLE_end_of_list   ()
37
38; Show that startx_length can be used when the address range starts at the start of the function.
39
40; CHECK:      0x0000001d:
41; CHECK-NEXT:             DW_LLE_startx_length (0x0000000000000000, 0x0000000000000003)
42; CHECK-NEXT:                              => Addr idx 0 (w/ length 3): DW_OP_consts +5, DW_OP_stack_value
43; CHECK-NEXT:             DW_LLE_end_of_list   ()
44
45; And use a base address when the range doesn't start at an existing/useful
46; address in the pool.
47
48; CHECK:      0x00000025:
49; CHECK-NEXT:             DW_LLE_base_addressx (0x0000000000000000)
50; CHECK-NEXT:             DW_LLE_offset_pair   (0x0000000000000003, 0x0000000000000004)
51; CHECK-NEXT:                              => [0x0000000000000003, 0x0000000000000004): DW_OP_reg0 RAX
52; CHECK-NEXT:             DW_LLE_end_of_list   ()
53
54; Built with clang -O3 -ffunction-sections from source:
55;
56; int f1(int i, int j) {
57;   int x = 5;
58;   int y = 3;
59;   int r = i + j;
60;   int undef;
61;   x = undef;
62;   y = 4;
63;   return r;
64; }
65; void f2() {
66; }
67
68; Function Attrs: norecurse nounwind readnone uwtable
69define dso_local i32 @_Z2f1ii(i32 %i, i32 %j) local_unnamed_addr !dbg !7 {
70entry:
71  call void @llvm.dbg.value(metadata i32 %i, metadata !12, metadata !DIExpression()), !dbg !18
72  call void @llvm.dbg.value(metadata i32 %j, metadata !13, metadata !DIExpression()), !dbg !18
73  call void @llvm.dbg.value(metadata i32 5, metadata !14, metadata !DIExpression()), !dbg !18
74  call void @llvm.dbg.value(metadata i32 3, metadata !15, metadata !DIExpression()), !dbg !18
75  %add = add nsw i32 %j, %i, !dbg !19
76  call void @llvm.dbg.value(metadata i32 %add, metadata !16, metadata !DIExpression()), !dbg !18
77  call void @llvm.dbg.value(metadata i32 undef, metadata !14, metadata !DIExpression()), !dbg !18
78  call void @llvm.dbg.value(metadata i32 4, metadata !15, metadata !DIExpression()), !dbg !18
79  ret i32 %add, !dbg !20
80}
81
82; Function Attrs: norecurse nounwind readnone uwtable
83define dso_local void @_Z2f2v() local_unnamed_addr !dbg !21 {
84entry:
85  ret void, !dbg !24
86}
87
88; Function Attrs: nounwind readnone speculatable willreturn
89declare void @llvm.dbg.value(metadata, metadata, metadata)
90
91!llvm.dbg.cu = !{!0}
92!llvm.module.flags = !{!3, !4, !5}
93!llvm.ident = !{!6}
94
95!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)
96!1 = !DIFile(filename: "loc2.cpp", directory: "/usr/local/google/home/blaikie/dev/scratch", checksumkind: CSK_MD5, checksum: "91e0069c680e2a63f4f885ec93f5d07e")
97!2 = !{}
98!3 = !{i32 2, !"Dwarf Version", i32 5}
99!4 = !{i32 2, !"Debug Info Version", i32 3}
100!5 = !{i32 1, !"wchar_size", i32 4}
101!6 = !{!"clang version 10.0.0 (trunk 374581) (llvm/trunk 374579)"}
102!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)
103!8 = !DISubroutineType(types: !9)
104!9 = !{!10, !10, !10}
105!10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
106!11 = !{!12, !13, !14, !15, !16, !17}
107!12 = !DILocalVariable(name: "i", arg: 1, scope: !7, file: !1, line: 1, type: !10)
108!13 = !DILocalVariable(name: "j", arg: 2, scope: !7, file: !1, line: 1, type: !10)
109!14 = !DILocalVariable(name: "x", scope: !7, file: !1, line: 2, type: !10)
110!15 = !DILocalVariable(name: "y", scope: !7, file: !1, line: 3, type: !10)
111!16 = !DILocalVariable(name: "r", scope: !7, file: !1, line: 4, type: !10)
112!17 = !DILocalVariable(name: "undef", scope: !7, file: !1, line: 5, type: !10)
113!18 = !DILocation(line: 0, scope: !7)
114!19 = !DILocation(line: 4, column: 13, scope: !7)
115!20 = !DILocation(line: 8, column: 3, scope: !7)
116!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)
117!22 = !DISubroutineType(types: !23)
118!23 = !{null}
119!24 = !DILocation(line: 11, column: 1, scope: !21)
120