[llvm-branch-commits] [clang] [clang][test] remove unused `run` overload in `BoundNodesCallback` (PR #94244)

2024-06-03 Thread Julian Schmidt via llvm-branch-commits

https://github.com/5chmidti created 
https://github.com/llvm/llvm-project/pull/94244

The overload that did not take the additional `ASTContext *` argument is 
unnecessary when the context could simply be commented out, as it is always 
passed to `run` from `VerifyMatcher::run`.
This patch removes the single-argument overload in favor of having a single 
overload.

>From 0c53f15ee5461f479bd8da88f1fba2aecad6430a Mon Sep 17 00:00:00 2001
From: Julian Schmidt 
Date: Sat, 1 Jun 2024 17:49:13 +0200
Subject: [PATCH] [clang][test] remove unused `run` overload in
 `BoundNodesCallback`

The overload that did not take the additional `ASTContext *` argument is
unnecessary when the context could simply be commented out, as it is
always passed to `run` from `VerifyMatcher::run`.
This patch removes the single-argument overload in favor of having a
single overload.
---
 clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp  | 2 --
 clang/unittests/ASTMatchers/ASTMatchersTest.h| 7 +--
 clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp | 9 +++--
 3 files changed, 4 insertions(+), 14 deletions(-)

diff --git a/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp 
b/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
index aed6a6408adc9..dd98fbdce3945 100644
--- a/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
+++ b/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
@@ -2030,8 +2030,6 @@ TEST_P(ASTMatchersTest,
 template 
 class VerifyAncestorHasChildIsEqual : public BoundNodesCallback {
 public:
-  bool run(const BoundNodes *Nodes) override { return false; }
-
   bool run(const BoundNodes *Nodes, ASTContext *Context) override {
 const T *Node = Nodes->getNodeAs("");
 return verify(*Nodes, *Context, Node);
diff --git a/clang/unittests/ASTMatchers/ASTMatchersTest.h 
b/clang/unittests/ASTMatchers/ASTMatchersTest.h
index e981299531574..ad2f5f355621c 100644
--- a/clang/unittests/ASTMatchers/ASTMatchersTest.h
+++ b/clang/unittests/ASTMatchers/ASTMatchersTest.h
@@ -28,7 +28,6 @@ using clang::tooling::runToolOnCodeWithArgs;
 class BoundNodesCallback {
 public:
   virtual ~BoundNodesCallback() {}
-  virtual bool run(const BoundNodes *BoundNodes) = 0;
   virtual bool run(const BoundNodes *BoundNodes, ASTContext *Context) = 0;
   virtual void onEndOfTranslationUnit() {}
 };
@@ -403,7 +402,7 @@ template  class VerifyIdIsBoundTo : public 
BoundNodesCallback {
 EXPECT_EQ("", Name);
   }
 
-  bool run(const BoundNodes *Nodes) override {
+  bool run(const BoundNodes *Nodes, ASTContext * /*Context*/) override {
 const BoundNodes::IDToNodeMap &M = Nodes->getMap();
 if (Nodes->getNodeAs(Id)) {
   ++Count;
@@ -426,10 +425,6 @@ template  class VerifyIdIsBoundTo : public 
BoundNodesCallback {
 return false;
   }
 
-  bool run(const BoundNodes *Nodes, ASTContext *Context) override {
-return run(Nodes);
-  }
-
 private:
   const std::string Id;
   const int ExpectedCount;
diff --git a/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp 
b/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
index ada3be287ed59..6bb402caa4d6d 100644
--- a/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
+++ b/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
@@ -5641,7 +5641,6 @@ TEST(HasParent, MatchesAllParents) {
 TEST(HasParent, NoDuplicateParents) {
   class HasDuplicateParents : public BoundNodesCallback {
   public:
-bool run(const BoundNodes *Nodes) override { return false; }
 bool run(const BoundNodes *Nodes, ASTContext *Context) override {
   const Stmt *Node = Nodes->getNodeAs("node");
   std::set Parents;
@@ -5850,16 +5849,14 @@ template  class VerifyMatchOnNode : public 
BoundNodesCallback {
 public:
   VerifyMatchOnNode(StringRef Id, const internal::Matcher &InnerMatcher,
 StringRef InnerId)
-: Id(Id), InnerMatcher(InnerMatcher), InnerId(InnerId) {
-  }
-
-  bool run(const BoundNodes *Nodes) override { return false; }
+  : Id(Id), InnerMatcher(InnerMatcher), InnerId(InnerId) {}
 
   bool run(const BoundNodes *Nodes, ASTContext *Context) override {
 const T *Node = Nodes->getNodeAs(Id);
 return selectFirst(InnerId, match(InnerMatcher, *Node, *Context)) !=
-  nullptr;
+   nullptr;
   }
+
 private:
   std::string Id;
   internal::Matcher InnerMatcher;

___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [clang][test] add testing for the AST matcher reference (PR #94248)

2024-06-03 Thread Julian Schmidt via llvm-branch-commits

5chmidti wrote:

CC @llvm/pr-subscribers-clang-tidy as stake-holders in matchers

https://github.com/llvm/llvm-project/pull/94248
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [clang][test] add testing for the AST matcher reference (PR #94248)

2024-06-03 Thread Julian Schmidt via llvm-branch-commits

https://github.com/5chmidti edited 
https://github.com/llvm/llvm-project/pull/94248
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [clang][test] add testing for the AST matcher reference (PR #94248)

2024-06-03 Thread Julian Schmidt via llvm-branch-commits

https://github.com/5chmidti edited 
https://github.com/llvm/llvm-project/pull/94248
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [clang][test] add testing for the AST matcher reference (PR #94248)

2024-06-03 Thread Julian Schmidt via llvm-branch-commits

https://github.com/5chmidti edited 
https://github.com/llvm/llvm-project/pull/94248
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [clang][test] remove unused `run` overload in `BoundNodesCallback` (PR #94244)

2024-06-03 Thread Julian Schmidt via llvm-branch-commits

https://github.com/5chmidti updated 
https://github.com/llvm/llvm-project/pull/94244

>From 615f30ba7db2bb13d20b4c2a8c0d405a8419ecae Mon Sep 17 00:00:00 2001
From: Julian Schmidt 
Date: Sat, 1 Jun 2024 17:49:13 +0200
Subject: [PATCH] [clang][test] remove unused `run` overload in
 `BoundNodesCallback`

The overload that did not take the additional `ASTContext *` argument is
unnecessary when the context could simply be commented out, as it is
always passed to `run` from `VerifyMatcher::run`.
This patch removes the single-argument overload in favor of having a
single overload.
---
 clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp  | 2 --
 clang/unittests/ASTMatchers/ASTMatchersTest.h| 7 +--
 clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp | 9 +++--
 3 files changed, 4 insertions(+), 14 deletions(-)

diff --git a/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp 
b/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
index aed6a6408adc9..dd98fbdce3945 100644
--- a/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
+++ b/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
@@ -2030,8 +2030,6 @@ TEST_P(ASTMatchersTest,
 template 
 class VerifyAncestorHasChildIsEqual : public BoundNodesCallback {
 public:
-  bool run(const BoundNodes *Nodes) override { return false; }
-
   bool run(const BoundNodes *Nodes, ASTContext *Context) override {
 const T *Node = Nodes->getNodeAs("");
 return verify(*Nodes, *Context, Node);
diff --git a/clang/unittests/ASTMatchers/ASTMatchersTest.h 
b/clang/unittests/ASTMatchers/ASTMatchersTest.h
index e981299531574..ad2f5f355621c 100644
--- a/clang/unittests/ASTMatchers/ASTMatchersTest.h
+++ b/clang/unittests/ASTMatchers/ASTMatchersTest.h
@@ -28,7 +28,6 @@ using clang::tooling::runToolOnCodeWithArgs;
 class BoundNodesCallback {
 public:
   virtual ~BoundNodesCallback() {}
-  virtual bool run(const BoundNodes *BoundNodes) = 0;
   virtual bool run(const BoundNodes *BoundNodes, ASTContext *Context) = 0;
   virtual void onEndOfTranslationUnit() {}
 };
@@ -403,7 +402,7 @@ template  class VerifyIdIsBoundTo : public 
BoundNodesCallback {
 EXPECT_EQ("", Name);
   }
 
-  bool run(const BoundNodes *Nodes) override {
+  bool run(const BoundNodes *Nodes, ASTContext * /*Context*/) override {
 const BoundNodes::IDToNodeMap &M = Nodes->getMap();
 if (Nodes->getNodeAs(Id)) {
   ++Count;
@@ -426,10 +425,6 @@ template  class VerifyIdIsBoundTo : public 
BoundNodesCallback {
 return false;
   }
 
-  bool run(const BoundNodes *Nodes, ASTContext *Context) override {
-return run(Nodes);
-  }
-
 private:
   const std::string Id;
   const int ExpectedCount;
diff --git a/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp 
b/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
index ada3be287ed59..6bb402caa4d6d 100644
--- a/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
+++ b/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
@@ -5641,7 +5641,6 @@ TEST(HasParent, MatchesAllParents) {
 TEST(HasParent, NoDuplicateParents) {
   class HasDuplicateParents : public BoundNodesCallback {
   public:
-bool run(const BoundNodes *Nodes) override { return false; }
 bool run(const BoundNodes *Nodes, ASTContext *Context) override {
   const Stmt *Node = Nodes->getNodeAs("node");
   std::set Parents;
@@ -5850,16 +5849,14 @@ template  class VerifyMatchOnNode : public 
BoundNodesCallback {
 public:
   VerifyMatchOnNode(StringRef Id, const internal::Matcher &InnerMatcher,
 StringRef InnerId)
-: Id(Id), InnerMatcher(InnerMatcher), InnerId(InnerId) {
-  }
-
-  bool run(const BoundNodes *Nodes) override { return false; }
+  : Id(Id), InnerMatcher(InnerMatcher), InnerId(InnerId) {}
 
   bool run(const BoundNodes *Nodes, ASTContext *Context) override {
 const T *Node = Nodes->getNodeAs(Id);
 return selectFirst(InnerId, match(InnerMatcher, *Node, *Context)) !=
-  nullptr;
+   nullptr;
   }
+
 private:
   std::string Id;
   internal::Matcher InnerMatcher;

___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [clang][test] add testing for the AST matcher reference (PR #94248)

2024-06-04 Thread Julian Schmidt via llvm-branch-commits

https://github.com/5chmidti edited 
https://github.com/llvm/llvm-project/pull/94248
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [clang][test] add testing for the AST matcher reference (PR #94248)

2024-06-04 Thread Julian Schmidt via llvm-branch-commits

https://github.com/5chmidti edited 
https://github.com/llvm/llvm-project/pull/94248
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [clang][test] add testing for the AST matcher reference (PR #94248)

2024-06-04 Thread Julian Schmidt via llvm-branch-commits

https://github.com/5chmidti edited 
https://github.com/llvm/llvm-project/pull/94248
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [clang][test] add testing for the AST matcher reference (PR #94248)

2024-06-04 Thread Julian Schmidt via llvm-branch-commits


@@ -176,11 +176,13 @@ inline internal::TrueMatcher anything() { return 
internal::TrueMatcher(); }
 /// \code
 ///   int X;
 ///   namespace NS {
-///   int Y;
+/// int Y;
 ///   }  // namespace NS
 /// \endcode
-/// decl(hasDeclContext(translationUnitDecl()))
-///   matches "int X", but not "int Y".
+/// \compile_args{-std=c++}
+/// The matcher \matcher{namedDecl(hasDeclContext(translationUnitDecl()))}
+/// matches \match{type=name$X} and \match{type=name$NS},

5chmidti wrote:

Using `type=name` can be generally considered to be a 
style/readability/expressiveness choice if the AST node supports it. The `X` 
example would probably be better spelling the declaration out, the same goes 
for `Y` (probably remnants of the early days). There may be other trivial 
examples that could be spelled out. 

There are for sure some more trivial cases which could be spelled out. I'll 
check on the documentation again tomorrow and provide some updates (also w.r.t 
to your other comment).

If we wanted to spell out the namespace, we could, but that would require 
writing the `NS` in a single line. It's an artificial limitation in the script 
that can probably be implemented if we want to have the option.

https://github.com/llvm/llvm-project/pull/94248
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [clang][test] add testing for the AST matcher reference (PR #94248)

2024-06-04 Thread Julian Schmidt via llvm-branch-commits

https://github.com/5chmidti commented:

> I wonder if we should add some documentation to ASTMatchers.h

I'll add one in a day or so. I updated the description with some more 
information, and I'll probably take parts of that as a basis for the comment in 
the header (and update the script comment as well).

> so that users who hit test failures with the new automatic tests have some 
> more help getting to a solution.

There is now a `What if ...?` section to the pr description, which I will put 
into the header comment as well.

https://github.com/llvm/llvm-project/pull/94248
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [clang][test] add testing for the AST matcher reference (PR #94248)

2024-06-04 Thread Julian Schmidt via llvm-branch-commits


@@ -330,35 +377,46 @@ AST_POLYMORPHIC_MATCHER_P(isExpandedFromMacro,
 
 /// Matches declarations.
 ///
-/// Examples matches \c X, \c C, and the friend declaration inside \c C;
+/// Given
 /// \code
 ///   void X();
 ///   class C {
-/// friend X;
+/// friend void X();
 ///   };
 /// \endcode
+/// \compile_args{-std=c++}
+/// The matcher \matcher{decl()}
+/// matches \match{void X()}, \match{type=name;count=2$C}
+/// and \match{count=2$friend void X()}.

5chmidti wrote:

```
|-FunctionDecl  col:6 X 'void ()'
`-CXXRecordDecl  line:2:7 class C definition
  |-DefinitionData pass_in_registers empty aggregate standard_layout 
trivially_copyable pod trivial literal has_constexpr_non_copy_move_ctor 
can_const_default_init
  | |-DefaultConstructor exists trivial constexpr needs_implicit 
defaulted_is_constexpr
  | |-CopyConstructor simple trivial has_const_param needs_implicit 
implicit_has_const_param
  | |-MoveConstructor exists simple trivial needs_implicit
  | |-CopyAssignment simple trivial has_const_param needs_implicit 
implicit_has_const_param
  | |-MoveAssignment exists simple trivial needs_implicit
  | `-Destructor simple irrelevant trivial needs_implicit
  |-CXXRecordDecl  col:7 implicit class C
  `-FriendDecl  col:17
`-FunctionDecl parent 0xf23a388 prev 0xf284370  col:17 
friend X 'void ()'
```

> Can you explain `\match{type=name;count=2$C}`?

That is the `implicit class C` in the AST above. I couldn't access it from the 
top-level `C` and I couldn't find a way from the `implicit class C` back to the 
top-level one, so I don't know how to call it. I thought it would be a decl but 
not a definition, however, `getDefinition` returns a `nullptr` for the 
`implicit class C`.

> should we add a comment explaining that other match?

Certainly. I'll read the documentation again to see if there are more cases 
like this that could be improved as well.

https://github.com/llvm/llvm-project/pull/94248
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [clang][test] add testing for the AST matcher reference (PR #94248)

2024-06-08 Thread Julian Schmidt via llvm-branch-commits

5chmidti wrote:

- added a file-level comment in the ASTMatcher.h file on how the syntax works 
(basically the pr description)
- replaced some `type=name` matches with explicit code matches where 
applicable, to be more expressive
- added comments to `count=` matches when they didn't explain why or if there 
were multiple matches

https://github.com/llvm/llvm-project/pull/94248
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [clang][test] add testing for the AST matcher reference (PR #94248)

2024-07-02 Thread Julian Schmidt via llvm-branch-commits

5chmidti wrote:

Thanks.

> ... how this impacts build times for Clang itself? I'm assuming that if 
> ASTMatchers.h isn't modified, CMake won't re-run 
> generate_ast_matcher_doc_tests.py and so the compile time performance hit is 
> only on full rebuilds or when changing the header?

The 'state' of the generated file is only checked when the `ASTMatchersTests` 
target is built, because it's the only thing that depends on the generated 
file. And the file is only generated when: the file does not exist or 
`ASTMatchers.h` has changed (excluding transitive changes in includes) or 
`generate_ast_matcher_doc_tests.py` has changed.

https://github.com/llvm/llvm-project/pull/94248
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [clang][test] add testing for the AST matcher reference (PR #94248)

2024-07-03 Thread Julian Schmidt via llvm-branch-commits

5chmidti wrote:

> Do you need me to land the changes on your behalf?

No need, I can do that. However, this PR is in a stack and depends on two small 
PRs: #94244 and #94243 that need to be reviewed before this PR can be merged

https://github.com/llvm/llvm-project/pull/94248
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [clang][test] remove unused `run` overload in `BoundNodesCallback` (PR #94244)

2024-07-12 Thread Julian Schmidt via llvm-branch-commits

https://github.com/5chmidti updated 
https://github.com/llvm/llvm-project/pull/94244

>From 51de6278688635cdcd5a8dd73a2ef0ede2a31b37 Mon Sep 17 00:00:00 2001
From: Julian Schmidt 
Date: Sat, 1 Jun 2024 17:49:13 +0200
Subject: [PATCH] [clang][test] remove unused `run` overload in
 `BoundNodesCallback`

The overload that did not take the additional `ASTContext *` argument is
unnecessary when the context could simply be commented out, as it is
always passed to `run` from `VerifyMatcher::run`.
This patch removes the single-argument overload in favor of having a
single overload.
---
 clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp  | 2 --
 clang/unittests/ASTMatchers/ASTMatchersTest.h| 7 +--
 clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp | 9 +++--
 3 files changed, 4 insertions(+), 14 deletions(-)

diff --git a/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp 
b/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
index 3295ad1e21455..ebf548eb25431 100644
--- a/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
+++ b/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
@@ -2030,8 +2030,6 @@ TEST_P(ASTMatchersTest,
 template 
 class VerifyAncestorHasChildIsEqual : public BoundNodesCallback {
 public:
-  bool run(const BoundNodes *Nodes) override { return false; }
-
   bool run(const BoundNodes *Nodes, ASTContext *Context) override {
 const T *Node = Nodes->getNodeAs("");
 return verify(*Nodes, *Context, Node);
diff --git a/clang/unittests/ASTMatchers/ASTMatchersTest.h 
b/clang/unittests/ASTMatchers/ASTMatchersTest.h
index e981299531574..ad2f5f355621c 100644
--- a/clang/unittests/ASTMatchers/ASTMatchersTest.h
+++ b/clang/unittests/ASTMatchers/ASTMatchersTest.h
@@ -28,7 +28,6 @@ using clang::tooling::runToolOnCodeWithArgs;
 class BoundNodesCallback {
 public:
   virtual ~BoundNodesCallback() {}
-  virtual bool run(const BoundNodes *BoundNodes) = 0;
   virtual bool run(const BoundNodes *BoundNodes, ASTContext *Context) = 0;
   virtual void onEndOfTranslationUnit() {}
 };
@@ -403,7 +402,7 @@ template  class VerifyIdIsBoundTo : public 
BoundNodesCallback {
 EXPECT_EQ("", Name);
   }
 
-  bool run(const BoundNodes *Nodes) override {
+  bool run(const BoundNodes *Nodes, ASTContext * /*Context*/) override {
 const BoundNodes::IDToNodeMap &M = Nodes->getMap();
 if (Nodes->getNodeAs(Id)) {
   ++Count;
@@ -426,10 +425,6 @@ template  class VerifyIdIsBoundTo : public 
BoundNodesCallback {
 return false;
   }
 
-  bool run(const BoundNodes *Nodes, ASTContext *Context) override {
-return run(Nodes);
-  }
-
 private:
   const std::string Id;
   const int ExpectedCount;
diff --git a/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp 
b/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
index 3c033638960de..97355d22dd72b 100644
--- a/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
+++ b/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
@@ -5641,7 +5641,6 @@ TEST(HasParent, MatchesAllParents) {
 TEST(HasParent, NoDuplicateParents) {
   class HasDuplicateParents : public BoundNodesCallback {
   public:
-bool run(const BoundNodes *Nodes) override { return false; }
 bool run(const BoundNodes *Nodes, ASTContext *Context) override {
   const Stmt *Node = Nodes->getNodeAs("node");
   std::set Parents;
@@ -5850,16 +5849,14 @@ template  class VerifyMatchOnNode : public 
BoundNodesCallback {
 public:
   VerifyMatchOnNode(StringRef Id, const internal::Matcher &InnerMatcher,
 StringRef InnerId)
-: Id(Id), InnerMatcher(InnerMatcher), InnerId(InnerId) {
-  }
-
-  bool run(const BoundNodes *Nodes) override { return false; }
+  : Id(Id), InnerMatcher(InnerMatcher), InnerId(InnerId) {}
 
   bool run(const BoundNodes *Nodes, ASTContext *Context) override {
 const T *Node = Nodes->getNodeAs(Id);
 return selectFirst(InnerId, match(InnerMatcher, *Node, *Context)) !=
-  nullptr;
+   nullptr;
   }
+
 private:
   std::string Id;
   internal::Matcher InnerMatcher;

___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [clang][test] remove unused `run` overload in `BoundNodesCallback` (PR #94244)

2024-07-12 Thread Julian Schmidt via llvm-branch-commits

5chmidti wrote:

rebase on trunk + rebased stack

https://github.com/llvm/llvm-project/pull/94244
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [clang][test] add testing for the AST matcher reference (PR #94248)

2024-07-12 Thread Julian Schmidt via llvm-branch-commits

5chmidti wrote:

rebase on trunk + rebased stack

https://github.com/llvm/llvm-project/pull/94248
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [clang][test] remove unused `run` overload in `BoundNodesCallback` (PR #94244)

2024-07-12 Thread Julian Schmidt via llvm-branch-commits

https://github.com/5chmidti updated 
https://github.com/llvm/llvm-project/pull/94244

>From 26d5b0377af3df4c551ae16d053684bb8c75e233 Mon Sep 17 00:00:00 2001
From: Julian Schmidt 
Date: Sat, 1 Jun 2024 17:49:13 +0200
Subject: [PATCH] [clang][test] remove unused `run` overload in
 `BoundNodesCallback`

The overload that did not take the additional `ASTContext *` argument is
unnecessary when the context could simply be commented out, as it is
always passed to `run` from `VerifyMatcher::run`.
This patch removes the single-argument overload in favor of having a
single overload.
---
 .../unittests/ASTMatchers/ASTMatchersNodeTest.cpp |  2 --
 clang/unittests/ASTMatchers/ASTMatchersTest.h |  7 +--
 .../ASTMatchers/ASTMatchersTraversalTest.cpp  | 15 ---
 3 files changed, 5 insertions(+), 19 deletions(-)

diff --git a/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp 
b/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
index 3295ad1e2145..ebf548eb2543 100644
--- a/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
+++ b/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
@@ -2030,8 +2030,6 @@ TEST_P(ASTMatchersTest,
 template 
 class VerifyAncestorHasChildIsEqual : public BoundNodesCallback {
 public:
-  bool run(const BoundNodes *Nodes) override { return false; }
-
   bool run(const BoundNodes *Nodes, ASTContext *Context) override {
 const T *Node = Nodes->getNodeAs("");
 return verify(*Nodes, *Context, Node);
diff --git a/clang/unittests/ASTMatchers/ASTMatchersTest.h 
b/clang/unittests/ASTMatchers/ASTMatchersTest.h
index e98129953157..ad2f5f355621 100644
--- a/clang/unittests/ASTMatchers/ASTMatchersTest.h
+++ b/clang/unittests/ASTMatchers/ASTMatchersTest.h
@@ -28,7 +28,6 @@ using clang::tooling::runToolOnCodeWithArgs;
 class BoundNodesCallback {
 public:
   virtual ~BoundNodesCallback() {}
-  virtual bool run(const BoundNodes *BoundNodes) = 0;
   virtual bool run(const BoundNodes *BoundNodes, ASTContext *Context) = 0;
   virtual void onEndOfTranslationUnit() {}
 };
@@ -403,7 +402,7 @@ template  class VerifyIdIsBoundTo : public 
BoundNodesCallback {
 EXPECT_EQ("", Name);
   }
 
-  bool run(const BoundNodes *Nodes) override {
+  bool run(const BoundNodes *Nodes, ASTContext * /*Context*/) override {
 const BoundNodes::IDToNodeMap &M = Nodes->getMap();
 if (Nodes->getNodeAs(Id)) {
   ++Count;
@@ -426,10 +425,6 @@ template  class VerifyIdIsBoundTo : public 
BoundNodesCallback {
 return false;
   }
 
-  bool run(const BoundNodes *Nodes, ASTContext *Context) override {
-return run(Nodes);
-  }
-
 private:
   const std::string Id;
   const int ExpectedCount;
diff --git a/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp 
b/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
index 3c033638960d..d887c5ba8f05 100644
--- a/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
+++ b/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
@@ -5641,7 +5641,6 @@ TEST(HasParent, MatchesAllParents) {
 TEST(HasParent, NoDuplicateParents) {
   class HasDuplicateParents : public BoundNodesCallback {
   public:
-bool run(const BoundNodes *Nodes) override { return false; }
 bool run(const BoundNodes *Nodes, ASTContext *Context) override {
   const Stmt *Node = Nodes->getNodeAs("node");
   std::set Parents;
@@ -5850,16 +5849,14 @@ template  class VerifyMatchOnNode : public 
BoundNodesCallback {
 public:
   VerifyMatchOnNode(StringRef Id, const internal::Matcher &InnerMatcher,
 StringRef InnerId)
-: Id(Id), InnerMatcher(InnerMatcher), InnerId(InnerId) {
-  }
-
-  bool run(const BoundNodes *Nodes) override { return false; }
+  : Id(Id), InnerMatcher(InnerMatcher), InnerId(InnerId) {}
 
   bool run(const BoundNodes *Nodes, ASTContext *Context) override {
 const T *Node = Nodes->getNodeAs(Id);
 return selectFirst(InnerId, match(InnerMatcher, *Node, *Context)) !=
-  nullptr;
+   nullptr;
   }
+
 private:
   std::string Id;
   internal::Matcher InnerMatcher;
@@ -6053,7 +6050,7 @@ namespace {
 class ForCallablePreservesBindingWithMultipleParentsTestCallback
 : public BoundNodesCallback {
 public:
-  bool run(const BoundNodes *BoundNodes) override {
+  bool run(const BoundNodes *BoundNodes, ASTContext *Context) override {
 FunctionDecl const *FunDecl =
 BoundNodes->getNodeAs("funDecl");
 // Validate test assumptions. This would be expressed as ASSERT_* in
@@ -6090,10 +6087,6 @@ class 
ForCallablePreservesBindingWithMultipleParentsTestCallback
 return true;
   }
 
-  bool run(const BoundNodes *BoundNodes, ASTContext *Context) override {
-return run(BoundNodes);
-  }
-
 private:
   void ExpectCorrectResult(StringRef LogInfo,
ArrayRef Results) const {

___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang-tidy] Add FixIts for libc namespace macros (PR #99681)

2024-07-20 Thread Julian Schmidt via llvm-branch-commits


@@ -51,7 +78,9 @@ void ImplementationInNamespaceCheck::check(
   // instead.
   if (NS->getVisibility() != Visibility::HiddenVisibility) {
 diag(NS->getLocation(), "the '%0' macro should start with '%1'")
-<< RequiredNamespaceDeclMacroName << RequiredNamespaceDeclStart;
+<< RequiredNamespaceDeclMacroName << RequiredNamespaceDeclStart
+<< FixItHint::CreateReplacement(NS->getLocation(),
+RequiredNamespaceDeclMacroName);

5chmidti wrote:

You probably would want to add an include in this case as well, given that 
you're adding the same macro as above.

https://github.com/llvm/llvm-project/pull/99681
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang-tidy] Add FixIts for libc namespace macros (PR #99681)

2024-07-20 Thread Julian Schmidt via llvm-branch-commits

https://github.com/5chmidti commented:

(not familiar with libc development)

One question may be if the outer namespace should be replaced with the libc 
macro, or if the libc macro should be added around the other namespace. But 
given that this check is for libc development, then the libc people would know 
best what is desired.

https://github.com/llvm/llvm-project/pull/99681
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang-tidy] Add FixIts for libc namespace macros (PR #99681)

2024-07-20 Thread Julian Schmidt via llvm-branch-commits


@@ -41,8 +50,26 @@ void ImplementationInNamespaceCheck::check(
 
   // Enforce that the namespace is the result of macro expansion
   if (Result.SourceManager->isMacroBodyExpansion(NS->getLocation()) == false) {
-diag(NS->getLocation(), "the outermost namespace should be the '%0' macro")
-<< RequiredNamespaceDeclMacroName;
+auto DB = diag(NS->getLocation(),
+   "the outermost namespace should be the '%0' macro")
+  << RequiredNamespaceDeclMacroName;
+
+// TODO: Determine how to split inline namespaces correctly in the 
FixItHint
+//
+// We can't easily replace LIBC_NAMEPACE::inner::namespace { with
+//
+// namespace LIBC_NAMEPACE_DECL {
+//   namespace inner::namespace {

5chmidti wrote:

I think this is doable, but the `MACRO` in `namespace MACRO::foo::bar` could be 
a nested namespace as well (`#define MACRO my::namespace`).

You would likely have to go through the lexer and check if the next tokens are 
`::`, and take these locations (with offset 1) as the range to be 
removed/changed. Should the outer libc namespace be on its own like in this 
example, or is a replacement from `LIBC_NAMESPACE::inner::namespace` to 
`LIBC_NAMESPACE_DECL::inner::namespace` fine?

FYI: `LIBC_NAMEPACE_DECL` -> `LIBC_NAMESPACE_DECL` (missing `S` twice)

https://github.com/llvm/llvm-project/pull/99681
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang-tidy] Add FixIts for libc namespace macros (PR #99681)

2024-07-20 Thread Julian Schmidt via llvm-branch-commits

https://github.com/5chmidti edited 
https://github.com/llvm/llvm-project/pull/99681
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang-tidy] Add FixIts for libc namespace macros (PR #99681)

2024-07-20 Thread Julian Schmidt via llvm-branch-commits


@@ -1,4 +1,6 @@
-// RUN: %check_clang_tidy %s llvmlibc-implementation-in-namespace %t
+// RUN: %check_clang_tidy %s llvmlibc-implementation-in-namespace %t -fix

5chmidti wrote:

No need to specify `-fix`, fixes are done automatically, e.g., 
https://github.com/llvm/llvm-project/blob/main/clang-tools-extra/test/clang-tidy/checkers/modernize/make-unique.cpp

https://github.com/llvm/llvm-project/pull/99681
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang-tidy] Add FixIts for libc namespace macros (PR #99681)

2024-07-20 Thread Julian Schmidt via llvm-branch-commits




5chmidti wrote:

Please add a test with an outer namespace that needs to be changed, but which 
already has the hidden visibility attribute. That way, we'll be sure that the 
replacement will replace the namespace name instead of breaking the attribute 
into pieces.

https://github.com/llvm/llvm-project/pull/99681
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang-tidy] Add FixIts for libc namespace macros (PR #99681)

2024-07-20 Thread Julian Schmidt via llvm-branch-commits


@@ -41,8 +50,26 @@ void ImplementationInNamespaceCheck::check(
 
   // Enforce that the namespace is the result of macro expansion
   if (Result.SourceManager->isMacroBodyExpansion(NS->getLocation()) == false) {
-diag(NS->getLocation(), "the outermost namespace should be the '%0' macro")
-<< RequiredNamespaceDeclMacroName;
+auto DB = diag(NS->getLocation(),
+   "the outermost namespace should be the '%0' macro")
+  << RequiredNamespaceDeclMacroName;
+
+// TODO: Determine how to split inline namespaces correctly in the 
FixItHint
+//
+// We can't easily replace LIBC_NAMEPACE::inner::namespace { with
+//
+// namespace LIBC_NAMEPACE_DECL {
+//   namespace inner::namespace {
+//
+// For now, just update the simple case w/ LIBC_NAMEPACE_DECL
+if (!NS->isInlineNamespace())
+  DB << FixItHint::CreateReplacement(NS->getLocation(),
+ RequiredNamespaceDeclMacroName);
+
+DB << IncludeInserter.createIncludeInsertion(
+Result.SourceManager->getFileID(NS->getBeginLoc()),
+NamespaceMacroHeader);

5chmidti wrote:

+-: It might be a bit weird to add an include without the macro

https://github.com/llvm/llvm-project/pull/99681
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang-tidy] Add FixIts for libc namespace macros (PR #99681)

2024-07-20 Thread Julian Schmidt via llvm-branch-commits


@@ -41,8 +50,26 @@ void ImplementationInNamespaceCheck::check(
 
   // Enforce that the namespace is the result of macro expansion
   if (Result.SourceManager->isMacroBodyExpansion(NS->getLocation()) == false) {
-diag(NS->getLocation(), "the outermost namespace should be the '%0' macro")
-<< RequiredNamespaceDeclMacroName;
+auto DB = diag(NS->getLocation(),
+   "the outermost namespace should be the '%0' macro")
+  << RequiredNamespaceDeclMacroName;
+
+// TODO: Determine how to split inline namespaces correctly in the 
FixItHint
+//
+// We can't easily replace LIBC_NAMEPACE::inner::namespace { with
+//
+// namespace LIBC_NAMEPACE_DECL {
+//   namespace inner::namespace {
+//
+// For now, just update the simple case w/ LIBC_NAMEPACE_DECL
+if (!NS->isInlineNamespace())

5chmidti wrote:

These are nested namespaces, not inline namespaces. Please fix the comment, use 
`isNested`, and add true negative tests for nested namespaces.

https://github.com/llvm/llvm-project/pull/99681
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [clang][test] remove unused `run` overload in `BoundNodesCallback` (PR #105935)

2024-08-24 Thread Julian Schmidt via llvm-branch-commits

https://github.com/5chmidti created 
https://github.com/llvm/llvm-project/pull/105935

The overload that did not take the additional `ASTContext *` argument is 
unnecessary when the context could simply be commented out, as it is always 
passed to `run` from `VerifyMatcher::run`.
This patch removes the single-argument overload in favor of having a single 
overload.

>From 8187d06e8a37899663b79c17402c544a48ec4610 Mon Sep 17 00:00:00 2001
From: Julian Schmidt 
Date: Sat, 1 Jun 2024 17:49:13 +0200
Subject: [PATCH] [clang][test] remove unused `run` overload in
 `BoundNodesCallback`

The overload that did not take the additional `ASTContext *` argument is
unnecessary when the context could simply be commented out, as it is
always passed to `run` from `VerifyMatcher::run`.
This patch removes the single-argument overload in favor of having a
single overload.
---
 .../unittests/ASTMatchers/ASTMatchersNodeTest.cpp |  2 --
 clang/unittests/ASTMatchers/ASTMatchersTest.h |  7 +--
 .../ASTMatchers/ASTMatchersTraversalTest.cpp  | 15 ---
 3 files changed, 5 insertions(+), 19 deletions(-)

diff --git a/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp 
b/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
index 3295ad1e21455f..ebf548eb254313 100644
--- a/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
+++ b/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
@@ -2030,8 +2030,6 @@ TEST_P(ASTMatchersTest,
 template 
 class VerifyAncestorHasChildIsEqual : public BoundNodesCallback {
 public:
-  bool run(const BoundNodes *Nodes) override { return false; }
-
   bool run(const BoundNodes *Nodes, ASTContext *Context) override {
 const T *Node = Nodes->getNodeAs("");
 return verify(*Nodes, *Context, Node);
diff --git a/clang/unittests/ASTMatchers/ASTMatchersTest.h 
b/clang/unittests/ASTMatchers/ASTMatchersTest.h
index e9812995315741..ad2f5f355621cd 100644
--- a/clang/unittests/ASTMatchers/ASTMatchersTest.h
+++ b/clang/unittests/ASTMatchers/ASTMatchersTest.h
@@ -28,7 +28,6 @@ using clang::tooling::runToolOnCodeWithArgs;
 class BoundNodesCallback {
 public:
   virtual ~BoundNodesCallback() {}
-  virtual bool run(const BoundNodes *BoundNodes) = 0;
   virtual bool run(const BoundNodes *BoundNodes, ASTContext *Context) = 0;
   virtual void onEndOfTranslationUnit() {}
 };
@@ -403,7 +402,7 @@ template  class VerifyIdIsBoundTo : public 
BoundNodesCallback {
 EXPECT_EQ("", Name);
   }
 
-  bool run(const BoundNodes *Nodes) override {
+  bool run(const BoundNodes *Nodes, ASTContext * /*Context*/) override {
 const BoundNodes::IDToNodeMap &M = Nodes->getMap();
 if (Nodes->getNodeAs(Id)) {
   ++Count;
@@ -426,10 +425,6 @@ template  class VerifyIdIsBoundTo : public 
BoundNodesCallback {
 return false;
   }
 
-  bool run(const BoundNodes *Nodes, ASTContext *Context) override {
-return run(Nodes);
-  }
-
 private:
   const std::string Id;
   const int ExpectedCount;
diff --git a/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp 
b/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
index 8a62358a71f0bf..b91eaf91c0bf23 100644
--- a/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
+++ b/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
@@ -5653,7 +5653,6 @@ TEST(HasParent, MatchesAllParents) {
 TEST(HasParent, NoDuplicateParents) {
   class HasDuplicateParents : public BoundNodesCallback {
   public:
-bool run(const BoundNodes *Nodes) override { return false; }
 bool run(const BoundNodes *Nodes, ASTContext *Context) override {
   const Stmt *Node = Nodes->getNodeAs("node");
   std::set Parents;
@@ -5862,16 +5861,14 @@ template  class VerifyMatchOnNode : public 
BoundNodesCallback {
 public:
   VerifyMatchOnNode(StringRef Id, const internal::Matcher &InnerMatcher,
 StringRef InnerId)
-: Id(Id), InnerMatcher(InnerMatcher), InnerId(InnerId) {
-  }
-
-  bool run(const BoundNodes *Nodes) override { return false; }
+  : Id(Id), InnerMatcher(InnerMatcher), InnerId(InnerId) {}
 
   bool run(const BoundNodes *Nodes, ASTContext *Context) override {
 const T *Node = Nodes->getNodeAs(Id);
 return selectFirst(InnerId, match(InnerMatcher, *Node, *Context)) !=
-  nullptr;
+   nullptr;
   }
+
 private:
   std::string Id;
   internal::Matcher InnerMatcher;
@@ -6065,7 +6062,7 @@ namespace {
 class ForCallablePreservesBindingWithMultipleParentsTestCallback
 : public BoundNodesCallback {
 public:
-  bool run(const BoundNodes *BoundNodes) override {
+  bool run(const BoundNodes *BoundNodes, ASTContext *Context) override {
 FunctionDecl const *FunDecl =
 BoundNodes->getNodeAs("funDecl");
 // Validate test assumptions. This would be expressed as ASSERT_* in
@@ -6102,10 +6099,6 @@ class 
ForCallablePreservesBindingWithMultipleParentsTestCallback
 return true;
   }
 
-  bool run(const BoundNodes *BoundNodes, ASTContext *Context) override {
-return run(BoundNodes);
-  }
-
 private:
   void Exp

[llvm-branch-commits] [clang] [clang][test] remove unused `run` overload in `BoundNodesCallback` (PR #105935)

2024-08-24 Thread Julian Schmidt via llvm-branch-commits

5chmidti wrote:

Recreated after accidental merge in #94244 because this is part of a stack.
Previous approval is in the linked pr.

https://github.com/llvm/llvm-project/pull/105935
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [clang][test] remove unused `run` overload in `BoundNodesCallback` (PR #94244)

2024-08-24 Thread Julian Schmidt via llvm-branch-commits

5chmidti wrote:

Thanks for noticing this pr, I've had a deadline to uphold and wasn't that 
active. This pr was actually part of a stack, and unluckily not the bottom pr 
that merges into `main`, so I've recreated the pr. I didn't want to ping Aaron 
for the last approval needed during the branch window for 19.

https://github.com/llvm/llvm-project/pull/94244
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [clang][test] add testing for the AST matcher reference (PR #94248)

2024-08-24 Thread Julian Schmidt via llvm-branch-commits

https://github.com/5chmidti edited 
https://github.com/llvm/llvm-project/pull/94248
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [clang][test] remove unused `run` overload in `BoundNodesCallback` (PR #105935)

2024-08-29 Thread Julian Schmidt via llvm-branch-commits

https://github.com/5chmidti updated 
https://github.com/llvm/llvm-project/pull/105935

>From 2072160d9b7763c58edd14083a4523fd94e6040f Mon Sep 17 00:00:00 2001
From: Julian Schmidt 
Date: Sat, 1 Jun 2024 17:49:13 +0200
Subject: [PATCH] [clang][test] remove unused `run` overload in
 `BoundNodesCallback`

The overload that did not take the additional `ASTContext *` argument is
unnecessary when the context could simply be commented out, as it is
always passed to `run` from `VerifyMatcher::run`.
This patch removes the single-argument overload in favor of having a
single overload.
---
 .../unittests/ASTMatchers/ASTMatchersNodeTest.cpp |  2 --
 clang/unittests/ASTMatchers/ASTMatchersTest.h |  7 +--
 .../ASTMatchers/ASTMatchersTraversalTest.cpp  | 15 ---
 3 files changed, 5 insertions(+), 19 deletions(-)

diff --git a/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp 
b/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
index 3295ad1e21455f..ebf548eb254313 100644
--- a/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
+++ b/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
@@ -2030,8 +2030,6 @@ TEST_P(ASTMatchersTest,
 template 
 class VerifyAncestorHasChildIsEqual : public BoundNodesCallback {
 public:
-  bool run(const BoundNodes *Nodes) override { return false; }
-
   bool run(const BoundNodes *Nodes, ASTContext *Context) override {
 const T *Node = Nodes->getNodeAs("");
 return verify(*Nodes, *Context, Node);
diff --git a/clang/unittests/ASTMatchers/ASTMatchersTest.h 
b/clang/unittests/ASTMatchers/ASTMatchersTest.h
index e9812995315741..ad2f5f355621cd 100644
--- a/clang/unittests/ASTMatchers/ASTMatchersTest.h
+++ b/clang/unittests/ASTMatchers/ASTMatchersTest.h
@@ -28,7 +28,6 @@ using clang::tooling::runToolOnCodeWithArgs;
 class BoundNodesCallback {
 public:
   virtual ~BoundNodesCallback() {}
-  virtual bool run(const BoundNodes *BoundNodes) = 0;
   virtual bool run(const BoundNodes *BoundNodes, ASTContext *Context) = 0;
   virtual void onEndOfTranslationUnit() {}
 };
@@ -403,7 +402,7 @@ template  class VerifyIdIsBoundTo : public 
BoundNodesCallback {
 EXPECT_EQ("", Name);
   }
 
-  bool run(const BoundNodes *Nodes) override {
+  bool run(const BoundNodes *Nodes, ASTContext * /*Context*/) override {
 const BoundNodes::IDToNodeMap &M = Nodes->getMap();
 if (Nodes->getNodeAs(Id)) {
   ++Count;
@@ -426,10 +425,6 @@ template  class VerifyIdIsBoundTo : public 
BoundNodesCallback {
 return false;
   }
 
-  bool run(const BoundNodes *Nodes, ASTContext *Context) override {
-return run(Nodes);
-  }
-
 private:
   const std::string Id;
   const int ExpectedCount;
diff --git a/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp 
b/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
index 8a62358a71f0bf..b91eaf91c0bf23 100644
--- a/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
+++ b/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
@@ -5653,7 +5653,6 @@ TEST(HasParent, MatchesAllParents) {
 TEST(HasParent, NoDuplicateParents) {
   class HasDuplicateParents : public BoundNodesCallback {
   public:
-bool run(const BoundNodes *Nodes) override { return false; }
 bool run(const BoundNodes *Nodes, ASTContext *Context) override {
   const Stmt *Node = Nodes->getNodeAs("node");
   std::set Parents;
@@ -5862,16 +5861,14 @@ template  class VerifyMatchOnNode : public 
BoundNodesCallback {
 public:
   VerifyMatchOnNode(StringRef Id, const internal::Matcher &InnerMatcher,
 StringRef InnerId)
-: Id(Id), InnerMatcher(InnerMatcher), InnerId(InnerId) {
-  }
-
-  bool run(const BoundNodes *Nodes) override { return false; }
+  : Id(Id), InnerMatcher(InnerMatcher), InnerId(InnerId) {}
 
   bool run(const BoundNodes *Nodes, ASTContext *Context) override {
 const T *Node = Nodes->getNodeAs(Id);
 return selectFirst(InnerId, match(InnerMatcher, *Node, *Context)) !=
-  nullptr;
+   nullptr;
   }
+
 private:
   std::string Id;
   internal::Matcher InnerMatcher;
@@ -6065,7 +6062,7 @@ namespace {
 class ForCallablePreservesBindingWithMultipleParentsTestCallback
 : public BoundNodesCallback {
 public:
-  bool run(const BoundNodes *BoundNodes) override {
+  bool run(const BoundNodes *BoundNodes, ASTContext *Context) override {
 FunctionDecl const *FunDecl =
 BoundNodes->getNodeAs("funDecl");
 // Validate test assumptions. This would be expressed as ASSERT_* in
@@ -6102,10 +6099,6 @@ class 
ForCallablePreservesBindingWithMultipleParentsTestCallback
 return true;
   }
 
-  bool run(const BoundNodes *BoundNodes, ASTContext *Context) override {
-return run(BoundNodes);
-  }
-
 private:
   void ExpectCorrectResult(StringRef LogInfo,
ArrayRef Results) const {

___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang-tools-extra] [clang-tidy] fix false positive in lambda expr for return-const-ref-from-parameter (PR #118990)

2024-12-06 Thread Julian Schmidt via llvm-branch-commits

https://github.com/5chmidti approved this pull request.

Nice catch, LGTM

https://github.com/llvm/llvm-project/pull/118990
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits