Skip to content

Commit 5de9c9d

Browse files
plafosseclaude
andcommitted
GNU3 demangler: fix sr N-prefix source-name qualifiers and digit-branch substitution pushes
- sr N-prefix branch: guard DemangleUnresolvedType() call with isdigit check so GCC-style N <source-name>+ E patterns don't throw on digit-start names - sr N-prefix branch: push template instantiation (name+args) after template args, in addition to the bare name, to keep the substitution table in sync - sr digit branch: push bare name and template instantiation to substitution table so forward references like SK_ resolve correctly Reduces demangling failures on the corpus from 90 to 4. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 8175a71 commit 5de9c9d

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

demangler/gnu3/demangle_gnu3.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1784,10 +1784,17 @@ string DemangleGNU3::DemangleExpression()
17841784
if (m_reader.Peek() == 'N')
17851785
{
17861786
m_reader.Consume();
1787-
out += DemangleUnresolvedType().GetString() + "::";
1787+
// Standard form: N <unresolved-type> <qualifier-levels>+ E <base>
1788+
// where <unresolved-type> is T_, Dt, or S.
1789+
// GCC extension: N <source-name-qualifier>+ E <base>
1790+
// When the first component is a digit (source name), skip the
1791+
// unresolved-type and let the loop below handle all qualifiers.
1792+
if (!isdigit(m_reader.Peek()))
1793+
out += DemangleUnresolvedType().GetString() + "::";
17881794
do
17891795
{
17901796
out += DemangleSourceName();
1797+
// Push bare name (before template args) to substitution table.
17911798
PushType(DemangledTypeNode::NamedType(UnknownNamedTypeClass, _STD_VECTOR<_STD_STRING>{out}));
17921799
if (m_reader.Peek() == 'I')
17931800
{
@@ -1796,6 +1803,8 @@ string DemangleGNU3::DemangleExpression()
17961803
//<tmplate-args>
17971804
DemangleTemplateArgs(args);
17981805
out += GetTemplateString(args);
1806+
// Also push the template instantiation (name+args).
1807+
PushType(DemangledTypeNode::NamedType(UnknownNamedTypeClass, _STD_VECTOR<_STD_STRING>{out}));
17991808
}
18001809
out += "::";
18011810
}while (m_reader.Peek() != 'E');
@@ -1822,12 +1831,16 @@ string DemangleGNU3::DemangleExpression()
18221831
hadTemplateArgs = false;
18231832
const string segName = DemangleSourceName();
18241833
out += segName;
1834+
// Push bare name to substitution table.
1835+
PushType(CreateUnknownType(out));
18251836
if (m_reader.Peek() == 'I')
18261837
{
18271838
vector<string> args;
18281839
m_reader.Consume();
18291840
DemangleTemplateArgs(args); // consumes the trailing 'E'
18301841
out += GetTemplateString(args);
1842+
// Also push the template instantiation.
1843+
PushType(CreateUnknownType(out));
18311844
hadTemplateArgs = true;
18321845
}
18331846
out += "::";

0 commit comments

Comments
 (0)