Skip to content

Commit 0e07c77

Browse files
Update cp demangling to display parentheses; update test
1 parent 167a0dc commit 0e07c77

File tree

2 files changed

+21
-15
lines changed

2 files changed

+21
-15
lines changed

libcxxabi/src/demangle/ItaniumDemangle.h

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2077,17 +2077,25 @@ class SizeofParamPackExpr : public Node {
20772077
class CallExpr : public Node {
20782078
const Node *Callee;
20792079
NodeArray Args;
2080+
bool IsParen; // (func)(args ...) ?
20802081

20812082
public:
2082-
CallExpr(const Node *Callee_, NodeArray Args_, Prec Prec_)
2083-
: Node(KCallExpr, Prec_), Callee(Callee_), Args(Args_) {}
2083+
CallExpr(const Node *Callee_, NodeArray Args_, bool IsParen_, Prec Prec_)
2084+
: Node(KCallExpr, Prec_), Callee(Callee_), Args(Args_),
2085+
IsParen(IsParen_) {}
20842086

20852087
template <typename Fn> void match(Fn F) const {
20862088
F(Callee, Args, getPrecedence());
20872089
}
20882090

20892091
void printLeft(OutputBuffer &OB) const override {
2090-
Callee->print(OB);
2092+
if (IsParen) {
2093+
OB.printOpen();
2094+
Callee->print(OB);
2095+
OB.printClose();
2096+
} else {
2097+
Callee->print(OB);
2098+
}
20912099
OB.printOpen();
20922100
Args.printWithComma(OB);
20932101
OB.printClose();
@@ -3354,10 +3362,10 @@ const typename AbstractManglingParser<
33543362
"operator co_await"},
33553363
{"az", OperatorInfo::OfIdOp, /*Type*/ false, Node::Prec::Unary, "alignof "},
33563364
{"cc", OperatorInfo::NamedCast, false, Node::Prec::Postfix, "const_cast"},
3357-
{"cl", OperatorInfo::Call, false, Node::Prec::Postfix, "operator()"},
3365+
{"cl", OperatorInfo::Call, /*Paren*/ false, Node::Prec::Postfix, "operator()"},
33583366
{"cm", OperatorInfo::Binary, false, Node::Prec::Comma, "operator,"},
33593367
{"co", OperatorInfo::Prefix, false, Node::Prec::Unary, "operator~"},
3360-
{"cp", OperatorInfo::Call, false, Node::Prec::Postfix, "operator()"},
3368+
{"cp", OperatorInfo::Call, /*Paren*/ true, Node::Prec::Postfix, "operator()"},
33613369
{"cv", OperatorInfo::CCast, false, Node::Prec::Cast, "operator"}, // C Cast
33623370
{"dV", OperatorInfo::Binary, false, Node::Prec::Assign, "operator/="},
33633371
{"da", OperatorInfo::Del, /*Ary*/ true, Node::Prec::Unary,
@@ -5140,7 +5148,7 @@ Node *AbstractManglingParser<Derived, Alloc>::parseExpr() {
51405148
Names.push_back(E);
51415149
}
51425150
return make<CallExpr>(Callee, popTrailingNodeArray(ExprsBegin),
5143-
Op->getPrecedence());
5151+
/*IsParen=*/Op->getFlag(), Op->getPrecedence());
51445152
}
51455153
case OperatorInfo::CCast: {
51465154
// C Cast: (type)expr
@@ -5327,7 +5335,7 @@ Node *AbstractManglingParser<Derived, Alloc>::parseExpr() {
53275335
}
53285336
}
53295337
return make<CallExpr>(Name, popTrailingNodeArray(ExprsBegin),
5330-
Node::Prec::Postfix);
5338+
/*IsParen=*/false, Node::Prec::Postfix);
53315339
}
53325340

53335341
// Only unresolved names remain.

libcxxabi/test/test_demangle.pass.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29834,6 +29834,7 @@ const char* cases[][2] =
2983429834
{"_ZN5Casts5auto_IiEEvDTnw_DapicvT__EEE", "void Casts::auto_<int>(decltype(new auto((int)())))"},
2983529835
{"_ZN5Casts7scalar_IiEEvDTcmcvT__Ecvi_EE", "void Casts::scalar_<int>(decltype((int)(), (int)()))"},
2983629836
{"_ZN5test11aIsEEDTcl3foocvT__EEES1_", "decltype(foo((short)())) test1::a<short>(short)"},
29837+
{"_ZN5test11bIsEEDTcp3foocvT__EEES1_", "decltype((foo)((short)())) test1::b<short>(short)"},
2983729838
{"_ZN5test21aIPFfvEEEvT_DTclfL0p_EE", "void test2::a<float (*)()>(float (*)(), decltype(fp()))"},
2983829839
{"_ZN5test21bIPFfvEEEDTclfp_EET_", "decltype(fp()) test2::b<float (*)()>(float (*)())"},
2983929840
{"_ZN5test21cIPFfvEEEvT_PFvDTclfL1p_EEE", "void test2::c<float (*)()>(float (*)(), void (*)(decltype(fp())))"},
@@ -30371,24 +30372,21 @@ void test_invalid_cases()
3037130372
assert(!passed && "demangle did not fail");
3037230373
}
3037330374

30374-
const char *xfail_cases[] = {
30375-
// FIXME: Why does clang generate the "cp" expr?
30376-
"_ZN5test11bIsEEDTcp3foocvT__EEES1_",
30375+
const char *const xfail_cases[] = {
30376+
nullptr
3037730377
};
3037830378

30379-
const size_t num_xfails = sizeof(xfail_cases) / sizeof(xfail_cases[0]);
30380-
3038130379
void test_xfail_cases()
3038230380
{
3038330381
std::size_t len = 0;
3038430382
char* buf = nullptr;
30385-
for (std::size_t i = 0; i < num_xfails; ++i)
30383+
for (const char *const *it = xfail_cases; *it; ++it)
3038630384
{
3038730385
int status;
30388-
char* demang = __cxxabiv1::__cxa_demangle(xfail_cases[i], buf, &len, &status);
30386+
char* demang = __cxxabiv1::__cxa_demangle(*it, buf, &len, &status);
3038930387
if (status != -2)
3039030388
{
30391-
std::printf("%s was documented as xfail but passed\n", xfail_cases[i]);
30389+
std::printf("%s was documented as xfail but passed\n", *it);
3039230390
std::printf("Got status = %d\n", status);
3039330391
assert(status == -2);
3039430392
}

0 commit comments

Comments
 (0)