[clang] [clang-tools-extra] [llvm] Add ``ignoringParenImpCasts`` in arguments of hasArgument (PR #89553)

Julian Schmidt via llvm-commits llvm-commits at lists.llvm.org
Wed May 1 12:23:45 PDT 2024


================
@@ -164,26 +164,32 @@ TEST_P(ASTMatchersTest, AllOf) {
                          "void g(int x) { struct T t; f(x, &t, 3, 4); }";
   EXPECT_TRUE(matches(
       Program, callExpr(allOf(callee(functionDecl(hasName("f"))),
-                              hasArgument(0, declRefExpr(to(varDecl())))))));
+                              hasArgument(0, ignoringParenImpCasts(declRefExpr(
+                                                 to(varDecl()))))))));
   EXPECT_TRUE(matches(
       Program,
-      callExpr(
-          allOf(callee(functionDecl(hasName("f"))),
-                hasArgument(0, declRefExpr(to(varDecl()))),
-                hasArgument(1, hasType(pointsTo(recordDecl(hasName("T")))))))));
+      callExpr(allOf(
+          callee(functionDecl(hasName("f"))),
+          hasArgument(0, ignoringParenImpCasts(declRefExpr(to(varDecl())))),
+          hasArgument(1, ignoringParenImpCasts(
+                             hasType(pointsTo(recordDecl(hasName("T"))))))))));
   EXPECT_TRUE(matches(
-      Program, callExpr(allOf(
-                   callee(functionDecl(hasName("f"))),
-                   hasArgument(0, declRefExpr(to(varDecl()))),
-                   hasArgument(1, hasType(pointsTo(recordDecl(hasName("T"))))),
-                   hasArgument(2, integerLiteral(equals(3)))))));
+      Program,
+      callExpr(allOf(
+          callee(functionDecl(hasName("f"))),
+          hasArgument(0, ignoringParenImpCasts(declRefExpr(to(varDecl())))),
+          hasArgument(1, ignoringParenImpCasts(
+                             hasType(pointsTo(recordDecl(hasName("T")))))),
+          hasArgument(2, ignoringParenImpCasts(integerLiteral(equals(3))))))));
   EXPECT_TRUE(matches(
-      Program, callExpr(allOf(
-                   callee(functionDecl(hasName("f"))),
-                   hasArgument(0, declRefExpr(to(varDecl()))),
-                   hasArgument(1, hasType(pointsTo(recordDecl(hasName("T"))))),
-                   hasArgument(2, integerLiteral(equals(3))),
-                   hasArgument(3, integerLiteral(equals(4)))))));
+      Program,
+      callExpr(allOf(
+          callee(functionDecl(hasName("f"))),
+          hasArgument(0, ignoringParenImpCasts(declRefExpr(to(varDecl())))),
+          hasArgument(1, ignoringParenImpCasts(
+                             hasType(pointsTo(recordDecl(hasName("T")))))),
+          hasArgument(2, ignoringParenImpCasts(integerLiteral(equals(3)))),
+          hasArgument(3, ignoringParenImpCasts(integerLiteral(equals(4))))))));
----------------
5chmidti wrote:

Please remove the `ignoringParenImpCasts` from all `hasArgument(1, ` matchers. These only care about the type, for which implicit nodes do not play a role for these matchers (fwict).

https://github.com/llvm/llvm-project/pull/89553


More information about the llvm-commits mailing list