Commit 4a861bb1 by Chris Mihelich Committed by Copybara-Service

Demangle valueless literals LDnE (nullptr) and LA<number>_<type>E ("foo").

PiperOrigin-RevId: 637958502
Change-Id: If81eba9729c16b5d5ac7187cf74738d8aaace367
parent 90d49cba
......@@ -2040,10 +2040,35 @@ static bool ParseExprPrimary(State *state) {
return false;
}
// The merged cast production.
if (ParseOneCharToken(state, 'L') && ParseType(state) &&
ParseExprCastValueAndTrailingE(state)) {
return true;
if (ParseOneCharToken(state, 'L')) {
// There are two special cases in which a literal may or must contain a type
// without a value. The first is that both LDnE and LDn0E are valid
// encodings of nullptr, used in different situations. Recognize LDnE here,
// leaving LDn0E to be recognized by the general logic afterward.
if (ParseThreeCharToken(state, "DnE")) return true;
// The second special case is a string literal, currently mangled in C++98
// style as LA<length + 1>_KcE. This is inadequate to support C++11 and
// later versions, and the discussion of this problem has not converged.
//
// https://github.com/itanium-cxx-abi/cxx-abi/issues/64
//
// For now the bare-type mangling is what's used in practice, so we
// recognize this form and only this form if an array type appears here.
// Someday we'll probably have to accept a new form of value mangling in
// LA...E constructs. (Note also that C++20 allows a wide range of
// class-type objects as template arguments, so someday their values will be
// mangled and we'll have to recognize them here too.)
if (RemainingInput(state)[0] == 'A' /* an array type follows */) {
if (ParseType(state) && ParseOneCharToken(state, 'E')) return true;
state->parse_state = copy;
return false;
}
// The merged cast production.
if (ParseType(state) && ParseExprCastValueAndTrailingE(state)) {
return true;
}
}
state->parse_state = copy;
......
......@@ -375,6 +375,26 @@ TEST(Demangle, LiteralOfGlobalNamespaceEnumType) {
EXPECT_STREQ("f<>()", tmp);
}
TEST(Demangle, NullptrLiterals) {
char tmp[80];
// void f<nullptr>()
EXPECT_TRUE(Demangle("_Z1fILDnEEvv", tmp, sizeof(tmp)));
EXPECT_STREQ("f<>()", tmp);
// also void f<nullptr>()
EXPECT_TRUE(Demangle("_Z1fILDn0EEvv", tmp, sizeof(tmp)));
EXPECT_STREQ("f<>()", tmp);
}
TEST(Demangle, StringLiterals) {
char tmp[80];
// void f<"<char const [42]>">()
EXPECT_TRUE(Demangle("_Z1fILA42_KcEEvv", tmp, sizeof(tmp)));
EXPECT_STREQ("f<>()", tmp);
}
// Test the GNU abi_tag extension.
TEST(Demangle, AbiTags) {
char tmp[80];
......
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