[llvm] [DebugInfo] Limit stripNonLineTableDebugInfo to debug named metadata (PR #225858)
Fabian Parzefall via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 23 10:53:22 PDT 2026
https://github.com/pzfl updated https://github.com/llvm/llvm-project/pull/225858
>From 17284ca85898ec2bb8f8af7722392b7805b37761 Mon Sep 17 00:00:00 2001
From: Fabian Parzefall <parzefall at meta.com>
Date: Wed, 23 Sep 2026 10:15:45 -0700
Subject: [PATCH] [DebugInfo] Limit stripNonLineTableDebugInfo to debug named
metadata
stripNonLineTableDebugInfo processes all named metadata nodes in the
module. Since remapping discards null-nodes, this might modify metadata
that is not related to debug info. Limit this to only llvm.dbg.* and
llvm.gcov named metadata. Also, remove a dead loop.
---
llvm/lib/IR/DebugInfo.cpp | 13 +++----------
.../Util/strip-nonlinetable-debuginfo-cus.ll | 4 ++++
2 files changed, 7 insertions(+), 10 deletions(-)
diff --git a/llvm/lib/IR/DebugInfo.cpp b/llvm/lib/IR/DebugInfo.cpp
index 8a119a98784a6b..881e83a0077c5a 100644
--- a/llvm/lib/IR/DebugInfo.cpp
+++ b/llvm/lib/IR/DebugInfo.cpp
@@ -954,16 +954,6 @@ void DebugTypeInfoRemoval::traverse(MDNode *N) {
bool llvm::stripNonLineTableDebugInfo(Module &M) {
bool Changed = false;
- // Delete non-CU debug info named metadata nodes.
- for (auto NMI = M.named_metadata_begin(), NME = M.named_metadata_end();
- NMI != NME;) {
- NamedMDNode *NMD = &*NMI;
- ++NMI;
- // Specifically keep dbg.cu around.
- if (NMD->getName() == "llvm.dbg.cu")
- continue;
- }
-
// Drop all dbg attachments from global variables.
for (auto &GV : M.globals())
GV.eraseMetadata(LLVMContext::MD_dbg);
@@ -1022,6 +1012,9 @@ bool llvm::stripNonLineTableDebugInfo(Module &M) {
// Create a new llvm.dbg.cu, which is equivalent to the one
// -gline-tables-only would have created.
for (auto &NMD : M.named_metadata()) {
+ if (!NMD.getName().starts_with("llvm.dbg.") && NMD.getName() != "llvm.gcov")
+ continue;
+
SmallVector<MDNode *, 8> Ops;
for (MDNode *Op : NMD.operands())
Ops.push_back(remap(Op));
diff --git a/llvm/test/Transforms/Util/strip-nonlinetable-debuginfo-cus.ll b/llvm/test/Transforms/Util/strip-nonlinetable-debuginfo-cus.ll
index 47074048d8769c..6129e8c45d2cba 100644
--- a/llvm/test/Transforms/Util/strip-nonlinetable-debuginfo-cus.ll
+++ b/llvm/test/Transforms/Util/strip-nonlinetable-debuginfo-cus.ll
@@ -2,15 +2,18 @@
!llvm.dbg.cu = !{!2, !6}
!llvm.gcov = !{!3}
!llvm.module.flags = !{!7}
+!llvm.other.md = !{!8}
!1 = !DIFile(filename: "path/to/file", directory: "/path/to/dir")
; The first CU is used for the line table, the second one is a module skeleton
; and should be stripped.
; CHECK: !llvm.dbg.cu = !{![[CU:[0-9]+]]}
+; CHECK: !llvm.other.md = !{![[OTHER:[0-9]+]]}
; CHECK: ![[CU]] = distinct !DICompileUnit({{.*}}"abc.debug"{{.*}}LineTablesOnly
; CHECK-NOT: retainedTypes:
; CHECK-SAME: )
; CHECK-NOT: DICompositeType
+; CHECK: ![[OTHER]] = distinct !{null, i32 8}
!2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang",
isOptimized: true, flags: "-O2", runtimeVersion: 2,
splitDebugFilename: "abc.debug", emissionKind: FullDebug,
@@ -22,3 +25,4 @@
splitDebugFilename: "abc.dwo", emissionKind: FullDebug,
dwoId: 1234)
!7 = !{i32 1, !"Debug Info Version", i32 3}
+!8 = distinct !{null, i32 8}
More information about the llvm-commits
mailing list