Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(demangle): support decltype(nullptr) and pack expansion #1018

Merged
merged 1 commit into from
Jan 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions src/demangle.cc
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ static const AbbrevPair kBuiltinTypeList[] = {
{"n", "__int128"}, {"o", "unsigned __int128"},
{"f", "float"}, {"d", "double"},
{"e", "long double"}, {"g", "__float128"},
{"z", "ellipsis"}, {nullptr, nullptr}};
{"z", "ellipsis"}, {"Dn", "decltype(nullptr)"},
{nullptr, nullptr}};

// List of substitutions Itanium C++ ABI.
static const AbbrevPair kSubstitutionList[] = {
Expand Down Expand Up @@ -1067,7 +1068,7 @@ static bool ParseTemplateArgs(State* state) {
// ::= X <expression> E
static bool ParseTemplateArg(State* state) {
// Avoid recursion above max_levels
constexpr uint32 max_levels = 5;
constexpr uint32 max_levels = 6;

if (state->arg_level > max_levels) {
return false;
Expand Down Expand Up @@ -1159,6 +1160,14 @@ static bool ParseExpression(State* state) {
return true;
}
*state = copy;

// Pack expansion
if (ParseTwoCharToken(state, "sp") && ParseType(state)) {
--state->expr_level;
return true;
}
*state = copy;

return false;
}

Expand Down Expand Up @@ -1286,7 +1295,7 @@ static bool ParseTopLevelMangledName(State* state) {
MaybeAppend(state, state->mangled_cur);
return true;
}
return false; // Unconsumed suffix.
return ParseName(state);
}
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion src/demangle_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,10 @@ TEST(Demangle, FromFile) {
#endif

int main(int argc, char** argv) {
InitGoogleTest(&argc, argv);
#ifdef GLOG_USE_GFLAGS
ParseCommandLineFlags(&argc, &argv, true);
#endif
InitGoogleTest(&argc, argv);

FLAGS_logtostderr = true;
InitGoogleLogging(argv[0]);
Expand Down
7 changes: 7 additions & 0 deletions src/demangle_unittest.txt
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,10 @@ _Zrm1XS_ operator%()
# Template argument packs can start with I or J.
_Z3addIIiEEvDpT_ add<>()
_Z3addIJiEEvDpT_ add<>()

# Nested templates with pack expansion
_ZSt13__invoke_implIvPFvPiEJDnEET_St14__invoke_otherOT0_DpOT1_ std::__invoke_impl<>()
_ZSt8__invokeIPFvPiEJDnEENSt15__invoke_resultIT_JDpT0_EE4typeEOS4_DpOS5_ std::__invoke<>()
_ZNSt6thread8_InvokerISt5tupleIJPFvPiEDnEEE9_M_invokeIJLm0ELm1EEEEvSt12_Index_tupleIJXspT_EEE std::thread::_Invoker<>::_M_invoke<>()
_ZNSt6thread8_InvokerISt5tupleIJPFvPiEDnEEEclEv std::thread::_Invoker<>::operator()()
_ZNSt6thread11_State_implINS_8_InvokerISt5tupleIJPFvPiEDnEEEEE6_M_runEv std::thread::_State_impl<>::_M_run()