[MS Demangler] Demangle symbols in function scopes.
authorZachary Turner <zturner@google.com>
Mon, 30 Jul 2018 03:12:34 +0000 (03:12 +0000)
committerZachary Turner <zturner@google.com>
Mon, 30 Jul 2018 03:12:34 +0000 (03:12 +0000)
commit71c91f948a81bffadd4697e2ab3508d6344d0411
tree161c5572042f4ef1e2c3554d0ca5ca10e8ab2917
parent8c40e40a85868166cbd801ae69cf675e471b5dd2
[MS Demangler] Demangle symbols in function scopes.

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.

Differential Revision: https://reviews.llvm.org/D49965

llvm-svn: 338226
llvm/lib/Demangle/MicrosoftDemangle.cpp
llvm/lib/Demangle/StringView.h
llvm/test/Demangle/ms-mangle.test
llvm/test/Demangle/ms-nested-scopes.test [new file with mode: 0644]