diff --git a/libiberty/d-demangle.c b/libiberty/d-demangle.c index d74cf47b1a9..a2152cc6551 100644 --- a/libiberty/d-demangle.c +++ b/libiberty/d-demangle.c @@ -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); } diff --git a/libiberty/testsuite/d-demangle-expected b/libiberty/testsuite/d-demangle-expected index 87ed8d330a8..c35185c3e1e 100644 --- a/libiberty/testsuite/d-demangle-expected +++ b/libiberty/testsuite/d-demangle-expected @@ -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