[libc++abi] Enable demangling of cp expression production (#114882)

See itanium-cxx-abi/cxx-abi#196
This commit is contained in:
Hubert Tong 2024-12-10 20:24:15 -04:00 committed by GitHub
parent 9b6bb83860
commit 918d4558b0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 41 additions and 20 deletions

View File

@ -2077,17 +2077,23 @@ public:
class CallExpr : public Node { class CallExpr : public Node {
const Node *Callee; const Node *Callee;
NodeArray Args; NodeArray Args;
bool IsParen; // (func)(args ...) ?
public: public:
CallExpr(const Node *Callee_, NodeArray Args_, Prec Prec_) CallExpr(const Node *Callee_, NodeArray Args_, bool IsParen_, Prec Prec_)
: Node(KCallExpr, Prec_), Callee(Callee_), Args(Args_) {} : Node(KCallExpr, Prec_), Callee(Callee_), Args(Args_),
IsParen(IsParen_) {}
template <typename Fn> void match(Fn F) const { template <typename Fn> void match(Fn F) const {
F(Callee, Args, getPrecedence()); F(Callee, Args, IsParen, getPrecedence());
} }
void printLeft(OutputBuffer &OB) const override { void printLeft(OutputBuffer &OB) const override {
if (IsParen)
OB.printOpen();
Callee->print(OB); Callee->print(OB);
if (IsParen)
OB.printClose();
OB.printOpen(); OB.printOpen();
Args.printWithComma(OB); Args.printWithComma(OB);
OB.printClose(); OB.printClose();
@ -3354,9 +3360,12 @@ const typename AbstractManglingParser<
"operator co_await"}, "operator co_await"},
{"az", OperatorInfo::OfIdOp, /*Type*/ false, Node::Prec::Unary, "alignof "}, {"az", OperatorInfo::OfIdOp, /*Type*/ false, Node::Prec::Unary, "alignof "},
{"cc", OperatorInfo::NamedCast, false, Node::Prec::Postfix, "const_cast"}, {"cc", OperatorInfo::NamedCast, false, Node::Prec::Postfix, "const_cast"},
{"cl", OperatorInfo::Call, false, Node::Prec::Postfix, "operator()"}, {"cl", OperatorInfo::Call, /*Paren*/ false, Node::Prec::Postfix,
"operator()"},
{"cm", OperatorInfo::Binary, false, Node::Prec::Comma, "operator,"}, {"cm", OperatorInfo::Binary, false, Node::Prec::Comma, "operator,"},
{"co", OperatorInfo::Prefix, false, Node::Prec::Unary, "operator~"}, {"co", OperatorInfo::Prefix, false, Node::Prec::Unary, "operator~"},
{"cp", OperatorInfo::Call, /*Paren*/ true, Node::Prec::Postfix,
"operator()"},
{"cv", OperatorInfo::CCast, false, Node::Prec::Cast, "operator"}, // C Cast {"cv", OperatorInfo::CCast, false, Node::Prec::Cast, "operator"}, // C Cast
{"dV", OperatorInfo::Binary, false, Node::Prec::Assign, "operator/="}, {"dV", OperatorInfo::Binary, false, Node::Prec::Assign, "operator/="},
{"da", OperatorInfo::Del, /*Ary*/ true, Node::Prec::Unary, {"da", OperatorInfo::Del, /*Ary*/ true, Node::Prec::Unary,
@ -5099,6 +5108,7 @@ Node *AbstractManglingParser<Derived, Alloc>::parseRequiresExpr() {
// ::= <binary operator-name> <expression> <expression> // ::= <binary operator-name> <expression> <expression>
// ::= <ternary operator-name> <expression> <expression> <expression> // ::= <ternary operator-name> <expression> <expression> <expression>
// ::= cl <expression>+ E # call // ::= cl <expression>+ E # call
// ::= cp <base-unresolved-name> <expression>* E # (name) (expr-list), call that would use argument-dependent lookup but for the parentheses
// ::= cv <type> <expression> # conversion with one argument // ::= cv <type> <expression> # conversion with one argument
// ::= cv <type> _ <expression>* E # conversion with a different number of arguments // ::= cv <type> _ <expression>* E # conversion with a different number of arguments
// ::= [gs] nw <expression>* _ <type> E # new (expr-list) type // ::= [gs] nw <expression>* _ <type> E # new (expr-list) type
@ -5234,7 +5244,7 @@ Node *AbstractManglingParser<Derived, Alloc>::parseExpr() {
Names.push_back(E); Names.push_back(E);
} }
return make<CallExpr>(Callee, popTrailingNodeArray(ExprsBegin), return make<CallExpr>(Callee, popTrailingNodeArray(ExprsBegin),
Op->getPrecedence()); /*IsParen=*/Op->getFlag(), Op->getPrecedence());
} }
case OperatorInfo::CCast: { case OperatorInfo::CCast: {
// C Cast: (type)expr // C Cast: (type)expr
@ -5421,7 +5431,7 @@ Node *AbstractManglingParser<Derived, Alloc>::parseExpr() {
} }
} }
return make<CallExpr>(Name, popTrailingNodeArray(ExprsBegin), return make<CallExpr>(Name, popTrailingNodeArray(ExprsBegin),
Node::Prec::Postfix); /*IsParen=*/false, Node::Prec::Postfix);
} }
// Only unresolved names remain. // Only unresolved names remain.

