xref: /llvm-project/llvm/test/DebugInfo/X86/rnglists_base_attr.ll (revision 5a288fa32e0c91b211e39f3e370255916902f898)
1; RUN: llc -dwarf-version=5 -O0 %s -mtriple=x86_64-unknown-linux-gnu -filetype=obj -o %t
2; RUN: llvm-dwarfdump -v %t | FileCheck %s
3
4; Make sure we don't generate a duplicate DW_AT_rnglists_base attribute in the CU DIE
5; when more than one range list is emitted.
6; From the source:
7;
8; void f1();
9; void f2() {
10;   f1();
11;   {
12;     bool b;
13;     f1();
14;     f1();
15;   }
16; }
17; __attribute__((section(".text.foo"))) void f3() { }
18
19; Compile with clang -gwarf5 -S -emit-llvm
20; and change the resulting IR to move the first call to f1() to between
21; the second and the third call. This, along with the dbg.declare instruction
22; for the variable b, creates a gap in the code range for the nested lexical
23; scope that is b's immediate parent scope. A range list is emitted for that scope.
24;
25; In addition, the placement of f3() in a different section forces a
26; rangelist to be emitted for the CU instead of simply using low/high pc
27; attributes.
28
29; CHECK:      .debug_info contents:
30; CHECK:      DW_TAG_compile_unit
31; Make sure we have 2 CU ranges.
32; CHECK:      DW_AT_ranges
33; CHECK-NEXT: [0x{{[0-9a-f]+, 0x[0-9a-f]+}}) ".text"
34; CHECK-NEXT: [0x{{[0-9a-f]+, 0x[0-9a-f]+}}) ".text.foo"
35; We should not see any duplicate DW_AT_rnglists_base attributes.
36; CHECK:      DW_AT_rnglists_base [DW_FORM_sec_offset]                   (0x0000000c)
37; CHECK-NOT:  DW_AT_rnglists_base
38;
39; Make sure we see 2 ranges in the lexical block DIE.
40; CHECK:      DW_TAG_lexical_block
41; CHECK-NOT:  DW_TAG
42; CHECK:      DW_AT_ranges
43; CHECK-NEXT: [0x{{[0-9a-f]+, 0x[0-9a-f]+}}) ".text"
44; CHECK-NEXT: [0x{{[0-9a-f]+, 0x[0-9a-f]+}}) ".text"
45
46define dso_local void @_Z2f2v() !dbg !7 {
47entry:
48  %b = alloca i8, align 1
49  call void @llvm.dbg.declare(metadata ptr %b, metadata !11, metadata !DIExpression()), !dbg !14
50  call void @_Z2f1v(), !dbg !15
51  ; The following call has been moved here from right after the alloca
52  call void @_Z2f1v(), !dbg !10
53  call void @_Z2f1v(), !dbg !16
54  ret void, !dbg !17
55}
56
57declare dso_local void @_Z2f1v()
58
59declare void @llvm.dbg.declare(metadata, metadata, metadata)
60
61define dso_local void @_Z2f3v() section ".text.foo" !dbg !18 {
62entry:
63  ret void, !dbg !19
64}
65
66!llvm.dbg.cu = !{!0}
67!llvm.module.flags = !{!3, !4, !5}
68!llvm.ident = !{!6}
69
70!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 7.0.0 (trunk 337837)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
71!1 = !DIFile(filename: "t3.cpp", directory: "/home/test/rangelists", checksumkind: CSK_MD5, checksum: "1ba81b564a832caa8114cd008c199048")
72!2 = !{}
73!3 = !{i32 2, !"Dwarf Version", i32 5}
74!4 = !{i32 2, !"Debug Info Version", i32 3}
75!5 = !{i32 1, !"wchar_size", i32 4}
76!6 = !{!"clang version 7.0.0 (trunk 337837)"}
77!7 = distinct !DISubprogram(name: "f2", linkageName: "_Z2f2v", scope: !1, file: !1, line: 2, type: !8, isLocal: false, isDefinition: true, scopeLine: 2, flags: DIFlagPrototyped, isOptimized: false, unit: !0, retainedNodes: !2)
78!8 = !DISubroutineType(types: !9)
79!9 = !{null}
80!10 = !DILocation(line: 3, column: 3, scope: !7)
81!11 = !DILocalVariable(name: "b", scope: !12, file: !1, line: 5, type: !13)
82!12 = distinct !DILexicalBlock(scope: !7, file: !1, line: 4, column: 3)
83!13 = !DIBasicType(name: "bool", size: 8, encoding: DW_ATE_boolean)
84!14 = !DILocation(line: 5, column: 10, scope: !12)
85!15 = !DILocation(line: 6, column: 5, scope: !12)
86!16 = !DILocation(line: 7, column: 5, scope: !12)
87!17 = !DILocation(line: 9, column: 1, scope: !7)
88!18 = distinct !DISubprogram(name: "f3", linkageName: "_Z2f3v", scope: !1, file: !1, line: 10, type: !8, isLocal: false, isDefinition: true, scopeLine: 10, flags: DIFlagPrototyped, isOptimized: false, unit: !0, retainedNodes: !2)
89!19 = !DILocation(line: 10, column: 51, scope: !18)
90