[llvm] [DebugInfo] Index base types synthesized for DW_OP_convert (PR #228908)

Kamil Monicz via llvm-commits llvm-commits at lists.llvm.org
Sun Oct 4 08:27:37 PDT 2026


https://github.com/Zaczero created https://github.com/llvm/llvm-project/pull/228908

`createBaseTypeDIEs()` gives the base types referenced by `DW_OP_convert` a `DW_AT_name`, but does not register them in the accelerator tables. When `.debug_names` is emitted, `llvm-dwarfdump --verify` reports missing entries such as `DW_ATE_unsigned_16` and `DW_ATE_unsigned_64`. DWARF 5 ยง6.1.1.1 requires entries for named types.

Register these types through `addAccelType()`, following the existing handling of the synthesized `__ARRAY_SIZE_TYPE__` in `getIndexTyDie()`. The regression test covers DWARF32 and DWARF64, verifies the emitted object, and checks that both conversion types appear in the name index.

Validation: the regression fails on the parent revision with the two missing-name errors and passes with this change. `llvm-lit -v -j16 llvm/test/DebugInfo` passes in a local Linux X86-only Debug build with assertions enabled: 1,403 passed, 296 unsupported, and one expected failure.

AI assistance: GPT-6 helped prepare the implementation, regression test, and description.


>From a35ca06322af23a6cfc7ca5575e23a2ea009284b Mon Sep 17 00:00:00 2001
From: Kamil Monicz <kamil at monicz.dev>
Date: Sun, 4 Oct 2026 15:16:24 +0000
Subject: [PATCH] [DebugInfo] Index base types synthesized for DW_OP_convert

createBaseTypeDIEs gives expression-referenced base types a DW_AT_name
but does not register them with the accelerator tables. When a DWARF 5
name index is emitted, llvm-dwarfdump --verify reports missing entries
for these types.

Register the synthesized types through addAccelType, as for other named
base types. Add coverage for DWARF32 and DWARF64 that verifies the name
index and checks that both conversion types are indexed.

Assisted-by: GPT-6
---
 .../CodeGen/AsmPrinter/DwarfCompileUnit.cpp   |  8 +++--
 .../test/DebugInfo/X86/convert-debug-names.ll | 32 +++++++++++++++++++
 2 files changed, 37 insertions(+), 3 deletions(-)
 create mode 100644 llvm/test/DebugInfo/X86/convert-debug-names.ll

diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
index 509fa83a2ce71..0cd55b20bc757 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
@@ -1927,9 +1927,10 @@ void DwarfCompileUnit::createBaseTypeDIEs() {
     DIE &Die = getUnitDie().addChildFront(
       DIE::get(DIEValueAllocator, dwarf::DW_TAG_base_type));
     SmallString<32> Str;
-    addString(Die, dwarf::DW_AT_name,
-              Twine(dwarf::AttributeEncodingString(Btr.Encoding) +
-                    "_" + Twine(Btr.BitSize)).toStringRef(Str));
+    StringRef Name = Twine(dwarf::AttributeEncodingString(Btr.Encoding) + "_" +
+                           Twine(Btr.BitSize))
+                         .toStringRef(Str);
+    addString(Die, dwarf::DW_AT_name, Name);
     addUInt(Die, dwarf::DW_AT_encoding, dwarf::DW_FORM_data1, Btr.Encoding);
     // Round up to smallest number of bytes that contains this number of bits.
     // ExprRefedBaseTypes is populated with types referenced by
@@ -1939,6 +1940,7 @@ void DwarfCompileUnit::createBaseTypeDIEs() {
     // DwarfUnit::constructTypeDIE.
     addUInt(Die, dwarf::DW_AT_byte_size, std::nullopt,
             divideCeil(Btr.BitSize, 8));
+    DD->addAccelType(*this, CUNode->getNameTableKind(), Name, Die, /*Flags*/ 0);
     Btr.Die = &Die;
   }
 }
diff --git a/llvm/test/DebugInfo/X86/convert-debug-names.ll b/llvm/test/DebugInfo/X86/convert-debug-names.ll
new file mode 100644
index 0000000000000..05d91b6fc3683
--- /dev/null
+++ b/llvm/test/DebugInfo/X86/convert-debug-names.ll
@@ -0,0 +1,32 @@
+; RUN: llc -mtriple=x86_64-unknown-linux-gnu -filetype=obj %s -o %t
+; RUN: llvm-dwarfdump --verify %t
+; RUN: llvm-dwarfdump --debug-names %t | FileCheck %s
+; RUN: llc -mtriple=x86_64-unknown-linux-gnu -dwarf64 -filetype=obj %s -o %t
+; RUN: llvm-dwarfdump --verify %t
+; RUN: llvm-dwarfdump --debug-names %t | FileCheck %s
+
+;; Base types synthesized for DW_OP_convert must be indexed by name.
+
+; CHECK:     .debug_names contents:
+; CHECK-DAG: String: {{.*}} "DW_ATE_unsigned_16"
+; CHECK-DAG: String: {{.*}} "DW_ATE_unsigned_64"
+
+define i64 @convert(i16 %value) !dbg !4 {
+  #dbg_value(i16 %value, !7, !DIExpression(DW_OP_LLVM_convert, 16, DW_ATE_unsigned, DW_OP_LLVM_convert, 64, DW_ATE_unsigned, DW_OP_stack_value), !8)
+  %wide = zext i16 %value to i64, !dbg !8
+  ret i64 %wide, !dbg !8
+}
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!2, !3}
+!0 = distinct !DICompileUnit(language: DW_LANG_C, file: !1, producer: "clang", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, nameTableKind: Default)
+!1 = !DIFile(filename: "convert.c", directory: "/")
+!2 = !{i32 2, !"Debug Info Version", i32 3}
+!3 = !{i32 2, !"Dwarf Version", i32 5}
+!4 = distinct !DISubprogram(name: "convert", scope: !1, file: !1, line: 1, type: !5, scopeLine: 1, unit: !0, spFlags: DISPFlagDefinition | DISPFlagOptimized)
+!5 = !DISubroutineType(types: !6)
+!6 = !{!9, !10}
+!7 = !DILocalVariable(name: "wide", scope: !4, file: !1, line: 1, type: !9)
+!8 = !DILocation(line: 1, column: 1, scope: !4)
+!9 = !DIBasicType(name: "unsigned long", size: 64, encoding: DW_ATE_unsigned)
+!10 = !DIBasicType(name: "unsigned short", size: 16, encoding: DW_ATE_unsigned)



More information about the llvm-commits mailing list