Skip to content

Commit c3b13af

Browse files
ostannardpogo59
authored andcommitted
[DebugInfo] Don't emit .loc directive with all values zero (llvm#109978)
When emitting debug info for code alignment, it was possible to emit a .loc directive with a file number of zero, which is invalid for DWARF 4 and earlier. This happened because getCurrentDwarfLoc() returned a zero-initialised value when there hadn't been a previous .loc directive emitted. --------- Co-authored-by: Paul T Robinson <[email protected]>
1 parent b8bb874 commit c3b13af

File tree

2 files changed

+36
-4
lines changed

2 files changed

+36
-4
lines changed

llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3682,8 +3682,10 @@ void DwarfDebug::beginCodeAlignment(const MachineBasicBlock &MBB) {
36823682
return;
36833683

36843684
auto PrevLoc = Asm->OutStreamer->getContext().getCurrentDwarfLoc();
3685-
Asm->OutStreamer->emitDwarfLocDirective(
3686-
PrevLoc.getFileNum(), 0, PrevLoc.getColumn(), 0, 0, 0, StringRef());
3687-
MCDwarfLineEntry::make(Asm->OutStreamer.get(),
3688-
Asm->OutStreamer->getCurrentSectionOnly());
3685+
if (PrevLoc.getLine()) {
3686+
Asm->OutStreamer->emitDwarfLocDirective(
3687+
PrevLoc.getFileNum(), 0, PrevLoc.getColumn(), 0, 0, 0, StringRef());
3688+
MCDwarfLineEntry::make(Asm->OutStreamer.get(),
3689+
Asm->OutStreamer->getCurrentSectionOnly());
3690+
}
36893691
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
; RUN: llc -mtriple=arm-none-eabi < %s | FileCheck %s
2+
; RUN: llc -mtriple=arm-none-eabi < %s | llvm-mc --triple=arm-none-eabi -mcpu=cortex-m3
3+
4+
; Check that, when an aligned loop is the first thing in a function, we do not
5+
; emit an invalid .loc directive, which is rejected by the assembly parser.
6+
7+
; CHECK-NOT: .loc 0
8+
; CHECK: .loc 1 2 3 prologue_end
9+
; CHECK-NOT: .loc 0
10+
11+
define dso_local void @foo() "target-cpu"="cortex-m3" !dbg !8 {
12+
entry:
13+
br label %while.body, !dbg !11
14+
15+
while.body:
16+
br label %while.body, !dbg !11
17+
}
18+
19+
20+
!llvm.dbg.cu = !{!0}
21+
!llvm.module.flags = !{!2, !3}
22+
23+
!0 = distinct !DICompileUnit(language: DW_LANG_C11, file: !1, producer: "clang version 20.0.0git ([email protected]:llvm/llvm-project.git 1c984b86b389bbc71c8c2988d1d707e2f32878bd)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: None)
24+
!1 = !DIFile(filename: "test.c", directory: "/work/scratch")
25+
!2 = !{i32 7, !"Dwarf Version", i32 4}
26+
!3 = !{i32 2, !"Debug Info Version", i32 3}
27+
!8 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 1, type: !9, scopeLine: 1, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0)
28+
!9 = !DISubroutineType(types: !10)
29+
!10 = !{null}
30+
!11 = !DILocation(line: 2, column: 3, scope: !8)

0 commit comments

Comments
 (0)