libiberty: Add support for demangling local D template declarations

The D language now allows multiple different template declarations in
the same function that have the same mangled name.  To make the mangled
names unique, a fake parent in the form `__Sddd' is added to the symbol.
This information is not important for the user, so the demangler now
handles and ignores it.

libiberty/ChangeLog:

	* d-demangle.c (dlang_identifier): Skip over fake parent manglings.
	* testsuite/d-demangle-expected: Add tests.
This commit is contained in:
Iain Buclaw 2021-08-29 20:26:06 +02:00
parent 34f3e0657a
commit 392e141079
2 changed files with 43 additions and 0 deletions

View File

@ -1044,6 +1044,25 @@ dlang_identifier (string *decl, const char *mangled, struct dlang_info *info)
&& (mangled[2] == 'T' || mangled[2] == 'U'))
return dlang_parse_template (decl, mangled, info, len);
/* There can be multiple different declarations in the same function that have
the same mangled name. To make the mangled names unique, a fake parent in
the form `__Sddd' is added to the symbol. */
if (len >= 4 && mangled[0] == '_' && mangled[1] == '_' && mangled[2] == 'S')
{
const char *numptr = mangled + 3;
while (numptr < (mangled + len) && ISDIGIT (*numptr))
numptr++;
if (mangled + len == numptr)
{
/* Skip over the fake parent. */
mangled += len;
return dlang_identifier (decl, mangled, info);
}
/* else demangle it as a plain identifier. */
}
return dlang_lname (decl, mangled, len);
}

View File

@ -1420,5 +1420,29 @@ _D3std3uni__T6toCaseS_DQvQt12toLowerIndexFNaNbNiNewZtVii1043S_DQCjQCi10toLowerTa
std.uni.toCase!(std.uni.toLowerIndex(dchar), 1043, std.uni.toLowerTab(ulong), std.ascii.toLower, immutable(char)[]).toCase(immutable(char)[]).__foreachbody2(ref ulong, ref dchar).__foreachbody3(ref dchar)
#
--format=dlang
_D8demangle4mainFZ1xi
demangle.main().x
#
--format=dlang
_D8demangle4mainFZ4__S11xi
demangle.main().x
#
--format=dlang
_D8demangle4mainFZ1fMFNaNbNiNfZv
demangle.main().f()
#
--format=dlang
_D8demangle4mainFZ4__S11fMFNaNbNiNfZv
demangle.main().f()
#
--format=dlang
_D3mod4funcFZ__T6nestedTiZQkMFNaNbNiNfZi
mod.func().nested!(int).nested()
#
--format=dlang
_D3mod4funcFZ__T6nestedTiZ4__S1QpMFNaNbNiNfZi
mod.func().nested!(int).nested()
#
--format=dlang
_D6mangle__T8fun21753VSQv6S21753S1f_DQBj10__lambda71MFNaNbNiNfZvZQCbQp
mangle.fun21753!(mangle.S21753(mangle.__lambda71())).fun21753