c++: Fix demangling of <unresolved-name>
authorJason Merrill <jason@redhat.com>
Mon, 21 Dec 2020 22:36:25 +0000 (17:36 -0500)
committerJason Merrill <jason@redhat.com>
Tue, 22 Dec 2020 02:13:41 +0000 (21:13 -0500)
commit58fb912c15175f4444144b8a4ab52a4880b84994
tree30eb36cd8436ac5f9d9dc3d0b4f4e56018450252
parent93ac0c05ffc84acba8e73ed5238fc325044378e0
c++: Fix demangling of <unresolved-name>

The ABI for unresolved scoped names on the RHS of . and -> used to be

  sr <type> <unqualified-id>

That changed years ago to something more complex, but G++ was never updated.
This change was particularly incompatible for simple qualified-ids like
A::x, which were previously mangled as sr1A1x, and now sr1AE1x.

This obviously makes life hard for demanglers, which can't know whether to
consume that E or not.  To work around this, we now try demangling with the
newer ABI, and if that fails and we saw an "sr", try again with the older
ABI.

libiberty/ChangeLog:

PR c++/67343
* cp-demangle.h (struct d_info): Add unresolved_name_state.
* cp-demangle.c (d_prefix): Add subst parm.
(d_nested_name): Pass it.
(d_unresolved_name): Split out from...
(d_expression_1): ...here.
(d_demangle_callback): Maybe retry with old sr mangling.
* testsuite/demangle-expected: Add test.
libiberty/cp-demangle.c
libiberty/cp-demangle.h
libiberty/testsuite/demangle-expected