View File

@ -29834,6 +29834,7 @@ const char* cases[][2] =
{"_ZN5Casts5auto_IiEEvDTnw_DapicvT__EEE", "void Casts::auto_<int>(decltype(new auto((int)())))"}, {"_ZN5Casts5auto_IiEEvDTnw_DapicvT__EEE", "void Casts::auto_<int>(decltype(new auto((int)())))"},
{"_ZN5Casts7scalar_IiEEvDTcmcvT__Ecvi_EE", "void Casts::scalar_<int>(decltype((int)(), (int)()))"}, {"_ZN5Casts7scalar_IiEEvDTcmcvT__Ecvi_EE", "void Casts::scalar_<int>(decltype((int)(), (int)()))"},
{"_ZN5test11aIsEEDTcl3foocvT__EEES1_", "decltype(foo((short)())) test1::a<short>(short)"}, {"_ZN5test11aIsEEDTcl3foocvT__EEES1_", "decltype(foo((short)())) test1::a<short>(short)"},
{"_ZN5test11bIsEEDTcp3foocvT__EEES1_", "decltype((foo)((short)())) test1::b<short>(short)"},
{"_ZN5test21aIPFfvEEEvT_DTclfL0p_EE", "void test2::a<float (*)()>(float (*)(), decltype(fp()))"}, {"_ZN5test21aIPFfvEEEvT_DTclfL0p_EE", "void test2::a<float (*)()>(float (*)(), decltype(fp()))"},
{"_ZN5test21bIPFfvEEEDTclfp_EET_", "decltype(fp()) test2::b<float (*)()>(float (*)())"}, {"_ZN5test21bIPFfvEEEDTclfp_EET_", "decltype(fp()) test2::b<float (*)()>(float (*)())"},
{"_ZN5test21cIPFfvEEEvT_PFvDTclfL1p_EEE", "void test2::c<float (*)()>(float (*)(), void (*)(decltype(fp())))"}, {"_ZN5test21cIPFfvEEEvT_PFvDTclfL1p_EEE", "void test2::c<float (*)()>(float (*)(), void (*)(decltype(fp())))"},
@ -30397,24 +30398,24 @@ void test_invalid_cases()
assert(!passed && "demangle did not fail"); assert(!passed && "demangle did not fail");
} }
const char *xfail_cases[] = { const char *const xfail_cases[] = {
// FIXME: Why does clang generate the "cp" expr? // Sentinel value
"_ZN5test11bIsEEDTcp3foocvT__EEES1_", nullptr
}; };
const size_t num_xfails = sizeof(xfail_cases) / sizeof(xfail_cases[0]);
void test_xfail_cases() void test_xfail_cases()
{ {
std::size_t len = 0; std::size_t len = 0;
char* buf = nullptr; char* buf = nullptr;
for (std::size_t i = 0; i < num_xfails; ++i) for (const char *c_str : xfail_cases)
{ {
if (!c_str)
break;
int status; int status;
char* demang = __cxxabiv1::__cxa_demangle(xfail_cases[i], buf, &len, &status); char* demang = __cxxabiv1::__cxa_demangle(c_str, buf, &len, &status);
if (status != -2) if (status != -2)
{ {
std::printf("%s was documented as xfail but passed\n", xfail_cases[i]); std::printf("%s was documented as xfail but passed\n", c_str);
std::printf("Got status = %d\n", status); std::printf("Got status = %d\n", status);
assert(status == -2); assert(status == -2);
} }

View File

@ -2077,17 +2077,23 @@ public:
class CallExpr : public Node { class CallExpr : public Node {
const Node *Callee; const Node *Callee;
NodeArray Args; NodeArray Args;
bool IsParen; // (func)(args ...) ?
public: public:
CallExpr(const Node *Callee_, NodeArray Args_, Prec Prec_) CallExpr(const Node *Callee_, NodeArray Args_, bool IsParen_, Prec Prec_)
: Node(KCallExpr, Prec_), Callee(Callee_), Args(Args_) {} : Node(KCallExpr, Prec_), Callee(Callee_), Args(Args_),
IsParen(IsParen_) {}
template <typename Fn> void match(Fn F) const { template <typename Fn> void match(Fn F) const {
F(Callee, Args, getPrecedence()); F(Callee, Args, IsParen, getPrecedence());
} }
void printLeft(OutputBuffer &OB) const override { void printLeft(OutputBuffer &OB) const override {
if (IsParen)
OB.printOpen();
Callee->print(OB); Callee->print(OB);
if (IsParen)
OB.printClose();
OB.printOpen(); OB.printOpen();
Args.printWithComma(OB); Args.printWithComma(OB);
OB.printClose(); OB.printClose();
@ -3354,9 +3360,12 @@ const typename AbstractManglingParser<
"operator co_await"}, "operator co_await"},
{"az", OperatorInfo::OfIdOp, /*Type*/ false, Node::Prec::Unary, "alignof "}, {"az", OperatorInfo::OfIdOp, /*Type*/ false, Node::Prec::Unary, "alignof "},
{"cc", OperatorInfo::NamedCast, false, Node::Prec::Postfix, "const_cast"}, {"cc", OperatorInfo::NamedCast, false, Node::Prec::Postfix, "const_cast"},
{"cl", OperatorInfo::Call, false, Node::Prec::Postfix, "operator()"}, {"cl", OperatorInfo::Call, /*Paren*/ false, Node::Prec::Postfix,
"operator()"},
{"cm", OperatorInfo::Binary, false, Node::Prec::Comma, "operator,"}, {"cm", OperatorInfo::Binary, false, Node::Prec::Comma, "operator,"},
{"co", OperatorInfo::Prefix, false, Node::Prec::Unary, "operator~"}, {"co", OperatorInfo::Prefix, false, Node::Prec::Unary, "operator~"},
{"cp", OperatorInfo::Call, /*Paren*/ true, Node::Prec::Postfix,
"operator()"},
{"cv", OperatorInfo::CCast, false, Node::Prec::Cast, "operator"}, // C Cast {"cv", OperatorInfo::CCast, false, Node::Prec::Cast, "operator"}, // C Cast
{"dV", OperatorInfo::Binary, false, Node::Prec::Assign, "operator/="}, {"dV", OperatorInfo::Binary, false, Node::Prec::Assign, "operator/="},
{"da", OperatorInfo::Del, /*Ary*/ true, Node::Prec::Unary, {"da", OperatorInfo::Del, /*Ary*/ true, Node::Prec::Unary,
@ -5099,6 +5108,7 @@ Node *AbstractManglingParser<Derived, Alloc>::parseRequiresExpr() {
// ::= <binary operator-name> <expression> <expression> // ::= <binary operator-name> <expression> <expression>
// ::= <ternary operator-name> <expression> <expression> <expression> // ::= <ternary operator-name> <expression> <expression> <expression>
// ::= cl <expression>+ E # call // ::= cl <expression>+ E # call
// ::= cp <base-unresolved-name> <expression>* E # (name) (expr-list), call that would use argument-dependent lookup but for the parentheses
// ::= cv <type> <expression> # conversion with one argument // ::= cv <type> <expression> # conversion with one argument
// ::= cv <type> _ <expression>* E # conversion with a different number of arguments // ::= cv <type> _ <expression>* E # conversion with a different number of arguments
// ::= [gs] nw <expression>* _ <type> E # new (expr-list) type // ::= [gs] nw <expression>* _ <type> E # new (expr-list) type
@ -5234,7 +5244,7 @@ Node *AbstractManglingParser<Derived, Alloc>::parseExpr() {
Names.push_back(E); Names.push_back(E);
} }
return make<CallExpr>(Callee, popTrailingNodeArray(ExprsBegin), return make<CallExpr>(Callee, popTrailingNodeArray(ExprsBegin),
Op->getPrecedence()); /*IsParen=*/Op->getFlag(), Op->getPrecedence());
} }
case OperatorInfo::CCast: { case OperatorInfo::CCast: {
// C Cast: (type)expr // C Cast: (type)expr
@ -5421,7 +5431,7 @@ Node *AbstractManglingParser<Derived, Alloc>::parseExpr() {
} }
} }
return make<CallExpr>(Name, popTrailingNodeArray(ExprsBegin), return make<CallExpr>(Name, popTrailingNodeArray(ExprsBegin),
Node::Prec::Postfix); /*IsParen=*/false, Node::Prec::Postfix);
} }
// Only unresolved names remain. // Only unresolved names remain.