[llvm] 363fdc5 - [LLVM][IR] Make sure that DILabel's line is always printed (#200846)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 1 22:12:00 PDT 2026
Author: Christian Ulmann
Date: 2026-06-02T07:11:55+02:00
New Revision: 363fdc5895b55c8c4775149df832960f615d3839
URL: https://github.com/llvm/llvm-project/commit/363fdc5895b55c8c4775149df832960f615d3839
DIFF: https://github.com/llvm/llvm-project/commit/363fdc5895b55c8c4775149df832960f615d3839.diff
LOG: [LLVM][IR] Make sure that DILabel's line is always printed (#200846)
This commit ensures that the textual IR of the DILabel always contains
the `line` information. This is required as the absence of a line causes
a parsing failure, i.e., this change fixes the print + parse roundtrip.
Added:
llvm/test/Assembler/dilabel.ll
Modified:
llvm/lib/IR/AsmWriter.cpp
Removed:
################################################################################
diff --git a/llvm/lib/IR/AsmWriter.cpp b/llvm/lib/IR/AsmWriter.cpp
index 7fac24b71487a..b0727cae346f0 100644
--- a/llvm/lib/IR/AsmWriter.cpp
+++ b/llvm/lib/IR/AsmWriter.cpp
@@ -2626,7 +2626,7 @@ static void writeDILabel(raw_ostream &Out, const DILabel *N,
Printer.printMetadata("scope", N->getRawScope(), /* ShouldSkipNull */ false);
Printer.printString("name", N->getName());
Printer.printMetadata("file", N->getRawFile());
- Printer.printInt("line", N->getLine());
+ Printer.printInt("line", N->getLine(), /* ShouldSkipZero */ false);
Printer.printInt("column", N->getColumn());
Printer.printBool("isArtificial", N->isArtificial(), false);
if (N->getCoroSuspendIdx())
diff --git a/llvm/test/Assembler/dilabel.ll b/llvm/test/Assembler/dilabel.ll
new file mode 100644
index 0000000000000..f5e66b98a91da
--- /dev/null
+++ b/llvm/test/Assembler/dilabel.ll
@@ -0,0 +1,22 @@
+; RUN: llvm-as < %s | llvm-dis | llvm-as | llvm-dis | FileCheck %s
+
+; CHECK: !named = !{!0, ![[FOO:[0-9]+]], ![[BAR:[0-9]+]]}
+!named = !{!0, !1, !2}
+
+!llvm.module.flags = !{!3}
+!llvm.dbg.cu = !{!4}
+
+; CHECK-DAG: ![[FOO]] = !DILabel(scope: !0, name: "foo", file: ![[FILE:[0-9]+]], line: 7)
+; CHECK-DAG: ![[BAR]] = !DILabel(scope: !0, name: "bar", file: ![[FILE]], line: 0)
+!0 = distinct !DISubprogram(unit: !4, type: !5)
+!1 = !DILabel(scope: !0, name: "foo", file: !6, line: 7)
+!2 = !DILabel(scope: !0, name: "bar", file: !6, line: 0)
+
+!3 = !{i32 2, !"Debug Info Version", i32 3}
+!4 = distinct !DICompileUnit(language: DW_LANG_C99, producer: "clang",
+ file: !6,
+ isOptimized: true, flags: "-O2",
+ splitDebugFilename: "abc.debug", emissionKind: 2)
+!5 = !DISubroutineType(types: !7)
+!6 = !DIFile(filename: "path/to/file", directory: "/path/to/dir")
+!7 = !{null}
More information about the llvm-commits
mailing list