[llvm] [llvm][DebugInfo] Unwrap template parameters that are typedefs when reconstructing DIE names (PR #168734)

Michael Buch via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 19 16:00:06 PST 2025


https://github.com/Michael137 updated https://github.com/llvm/llvm-project/pull/168734

>From ff6d6d3f47fe9688a85ef150c130bbea50f6fb1d Mon Sep 17 00:00:00 2001
From: Michael Buch <michaelbuch12 at gmail.com>
Date: Wed, 19 Nov 2025 15:33:44 +0000
Subject: [PATCH] [llvm][DebugInfo] Unwrap template parameters that are
 typedefs when reconstructing DIE names

---
 .../simplified_template_names.test            |  1 -
 .../llvm/DebugInfo/DWARF/DWARFTypePrinter.h   | 22 ++++++++++++++++---
 2 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/cross-project-tests/debuginfo-tests/clang_llvm_roundtrip/simplified_template_names.test b/cross-project-tests/debuginfo-tests/clang_llvm_roundtrip/simplified_template_names.test
index 0adb2403db304..5a0da903e2a8b 100644
--- a/cross-project-tests/debuginfo-tests/clang_llvm_roundtrip/simplified_template_names.test
+++ b/cross-project-tests/debuginfo-tests/clang_llvm_roundtrip/simplified_template_names.test
@@ -1,4 +1,3 @@
-// XFAIL: system-darwin
 // RUN: %clang %target_itanium_abi_host_triple %p/Inputs/simplified_template_names.cpp -c -o - -gdwarf-4 -Xclang -gsimple-template-names=mangled -Xclang -debug-forward-template-params -std=c++20 -gtemplate-alias \
 // RUN:   | llvm-dwarfdump --verify -
 //
diff --git a/llvm/include/llvm/DebugInfo/DWARF/DWARFTypePrinter.h b/llvm/include/llvm/DebugInfo/DWARF/DWARFTypePrinter.h
index 9108c718c4794..5201870131ce6 100644
--- a/llvm/include/llvm/DebugInfo/DWARF/DWARFTypePrinter.h
+++ b/llvm/include/llvm/DebugInfo/DWARF/DWARFTypePrinter.h
@@ -167,6 +167,23 @@ const char *toString(std::optional<DWARFFormValueType> F) {
   }
   return nullptr;
 }
+
+/// Resolve the DW_AT_type of \c D until we reach a DIE that is not a
+/// DW_TAG_typedef.
+template <typename DieType> DieType unwrapReferencedTypedefType(DieType D) {
+  auto TypeAttr = D.find(dwarf::DW_AT_type);
+  if (!TypeAttr)
+    return DieType();
+
+  auto Unwrapped = detail::resolveReferencedType(D, *TypeAttr);
+  if (!Unwrapped)
+    return DieType();
+
+  if (Unwrapped.getTag() == dwarf::DW_TAG_typedef)
+    return unwrapReferencedTypedefType(Unwrapped);
+
+  return Unwrapped;
+}
 } // namespace detail
 
 template <typename DieType>
@@ -588,10 +605,9 @@ bool DWARFTypePrinter<DieType>::appendTemplateParameters(DieType D,
     }
     if (C.getTag() != dwarf::DW_TAG_template_type_parameter)
       continue;
-    auto TypeAttr = C.find(dwarf::DW_AT_type);
     Sep();
-    appendQualifiedName(TypeAttr ? detail::resolveReferencedType(C, *TypeAttr)
-                                 : DieType());
+
+    appendQualifiedName(detail::unwrapReferencedTypedefType(C));
   }
   if (IsTemplate && *FirstParameter && FirstParameter == &FirstParameterValue) {
     OS << '<';



More information about the llvm-commits mailing list