Skip to content

Commit 2612316

Browse files
authored
[ItaniumDemangle] Add template name to the substitutions list during demangling (#108538)
When demangling a template template parameter (`method<bool, Bar>(Bar<bool> b)`), the current demangler version first enters the template argument (`bool`) into the substitutions list, then the whole template specialization (`Bar<bool>`). The template name (`Bar`) never becomes a substitution candidate on its own. This is different when mangling. Mangling `method<bool, Bar>(Bar<bool> b, Bar<int> i)` substitutes the `Bar` in the second parameter with the substitution for `TemplateTemplateParmDecl`. This leads to a discrepancy between mangler and demangler, see #108009.
1 parent 3e0a76b commit 2612316

File tree

3 files changed

+5
-0
lines changed

3 files changed

+5
-0
lines changed

libcxxabi/src/demangle/ItaniumDemangle.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4450,6 +4450,7 @@ Node *AbstractManglingParser<Derived, Alloc>::parseType() {
44504450
// parse them, take the second production.
44514451

44524452
if (TryToParseTemplateArgs && look() == 'I') {
4453+
Subs.push_back(Result);
44534454
Node *TA = getDerived().parseTemplateArgs();
44544455
if (TA == nullptr)
44554456
return nullptr;

libcxxabi/test/test_demangle.pass.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30024,6 +30024,9 @@ const char* cases[][2] =
3002430024
// See https://github.com/itanium-cxx-abi/cxx-abi/issues/165.
3002530025
{"_ZN1C1fIiEEvDTtlNS_UlT_TL0__E_EEE", "void C::f<int>(decltype(C::'lambda'(int, auto){}))"},
3002630026

30027+
// See https://github.com/llvm/llvm-project/issues/108009.
30028+
{"_ZN3FooIiE6methodIb3BarEEvT0_IT_ES3_IiE", "void Foo<int>::method<bool, Bar>(Bar<bool>, Bar<int>)"},
30029+
3002730030
// C++20 class type non-type template parameters:
3002830031
{"_Z1fIXtl1BLPi0ELi1EEEEvv", "void f<B{(int*)0, 1}>()"},
3002930032
{"_Z1fIXtl1BLPi32EEEEvv", "void f<B{(int*)32}>()"},

llvm/include/llvm/Demangle/ItaniumDemangle.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4450,6 +4450,7 @@ Node *AbstractManglingParser<Derived, Alloc>::parseType() {
44504450
// parse them, take the second production.
44514451

44524452
if (TryToParseTemplateArgs && look() == 'I') {
4453+
Subs.push_back(Result);
44534454
Node *TA = getDerived().parseTemplateArgs();
44544455
if (TA == nullptr)
44554456
return nullptr;

0 commit comments

Comments
 (0)