[llvm] abffdd8 - [demangler] Fix node matchers
Nathan Sidwell via llvm-commits
llvm-commits at lists.llvm.org
Fri Apr 1 05:19:56 PDT 2022
Author: Nathan Sidwell
Date: 2022-04-01T05:19:34-07:00
New Revision: abffdd88767791ef6da4d2df7ec7ab158eb8b775
URL: https://github.com/llvm/llvm-project/commit/abffdd88767791ef6da4d2df7ec7ab158eb8b775
DIFF: https://github.com/llvm/llvm-project/commit/abffdd88767791ef6da4d2df7ec7ab158eb8b775.diff
LOG: [demangler] Fix node matchers
* 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
Added:
Modified:
libcxxabi/src/demangle/ItaniumDemangle.h
llvm/include/llvm/Demangle/ItaniumDemangle.h
llvm/unittests/Demangle/ItaniumDemangleTest.cpp
Removed:
################################################################################
diff --git a/libcxxabi/src/demangle/ItaniumDemangle.h b/libcxxabi/src/demangle/ItaniumDemangle.h
index 4fc21817ee259..46b390bcd996a 100644
--- a/libcxxabi/src/demangle/ItaniumDemangle.h
+++ b/libcxxabi/src/demangle/ItaniumDemangle.h
@@ -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); }
@@ -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); }
@@ -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 {
diff --git a/llvm/include/llvm/Demangle/ItaniumDemangle.h b/llvm/include/llvm/Demangle/ItaniumDemangle.h
index f7ba53a1cb134..62e91fb2e9b9c 100644
--- a/llvm/include/llvm/Demangle/ItaniumDemangle.h
+++ b/llvm/include/llvm/Demangle/ItaniumDemangle.h
@@ -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); }
@@ -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); }
@@ -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 {
diff --git a/llvm/unittests/Demangle/ItaniumDemangleTest.cpp b/llvm/unittests/Demangle/ItaniumDemangleTest.cpp
index 9d9f683b36925..ddd988f45992a 100644
--- a/llvm/unittests/Demangle/ItaniumDemangleTest.cpp
+++ b/llvm/unittests/Demangle/ItaniumDemangleTest.cpp
@@ -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;
More information about the llvm-commits
mailing list