Skip to content

Add MSVC demangler correctness fixes and generated test corpus#8140

Closed
plafosse wants to merge 4 commits into
devfrom
test_ms_demangler_fixes
Closed

Add MSVC demangler correctness fixes and generated test corpus#8140
plafosse wants to merge 4 commits into
devfrom
test_ms_demangler_fixes

Conversation

@plafosse

@plafosse plafosse commented Apr 30, 2026

Copy link
Copy Markdown
Member

This should be considered a ground up re-write and so you probably won't get any value out of looking at diffs of the actual demangler. It pretty much solves all known demangler accuracy issues. And lays the ground work for more performance unlocks when we get the new simplifier integrated.

Major changes:

  • Demangling now is backed by the DemangledTypeNode like gnu3 is. The purpose is
    to provide an abstraction layer between c++ features and binary
    ninja's type objects.
  • Substantial performance increase I think around 3x what it was before
    this is due to cutting down on extraneous string copies and type object allocations
  • Substantial accuracy fixes. The most substantial of which is accurate scoping
    of back references.
  • Lots and lots of other small fixes. This commit could have been about 100 commits but
    I didn't feel that adding all those commits would be helpful in understanding what's
    actually going on here.
  • The msvc code roughly twice as fast even while bailing out way less than the previous version.

Fixes:

@plafosse plafosse self-assigned this Apr 30, 2026
@plafosse plafosse force-pushed the test_ms_demangler_fixes branch 3 times, most recently from 4b906ea to 15dd98a Compare May 6, 2026 19:34
@plafosse plafosse marked this pull request as ready for review May 7, 2026 14:48
@plafosse

Copy link
Copy Markdown
Member Author

I realized that bb9e720 and 7bfbb87 have regressed performance. And this needs some more changes so I'm converting it back to a draft :\

@plafosse plafosse marked this pull request as draft May 11, 2026 13:18
@plafosse plafosse force-pushed the test_ms_demangler_fixes branch 2 times, most recently from 1cd85f5 to 02cebd9 Compare May 21, 2026 19:43
@plafosse plafosse force-pushed the test_ms_demangler_fixes branch from 02cebd9 to 7862d28 Compare June 6, 2026 01:51
@plafosse plafosse marked this pull request as ready for review June 6, 2026 03:27
@plafosse plafosse requested a review from CouleeApps June 6, 2026 03:40
Comment thread demangler/msvc/demangle_msvc.h Outdated
#endif


#define MAX_DEMANGLE_LENGTH 262144

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason to remove the max length guard? I know the max nesting depth guard was added but that doesn't seem like it replaces this, and maximum length is a useful guardrail to have.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We would need to stringify just to check the length this was a huge source of slow down in the old version

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. It may still be worth having a length size check on individual nodes though. I'm not sure if the mangle format lets you specify token length in a way that would cause problems, but I wouldn't put it past it.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it might be worth it having a maximum node length

Comment thread plugins/rtti/rtti.cpp
@plafosse

Copy link
Copy Markdown
Member Author

Also fixes #8230 as we switched to a nesting guard rather than stringification max length

@plafosse plafosse force-pushed the test_ms_demangler_fixes branch from 2eb0f36 to 40d903f Compare June 22, 2026 23:41
plafosse added 3 commits June 22, 2026 19:51
Parse MSVC symbols into structured type nodes before finalization.
This keeps thunk suffixes, calling conventions, member pointers, and
implicit this parameters dependent on the final platform/view context.
Use shared demangler type nodes for substitutions and nested names.
This preserves structure for template arguments, expression arguments,
argument packs, and lambda auto parameters instead of relying on stale
formatted strings.
Share DemangledTypeNode across demangler implementations and add
MAX_DEMANGLE_NODE_LENGTH for bounded formatting.
@plafosse plafosse force-pushed the test_ms_demangler_fixes branch from 40d903f to c553290 Compare June 22, 2026 23:55
@plafosse

Copy link
Copy Markdown
Member Author

Merged in 5.4.9912

@plafosse plafosse closed this Jun 23, 2026
@plafosse plafosse deleted the test_ms_demangler_fixes branch June 23, 2026 19:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants