Skip to content

Commit

Permalink
[demangler] Fix node matchers
Browse files Browse the repository at this point in the history
* Add instantiation tests to ItaniumDemangleTest, to make sure all
  match functions provide constructor arguments to the provided functor.

* Fix the Node constructors that lost const qualification on arguments.

Reviewed By: dblaikie

Differential Revision: https://reviews.llvm.org/D122665
  • Loading branch information
urnathan committed Apr 1, 2022
1 parent de70ff1 commit abffdd8
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 10 deletions.
10 changes: 5 additions & 5 deletions libcxxabi/src/demangle/ItaniumDemangle.h
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ class PostfixQualifiedType final : public Node {
const StringView Postfix;

public:
PostfixQualifiedType(Node *Ty_, StringView Postfix_)
PostfixQualifiedType(const Node *Ty_, StringView Postfix_)
: Node(KPostfixQualifiedType), Ty(Ty_), Postfix(Postfix_) {}

template<typename Fn> void match(Fn F) const { F(Ty, Postfix); }
Expand Down Expand Up @@ -1047,9 +1047,8 @@ class VectorType final : public Node {
const Node *Dimension;

public:
VectorType(const Node *BaseType_, Node *Dimension_)
: Node(KVectorType), BaseType(BaseType_),
Dimension(Dimension_) {}
VectorType(const Node *BaseType_, const Node *Dimension_)
: Node(KVectorType), BaseType(BaseType_), Dimension(Dimension_) {}

template<typename Fn> void match(Fn F) const { F(BaseType, Dimension); }

Expand Down Expand Up @@ -1846,7 +1845,8 @@ class EnclosingExpr : public Node {
const StringView Postfix;

public:
EnclosingExpr(StringView Prefix_, Node *Infix_, Prec Prec_ = Prec::Primary)
EnclosingExpr(StringView Prefix_, const Node *Infix_,
Prec Prec_ = Prec::Primary)
: Node(KEnclosingExpr, Prec_), Prefix(Prefix_), Infix(Infix_) {}

template <typename Fn> void match(Fn F) const {
Expand Down
10 changes: 5 additions & 5 deletions llvm/include/llvm/Demangle/ItaniumDemangle.h
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ class PostfixQualifiedType final : public Node {
const StringView Postfix;

public:
PostfixQualifiedType(Node *Ty_, StringView Postfix_)
PostfixQualifiedType(const Node *Ty_, StringView Postfix_)
: Node(KPostfixQualifiedType), Ty(Ty_), Postfix(Postfix_) {}

template<typename Fn> void match(Fn F) const { F(Ty, Postfix); }
Expand Down Expand Up @@ -1047,9 +1047,8 @@ class VectorType final : public Node {
const Node *Dimension;

public:
VectorType(const Node *BaseType_, Node *Dimension_)
: Node(KVectorType), BaseType(BaseType_),
Dimension(Dimension_) {}
VectorType(const Node *BaseType_, const Node *Dimension_)
: Node(KVectorType), BaseType(BaseType_), Dimension(Dimension_) {}

template<typename Fn> void match(Fn F) const { F(BaseType, Dimension); }

Expand Down Expand Up @@ -1846,7 +1845,8 @@ class EnclosingExpr : public Node {
const StringView Postfix;

public:
EnclosingExpr(StringView Prefix_, Node *Infix_, Prec Prec_ = Prec::Primary)
EnclosingExpr(StringView Prefix_, const Node *Infix_,
Prec Prec_ = Prec::Primary)
: Node(KEnclosingExpr, Prec_), Prefix(Prefix_), Infix(Infix_) {}

template <typename Fn> void match(Fn F) const {
Expand Down
22 changes: 22 additions & 0 deletions llvm/unittests/Demangle/ItaniumDemangleTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,28 @@ class TestAllocator {
};
} // namespace

namespace {
// Make sure the node matchers provide constructor parameters. This is a
// compilation test.
template <typename NT> struct Ctor {
template <typename... Args> void operator()(Args &&...args) {
auto _ = NT(std::forward<Args>(args)...);
}
};

template <typename NT> void Visit(const NT *Node) { Node->match(Ctor<NT>{}); }
#define NOMATCHER(X) \
template <> void Visit<itanium_demangle::X>(const itanium_demangle::X *) {}
// Some nodes have no match member.
NOMATCHER(ForwardTemplateReference)
#undef NOMATCHER

void __attribute__((used)) Visitor() {
#define NODE(X) Visit(static_cast<const itanium_demangle::X *>(nullptr));
#include "llvm/Demangle/ItaniumNodes.def"
}
} // namespace

TEST(ItaniumDemangle, MethodOverride) {
struct TestParser : AbstractManglingParser<TestParser, TestAllocator> {
std::vector<char> Types;
Expand Down

0 comments on commit abffdd8

Please sign in to comment.