Skip to content

Commit 06296a6

Browse files
committed
[DWARF] Line 0 should not have a discriminator.
It's meaningless and takes up extra space in the line table. Differential Revision: https://reviews.llvm.org/D37364 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@312751 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 929163d commit 06296a6

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

lib/CodeGen/AsmPrinter/DwarfDebug.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1362,8 +1362,8 @@ void DwarfDebug::recordSourceLine(unsigned Line, unsigned Col, const MDNode *S,
13621362
if (auto *Scope = cast_or_null<DIScope>(S)) {
13631363
Fn = Scope->getFilename();
13641364
Dir = Scope->getDirectory();
1365-
if (auto *LBF = dyn_cast<DILexicalBlockFile>(Scope))
1366-
if (getDwarfVersion() >= 4)
1365+
if (Line != 0 && getDwarfVersion() >= 4)
1366+
if (auto *LBF = dyn_cast<DILexicalBlockFile>(Scope))
13671367
Discriminator = LBF->getDiscriminator();
13681368

13691369
unsigned CUID = Asm->OutStreamer->getContext().getDwarfCompileUnitID();
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
; RUN: llc -filetype=obj -use-unknown-locations=Enable -mtriple=x86_64-unknown-linux %s -o %t
2+
; RUN: llvm-dwarfdump -debug-dump=line %t | FileCheck %s
3+
4+
define void @_Z3bazv() !dbg !6 {
5+
call void @_Z3foov(), !dbg !9
6+
call void @_Z3foov() ; no !dbg, so will be marked as line 0
7+
ret void, !dbg !11
8+
}
9+
10+
declare void @_Z3foov()
11+
12+
!llvm.dbg.cu = !{!0}
13+
!llvm.module.flags = !{!3, !4}
14+
!llvm.ident = !{!5}
15+
16+
!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 3.9.0 (trunk 267219)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
17+
!1 = !DIFile(filename: "test.cc", directory: ".")
18+
!2 = !{}
19+
!3 = !{i32 2, !"Dwarf Version", i32 4}
20+
!4 = !{i32 2, !"Debug Info Version", i32 3}
21+
!5 = !{!"clang version 3.9.0 (trunk 267219)"}
22+
!6 = distinct !DISubprogram(name: "baz", linkageName: "_Z3bazv", scope: !1, file: !1, line: 3, type: !7, isLocal: false, isDefinition: true, scopeLine: 3, flags: DIFlagPrototyped, isOptimized: false, unit: !0, variables: !2)
23+
!7 = !DISubroutineType(types: !8)
24+
!8 = !{null}
25+
!9 = !DILocation(line: 4, column: 3, scope: !10)
26+
!10 = !DILexicalBlockFile(scope: !6, file: !1, discriminator: 1)
27+
!11 = !DILocation(line: 6, column: 1, scope: !6)
28+
29+
; Look at the lengths. We can't verify the line-number-program size
30+
; directly, but the difference in the two lengths should not change
31+
; unexpectedly.
32+
; CHECK: total_length: 0x00000043
33+
; CHECK: prologue_length: 0x0000001e
34+
;
35+
; Verify that we see a line entry with a discriminator, and the next entry
36+
; has line 0 and no discriminator.
37+
; line column file ISA discriminator
38+
; CHECK: 4 3 1 0 1
39+
; CHECK-NEXT: 0 3 1 0 0

0 commit comments

Comments
 (0)