Skip to content

Commit e96cc99

Browse files
authored
[llvm][DebugInfo] Unwrap template parameters that are typedefs when reconstructing DIE names (llvm#168734)
Depends on: * llvm#168725 When compiling with `-glldb`, we repoint the `DW_AT_type` of a DIE to be a typedef that refers to the `preferred_name`. I.e.,: ``` template <typename T> structure t7; using t7i = t7<int>; template <typename T> struct __attribute__((__preferred_name__(t7i))) t7 {}; template <typename... Ts> void f1() int main() { f1<t7i>(); } ``` would produce following (minified) DWARF: ``` DW_TAG_subprogram DW_AT_name ("_STN|f1|<t7<int> >") DW_TAG_template_type_parameter DW_AT_type (0x0000299c "t7i") ... DW_TAG_typedef DW_AT_type (0x000029a7 "t7<int>") DW_AT_name ("t7i") ``` Note how the `DW_AT_type` of the template parameter is a typedef itself (instead of the canonical type). The `DWARFTypePrinter` would take the `DW_AT_name` of this typedef when reconstructing the name of `f1`, so we would end up with a verifier failure: ``` error: Simplified template DW_AT_name could not be reconstituted: original: f1<t7<int> > reconstituted: f1<t7i> ``` Fixing this allows us to un-XFAIL the `simplified-template-names.cpp` test in `cross-project-tests`. Unfortunately this is only tested on Darwin, where LLDB tuning is the default. AFAIK, there is no other case where the template parameter type wouldn't be canonical.
1 parent ccdb719 commit e96cc99

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

cross-project-tests/debuginfo-tests/clang_llvm_roundtrip/simplified_template_names.test

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// XFAIL: system-darwin
21
// 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 \
32
// RUN: | llvm-dwarfdump --verify -
43
//

llvm/include/llvm/DebugInfo/DWARF/DWARFTypePrinter.h

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,23 @@ const char *toString(std::optional<DWARFFormValueType> F) {
167167
}
168168
return nullptr;
169169
}
170+
171+
/// Resolve the DW_AT_type of \c D until we reach a DIE that is not a
172+
/// DW_TAG_typedef.
173+
template <typename DieType> DieType unwrapReferencedTypedefType(DieType D) {
174+
auto TypeAttr = D.find(dwarf::DW_AT_type);
175+
if (!TypeAttr)
176+
return DieType();
177+
178+
auto Unwrapped = detail::resolveReferencedType(D, *TypeAttr);
179+
if (!Unwrapped)
180+
return DieType();
181+
182+
if (Unwrapped.getTag() == dwarf::DW_TAG_typedef)
183+
return unwrapReferencedTypedefType(Unwrapped);
184+
185+
return Unwrapped;
186+
}
170187
} // namespace detail
171188

172189
template <typename DieType>
@@ -588,10 +605,9 @@ bool DWARFTypePrinter<DieType>::appendTemplateParameters(DieType D,
588605
}
589606
if (C.getTag() != dwarf::DW_TAG_template_type_parameter)
590607
continue;
591-
auto TypeAttr = C.find(dwarf::DW_AT_type);
592608
Sep();
593-
appendQualifiedName(TypeAttr ? detail::resolveReferencedType(C, *TypeAttr)
594-
: DieType());
609+
610+
appendQualifiedName(detail::unwrapReferencedTypedefType(C));
595611
}
596612
if (IsTemplate && *FirstParameter && FirstParameter == &FirstParameterValue) {
597613
OS << '<';

0 commit comments

Comments
 (0)