[PATCH] D49965: [MS Demangler] Demangle symbols in function local scopes

Zachary Turner via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Jul 29 10:46:01 PDT 2018


zturner created this revision.
zturner added reviewers: rnk, thakis, majnemer, ruiu.
Herald added subscribers: erik.pilkington, hiraditya.

There are a couple of issues you run into when you start getting into more complex names, especially with regards to function local statics.  When you've got something like:

  int x() {
    static int n = 0;
    return n;
  }

Then this needs to demangle to something like

  int `int __cdecl x()'::`1'::n

The nested mangled symbols (e.g. `int __cdecl x()` in the above example) also share state with regards to back-referencing, so we need to be able to re-use the demangler in the middle of demangling a symbol while sharing back-ref state.

To make matters more complicated, there are a lot of ambiguities when demangling a symbol's qualified name, because a function local scope pattern (usually something like `?1??name?`) looks suspiciously like many other possible things that can occur, such as `?1` meaning the second back-ref and disambiguating these cases is rather interesting.  the `?1?` in a local scope pattern is actually a special case of the more general pattern of `? + <encoded number> + ?`, where "encoded number" can itself have embedded `@` symbols, which is a common delimeter in mangled names.  So we have to take care during the disambiguation, which is the reason for the overly complicated `isLocalScopePattern` function in this patch.

I've added some pretty obnoxious tests to exercise all of this, which exposed several other problems related to back-referencing, so those are fixed here as well.  Finally, I've uncommented some tests that were previously marked as `FIXME`, since now these work.


https://reviews.llvm.org/D49965

Files:
  llvm/lib/Demangle/MicrosoftDemangle.cpp
  llvm/lib/Demangle/StringView.h
  llvm/test/Demangle/ms-mangle.test
  llvm/test/Demangle/ms-nested-scopes.test

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D49965.157890.patch
Type: text/x-patch
Size: 15315 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180729/b6f594e5/attachment.bin>


More information about the llvm-commits mailing list