Commit 36c2a14c by Chris Mihelich Committed by Copybara-Service

Demangle unofficial <unresolved-qualifier-level> encodings like S0_IT_E.

PiperOrigin-RevId: 638430573
Change-Id: Ifc4d93bc4ea30951404546436f5397c8fb1bda57
parent 65a55c2b
......@@ -612,6 +612,7 @@ static bool ParseTemplateArgs(State *state);
static bool ParseTemplateArg(State *state);
static bool ParseBaseUnresolvedName(State *state);
static bool ParseUnresolvedName(State *state);
static bool ParseUnresolvedQualifierLevel(State *state);
static bool ParseUnionSelector(State* state);
static bool ParseFunctionParam(State* state);
static bool ParseBracedExpression(State *state);
......@@ -1826,7 +1827,7 @@ static bool ParseUnresolvedName(State *state) {
if (ParseTwoCharToken(state, "sr") && ParseOneCharToken(state, 'N') &&
ParseUnresolvedType(state) &&
OneOrMore(/* <unresolved-qualifier-level> ::= */ ParseSimpleId, state) &&
OneOrMore(ParseUnresolvedQualifierLevel, state) &&
ParseOneCharToken(state, 'E') && ParseBaseUnresolvedName(state)) {
return true;
}
......@@ -1834,7 +1835,7 @@ static bool ParseUnresolvedName(State *state) {
if (Optional(ParseTwoCharToken(state, "gs")) &&
ParseTwoCharToken(state, "sr") &&
OneOrMore(/* <unresolved-qualifier-level> ::= */ ParseSimpleId, state) &&
OneOrMore(ParseUnresolvedQualifierLevel, state) &&
ParseOneCharToken(state, 'E') && ParseBaseUnresolvedName(state)) {
return true;
}
......@@ -1843,6 +1844,29 @@ static bool ParseUnresolvedName(State *state) {
return false;
}
// <unresolved-qualifier-level> ::= <simple-id>
// ::= <substitution> <template-args>
//
// The production <substitution> <template-args> is nonstandard but is observed
// in practice. An upstream discussion on the best shape of <unresolved-name>
// has not converged:
//
// https://github.com/itanium-cxx-abi/cxx-abi/issues/38
static bool ParseUnresolvedQualifierLevel(State *state) {
ComplexityGuard guard(state);
if (guard.IsTooComplex()) return false;
if (ParseSimpleId(state)) return true;
ParseState copy = state->parse_state;
if (ParseSubstitution(state, /*accept_std=*/false) &&
ParseTemplateArgs(state)) {
return true;
}
state->parse_state = copy;
return false;
}
// <union-selector> ::= _ [<number>]
//
// https://github.com/itanium-cxx-abi/cxx-abi/issues/47
......
......@@ -372,6 +372,21 @@ TEST(Demangle, SubstpackNotationForTroublesomeTemplatePack) {
EXPECT_STREQ(tmp, "A<>::f<>()");
}
TEST(Demangle, TemplateTemplateParamAppearingAsBackrefFollowedByTemplateArgs) {
char tmp[100];
// Source:
//
// template <template <class> class C> struct W {
// template <class T> static decltype(C<T>::m()) f() { return {}; }
// };
//
// template <class T> struct S { static int m() { return 0; } };
// template decltype(S<int>::m()) W<S>::f<int>();
ASSERT_TRUE(Demangle("_ZN1WI1SE1fIiEEDTclsrS0_IT_EE1mEEv", tmp, sizeof(tmp)));
EXPECT_STREQ(tmp, "W<>::f<>()");
}
// Test corner cases of boundary conditions.
TEST(Demangle, CornerCases) {
char tmp[10];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment