Commit 64457068 by Chris Mihelich Committed by Copybara-Service

Demangle Clang's last-resort notation _SUBSTPACK_.

PiperOrigin-RevId: 638283381
Change-Id: Icdd46801f530bd4e8083777c14c78593fd6e111d
parent 77d0ac71
......@@ -329,6 +329,22 @@ static bool ParseThreeCharToken(State *state, const char *three_char_token) {
return false;
}
// Returns true and advances "mangled_idx" if we find a copy of the
// NUL-terminated string "long_token" at "mangled_idx" position.
static bool ParseLongToken(State *state, const char *long_token) {
ComplexityGuard guard(state);
if (guard.IsTooComplex()) return false;
int i = 0;
for (; long_token[i] != '\0'; ++i) {
// Note that we cannot run off the end of the NUL-terminated input here.
// Inside the loop body, long_token[i] is known to be different from NUL.
// So if we read the NUL on the end of the input here, we return at once.
if (RemainingInput(state)[i] != long_token[i]) return false;
}
state->parse_state.mangled_idx += i;
return true;
}
// Returns true and advances "mangled_cur" if we find any character in
// "char_class" at "mangled_cur" position.
static bool ParseCharClass(State *state, const char *char_class) {
......@@ -1329,7 +1345,10 @@ static bool ParseType(State *state) {
}
state->parse_state = copy;
return false;
// For this notation see CXXNameMangler::mangleType in Clang's source code.
// The relevant logic and its comment "not clear how to mangle this!" date
// from 2011, so it may be with us awhile.
return ParseLongToken(state, "_SUBSTPACK_");
}
// <CV-qualifiers> ::= [r] [V] [K]
......
......@@ -353,6 +353,25 @@ TEST(Demangle, LambdaWithExplicitPackArgument) {
EXPECT_STREQ(tmp, "f<>()::{lambda()#1}::operator()<>()");
}
TEST(Demangle, SubstpackNotationForTroublesomeTemplatePack) {
char tmp[100];
// Source:
//
// template <template <class> class, template <class> class> struct B {};
//
// template <template <class> class... T> struct A {
// template <template <class> class... U> void f(B<T, U>&&...) {}
// };
//
// template void A<>::f<>();
//
// LLVM can't demangle its own _SUBSTPACK_ notation.
ASSERT_TRUE(Demangle("_ZN1AIJEE1fIJEEEvDpO1BI_SUBSTPACK_T_E",
tmp, sizeof(tmp)));
EXPECT_STREQ(tmp, "A<>::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