[llvm] [DebugInfo] Don't emit .loc directive with all values zero (PR #109978)
Oliver Stannard via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 26 01:23:42 PDT 2024
https://github.com/ostannard updated https://github.com/llvm/llvm-project/pull/109978
>From 07526d8642e1ad1971421513f4d20dc27f216863 Mon Sep 17 00:00:00 2001
From: Oliver Stannard <oliver.stannard at arm.com>
Date: Wed, 25 Sep 2024 13:41:14 +0100
Subject: [PATCH 1/3] [DebugInfo] Don't emit .loc directive with all values
zero
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.
---
llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp | 10 ++++----
llvm/test/DebugInfo/ARM/align-func-start.ll | 26 +++++++++++++++++++++
2 files changed, 32 insertions(+), 4 deletions(-)
create mode 100644 llvm/test/DebugInfo/ARM/align-func-start.ll
diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
index e9649f9ff81658..f94240e6d2224b 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
@@ -3682,8 +3682,10 @@ void DwarfDebug::beginCodeAlignment(const MachineBasicBlock &MBB) {
return;
auto PrevLoc = Asm->OutStreamer->getContext().getCurrentDwarfLoc();
- Asm->OutStreamer->emitDwarfLocDirective(
- PrevLoc.getFileNum(), 0, PrevLoc.getColumn(), 0, 0, 0, StringRef());
- MCDwarfLineEntry::make(Asm->OutStreamer.get(),
- Asm->OutStreamer->getCurrentSectionOnly());
+ if (PrevLoc.getLine()) {
+ Asm->OutStreamer->emitDwarfLocDirective(
+ PrevLoc.getFileNum(), 0, PrevLoc.getColumn(), 0, 0, 0, StringRef());
+ MCDwarfLineEntry::make(Asm->OutStreamer.get(),
+ Asm->OutStreamer->getCurrentSectionOnly());
+ }
}
diff --git a/llvm/test/DebugInfo/ARM/align-func-start.ll b/llvm/test/DebugInfo/ARM/align-func-start.ll
new file mode 100644
index 00000000000000..60900ae30351cc
--- /dev/null
+++ b/llvm/test/DebugInfo/ARM/align-func-start.ll
@@ -0,0 +1,26 @@
+; RUN: llc -mtriple=arm-none-eabi < %s | FileCheck %s
+; RUN: llc -mtriple=arm-none-eabi < %s | llvm-mc --triple=arm-none-eabi -mcpu=cortex-m3
+
+; CHECK-NOT: .loc 0 0 0
+; CHECK: .loc 1 2 3 prologue_end
+
+define dso_local void @foo() "target-cpu"="cortex-m3" !dbg !8 {
+entry:
+ br label %while.body, !dbg !11
+
+while.body:
+ br label %while.body, !dbg !11
+}
+
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!2, !3}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C11, file: !1, producer: "clang version 20.0.0git (git at github.com:llvm/llvm-project.git 1c984b86b389bbc71c8c2988d1d707e2f32878bd)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: None)
+!1 = !DIFile(filename: "test.c", directory: "/work/scratch")
+!2 = !{i32 7, !"Dwarf Version", i32 4}
+!3 = !{i32 2, !"Debug Info Version", i32 3}
+!8 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 1, type: !9, scopeLine: 1, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0)
+!9 = !DISubroutineType(types: !10)
+!10 = !{null}
+!11 = !DILocation(line: 2, column: 3, scope: !8)
>From 7ae8a184d69faed449450e5f3d6000e227540e2e Mon Sep 17 00:00:00 2001
From: Oliver Stannard <ostannard at gmail.com>
Date: Wed, 25 Sep 2024 14:52:39 +0100
Subject: [PATCH 2/3] Update llvm/test/DebugInfo/ARM/align-func-start.ll
Co-authored-by: Paul T Robinson <paul.robinson at sony.com>
---
llvm/test/DebugInfo/ARM/align-func-start.ll | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/llvm/test/DebugInfo/ARM/align-func-start.ll b/llvm/test/DebugInfo/ARM/align-func-start.ll
index 60900ae30351cc..356fe2abd3194d 100644
--- a/llvm/test/DebugInfo/ARM/align-func-start.ll
+++ b/llvm/test/DebugInfo/ARM/align-func-start.ll
@@ -1,8 +1,9 @@
; RUN: llc -mtriple=arm-none-eabi < %s | FileCheck %s
; RUN: llc -mtriple=arm-none-eabi < %s | llvm-mc --triple=arm-none-eabi -mcpu=cortex-m3
-; CHECK-NOT: .loc 0 0 0
+; CHECK-NOT: .loc 0
; CHECK: .loc 1 2 3 prologue_end
+; CHECK-NOT: .loc 0
define dso_local void @foo() "target-cpu"="cortex-m3" !dbg !8 {
entry:
>From 8f24b7c49888ae43e5058a784815343f45cd887c Mon Sep 17 00:00:00 2001
From: Oliver Stannard <oliver.stannard at arm.com>
Date: Thu, 26 Sep 2024 09:20:25 +0100
Subject: [PATCH 3/3] Add a comment explaining the test
---
llvm/test/DebugInfo/ARM/align-func-start.ll | 3 +++
1 file changed, 3 insertions(+)
diff --git a/llvm/test/DebugInfo/ARM/align-func-start.ll b/llvm/test/DebugInfo/ARM/align-func-start.ll
index 60900ae30351cc..21ec9b2849fbc3 100644
--- a/llvm/test/DebugInfo/ARM/align-func-start.ll
+++ b/llvm/test/DebugInfo/ARM/align-func-start.ll
@@ -1,6 +1,9 @@
; RUN: llc -mtriple=arm-none-eabi < %s | FileCheck %s
; RUN: llc -mtriple=arm-none-eabi < %s | llvm-mc --triple=arm-none-eabi -mcpu=cortex-m3
+; Check that, when an aligned loop is the first thing in a function, we do not
+; emit an invalid .loc directive, which is rejected by the assembly parser.
+
; CHECK-NOT: .loc 0 0 0
; CHECK: .loc 1 2 3 prologue_end
More information about the llvm-commits
mailing list