Page MenuHomePhabricator

Give microsoftDemangle() an outparam for how many input bytes were consumed.
ClosedPublic

Authored by thakis on Mon, May 18, 5:02 PM.

Details

Summary

Demangling Itanium symbols either consumes the whole input or fails,
but Microsoft symbols can be successfully demangled with just some
of the input.

Add an outparam that enables clients to know how much of the input was
consumed, andn use this flag to give llvm-undname an opt-in warning
on partially consumed symbols.

Diff Detail

Event Timeline

thakis created this revision.Mon, May 18, 5:02 PM
Herald added a reviewer: MaskRay. · View Herald Transcript
Herald added a project: Restricted Project. · View Herald Transcript
hans added a comment.Tue, May 19, 1:39 AM

Seems reasonable, but can you expand on when this comes up in practice?

llvm/include/llvm/Demangle/Demangle.h
50

s/to/too/

Sure! The motivation is that if you want to write something like c++filt that finds all symbols in text and replaces them with the demangled form, you'll have a loop like:

for each word w
  try to demangle w to demangled_w
  if that worked,
    print demangled_w
  else
    print w

For Itanium this works great since as far as I know if w is demangled successfully, it always consumes all of w. But with the Microsoft scheme, it's possible that we get a demangled_w successfully but only consume some prefix of w, and it'd be good to print the unconsumed suffix too. With the current API that's not (*) possible.

*: Well I suppose for each w that successfully demangles, you could hand in only the first half of w and see if that demangles too and binary search over prefixes to find the suffix. But since the data is right there in the demangler and we only have to get it out, adding a way to get it out seems better to me.

hans accepted this revision.Wed, May 20, 6:12 AM

Thanks! lgtm

nit in the commit message: "consumed, *andn* use this"

This revision is now accepted and ready to land.Wed, May 20, 6:12 AM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptWed, May 20, 1:44 PM