From 23a799adf0abbe9a7be1494d5efd1ab3215ee4fb Mon Sep 17 00:00:00 2001 From: Jonas Toth Date: Sat, 11 Jan 2020 19:41:27 +0100 Subject: [PATCH] Revert "[ASTMatchers] extract public matchers from const-analysis into own patch" This reverts commit 4c48ea68e491cb42f1b5d43ffba89f6a7f0dadc4. The powerpc buildbots had an internal compiler error after this patch. This requires some inspection. --- clang/docs/LibASTMatchersReference.html | 132 -------------- clang/include/clang/ASTMatchers/ASTMatchers.h | 110 ------------ clang/lib/ASTMatchers/Dynamic/Registry.cpp | 2 - .../ASTMatchers/ASTMatchersTraversalTest.cpp | 166 ------------------ 4 files changed, 410 deletions(-) diff --git a/clang/docs/LibASTMatchersReference.html b/clang/docs/LibASTMatchersReference.html index 099462f17d2b..5bb181b04d3a 100644 --- a/clang/docs/LibASTMatchersReference.html +++ b/clang/docs/LibASTMatchersReference.html @@ -635,30 +635,6 @@ Example matches a -Matcher<DecompositionDecl>decompositionDeclMatcher<DecompositionDecl>... -
Matches decomposition-declarations.
-
-Examples matches the declaration node with foo and bar, but not
-number.
-(matcher = declStmt(has(decompositionDecl())))
-
-  int number = 42;
-  auto [foo, bar] = std::make_pair{42, 42};
-
- - -Matcher<DecompositionDecl>decompositionDeclMatcher<DecompositionDecl>... -
Matches decomposition-declarations.
-
-Examples matches the declaration node with foo and bar, but not
-number.
-(matcher = declStmt(has(decompositionDecl())))
-
-  int number = 42;
-  auto [foo, bar] = std::make_pair{42, 42};
-
- - Matcher<NestedNameSpecifierLoc>nestedNameSpecifierLocMatcher<NestedNameSpecifierLoc>...
Same as nestedNameSpecifier but matches NestedNameSpecifierLoc.
 
@@ -4993,60 +4969,6 @@ and parmVarDecl(...) -Matcher<CXXConstructExpr>forEachArgumentWithParamTypeMatcher<Expr> ArgMatcher, Matcher<QualType> ParamMatcher -
Matches all arguments and their respective types for a CallExpr or
-CXXConstructExpr. It is very similar to forEachArgumentWithParam but
-it works on calls through function pointers as well.
-
-The difference is, that function pointers do not provide access to a
-ParmVarDecl, but only the QualType for each argument.
-
-Given
-  void f(int i);
-  int y;
-  f(y);
-  void (*f_ptr)(int) = f;
-  f_ptr(y);
-callExpr(
-  forEachArgumentWithParamType(
-    declRefExpr(to(varDecl(hasName("y")))),
-    qualType(isInteger()).bind("type)
-))
-  matches f(y) and f_ptr(y)
-with declRefExpr(...)
-  matching int y
-and qualType(...)
-  matching int
-
- - -Matcher<CXXConstructExpr>forEachArgumentWithParamTypeMatcher<Expr> ArgMatcher, Matcher<QualType> ParamMatcher -
Matches all arguments and their respective types for a CallExpr or
-CXXConstructExpr. It is very similar to forEachArgumentWithParam but
-it works on calls through function pointers as well.
-
-The difference is, that function pointers do not provide access to a
-ParmVarDecl, but only the QualType for each argument.
-
-Given
-  void f(int i);
-  int y;
-  f(y);
-  void (*f_ptr)(int) = f;
-  f_ptr(y);
-callExpr(
-  forEachArgumentWithParamType(
-    declRefExpr(to(varDecl(hasName("y")))),
-    qualType(isInteger()).bind("type)
-))
-  matches f(y) and f_ptr(y)
-with declRefExpr(...)
-  matching int y
-and qualType(...)
-  matching int
-
- - Matcher<CXXConstructExpr>hasAnyArgumentMatcher<Expr> InnerMatcher
Matches any argument of a call expression or a constructor call
 expression, or an ObjC-message-send expression.
@@ -5525,60 +5447,6 @@ and parmVarDecl(...)
 
-Matcher<CallExpr>forEachArgumentWithParamTypeMatcher<Expr> ArgMatcher, Matcher<QualType> ParamMatcher -
Matches all arguments and their respective types for a CallExpr or
-CXXConstructExpr. It is very similar to forEachArgumentWithParam but
-it works on calls through function pointers as well.
-
-The difference is, that function pointers do not provide access to a
-ParmVarDecl, but only the QualType for each argument.
-
-Given
-  void f(int i);
-  int y;
-  f(y);
-  void (*f_ptr)(int) = f;
-  f_ptr(y);
-callExpr(
-  forEachArgumentWithParamType(
-    declRefExpr(to(varDecl(hasName("y")))),
-    qualType(isInteger()).bind("type)
-))
-  matches f(y) and f_ptr(y)
-with declRefExpr(...)
-  matching int y
-and qualType(...)
-  matching int
-
- - -Matcher<CallExpr>forEachArgumentWithParamTypeMatcher<Expr> ArgMatcher, Matcher<QualType> ParamMatcher -
Matches all arguments and their respective types for a CallExpr or
-CXXConstructExpr. It is very similar to forEachArgumentWithParam but
-it works on calls through function pointers as well.
-
-The difference is, that function pointers do not provide access to a
-ParmVarDecl, but only the QualType for each argument.
-
-Given
-  void f(int i);
-  int y;
-  f(y);
-  void (*f_ptr)(int) = f;
-  f_ptr(y);
-callExpr(
-  forEachArgumentWithParamType(
-    declRefExpr(to(varDecl(hasName("y")))),
-    qualType(isInteger()).bind("type)
-))
-  matches f(y) and f_ptr(y)
-with declRefExpr(...)
-  matching int y
-and qualType(...)
-  matching int
-
- - Matcher<CallExpr>hasAnyArgumentMatcher<Expr> InnerMatcher
Matches any argument of a call expression or a constructor call
 expression, or an ObjC-message-send expression.
diff --git a/clang/include/clang/ASTMatchers/ASTMatchers.h b/clang/include/clang/ASTMatchers/ASTMatchers.h
index d223e9a0477d..9a5888b7572b 100644
--- a/clang/include/clang/ASTMatchers/ASTMatchers.h
+++ b/clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -310,18 +310,6 @@ AST_POLYMORPHIC_MATCHER_P(isExpansionInFileMatching,
 /// \endcode
 extern const internal::VariadicAllOfMatcher decl;
 
-/// Matches decomposition-declarations.
-///
-/// Examples matches the declaration node with \c foo and \c bar, but not
-/// \c number.
-/// (matcher = declStmt(has(decompositionDecl())))
-///
-/// \code
-///   int number = 42;
-///   auto [foo, bar] = std::make_pair{42, 42};
-/// \endcode
-extern const internal::VariadicAllOfMatcher decompositionDecl;
-
 /// Matches a declaration of a linkage specification.
 ///
 /// Given
@@ -4206,104 +4194,6 @@ AST_POLYMORPHIC_MATCHER_P2(forEachArgumentWithParam,
   return Matched;
 }
 
-/// Matches all arguments and their respective types for a \c CallExpr or
-/// \c CXXConstructExpr. It is very similar to \c forEachArgumentWithParam but
-/// it works on calls through function pointers as well.
-///
-/// The difference is, that function pointers do not provide access to a
-/// \c ParmVarDecl, but only the \c QualType for each argument.
-///
-/// Given
-/// \code
-///   void f(int i);
-///   int y;
-///   f(y);
-///   void (*f_ptr)(int) = f;
-///   f_ptr(y);
-/// \endcode
-/// callExpr(
-///   forEachArgumentWithParamType(
-///     declRefExpr(to(varDecl(hasName("y")))),
-///     qualType(isInteger()).bind("type)
-/// ))
-///   matches f(y) and f_ptr(y)
-/// with declRefExpr(...)
-///   matching int y
-/// and qualType(...)
-///   matching int
-AST_POLYMORPHIC_MATCHER_P2(forEachArgumentWithParamType,
-                           AST_POLYMORPHIC_SUPPORTED_TYPES(CallExpr,
-                                                           CXXConstructExpr),
-                           internal::Matcher, ArgMatcher,
-                           internal::Matcher, ParamMatcher) {
-  BoundNodesTreeBuilder Result;
-  // The first argument of an overloaded member operator is the implicit object
-  // argument of the method which should not be matched against a parameter, so
-  // we skip over it here.
-  BoundNodesTreeBuilder Matches;
-  unsigned ArgIndex = cxxOperatorCallExpr(callee(cxxMethodDecl()))
-                              .matches(Node, Finder, &Matches)
-                          ? 1
-                          : 0;
-
-  const FunctionProtoType *FProto = nullptr;
-
-  if (const auto *Call = dyn_cast(&Node)) {
-    if (const auto *Value =
-            dyn_cast_or_null(Call->getCalleeDecl())) {
-      QualType QT = Value->getType().getCanonicalType();
-
-      // This does not necessarily lead to a `FunctionProtoType`,
-      // e.g. K&R functions do not have a function prototype.
-      if (QT->isFunctionPointerType())
-        FProto = QT->getPointeeType()->getAs();
-
-      if (QT->isMemberFunctionPointerType()) {
-        const auto *MP = QT->getAs();
-        assert(MP &&
-               "Must be member-pointer if its a memberfunctionpointer");
-        FProto = MP->getPointeeType()->getAs();
-        assert(FProto &&
-               "The call must have happened through a member function "
-               "pointer");
-      }
-    }
-  }
-
-  int ParamIndex = 0;
-  bool Matched = false;
-
-  for (; ArgIndex < Node.getNumArgs(); ++ArgIndex, ++ParamIndex) {
-    BoundNodesTreeBuilder ArgMatches(*Builder);
-    if (ArgMatcher.matches(*(Node.getArg(ArgIndex)->IgnoreParenCasts()),
-                           Finder, &ArgMatches)) {
-      BoundNodesTreeBuilder ParamMatches(ArgMatches);
-
-      // This test is cheaper compared to the big matcher in the next if.
-      // Therefore, please keep this order.
-      if (FProto) {
-        QualType ParamType = FProto->getParamType(ParamIndex);
-        if (ParamMatcher.matches(ParamType, Finder, &ParamMatches)) {
-          Result.addMatch(ParamMatches);
-          Matched = true;
-          continue;
-        }
-      }
-      if (expr(anyOf(cxxConstructExpr(hasDeclaration(cxxConstructorDecl(
-                         hasParameter(ParamIndex, hasType(ParamMatcher))))),
-                     callExpr(callee(functionDecl(
-                         hasParameter(ParamIndex, hasType(ParamMatcher)))))))
-              .matches(Node, Finder, &ParamMatches)) {
-        Result.addMatch(ParamMatches);
-        Matched = true;
-        continue;
-      }
-    }
-  }
-  *Builder = std::move(Result);
-  return Matched;
-}
-
 /// Matches any parameter of a function or an ObjC method declaration or a
 /// block.
 ///
diff --git a/clang/lib/ASTMatchers/Dynamic/Registry.cpp b/clang/lib/ASTMatchers/Dynamic/Registry.cpp
index bfd7906559af..1c0930c5983a 100644
--- a/clang/lib/ASTMatchers/Dynamic/Registry.cpp
+++ b/clang/lib/ASTMatchers/Dynamic/Registry.cpp
@@ -196,7 +196,6 @@ RegistryMaps::RegistryMaps() {
   REGISTER_MATCHER(cxxUnresolvedConstructExpr);
   REGISTER_MATCHER(decayedType);
   REGISTER_MATCHER(decl);
-  REGISTER_MATCHER(decompositionDecl);
   REGISTER_MATCHER(declCountIs);
   REGISTER_MATCHER(declRefExpr);
   REGISTER_MATCHER(declStmt);
@@ -221,7 +220,6 @@ RegistryMaps::RegistryMaps() {
   REGISTER_MATCHER(floatLiteral);
   REGISTER_MATCHER(forEach);
   REGISTER_MATCHER(forEachArgumentWithParam);
-  REGISTER_MATCHER(forEachArgumentWithParamType);
   REGISTER_MATCHER(forEachConstructorInitializer);
   REGISTER_MATCHER(forEachDescendant);
   REGISTER_MATCHER(forEachOverridden);
diff --git a/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp b/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
index c9911379623e..23447baf912b 100644
--- a/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
+++ b/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
@@ -735,172 +735,6 @@ TEST(ForEachArgumentWithParam, HandlesBoundNodesForNonMatches) {
     std::make_unique>("v", 4)));
 }
 
-TEST(ForEachArgumentWithParamType, ReportsNoFalsePositives) {
-  StatementMatcher ArgumentY =
-    declRefExpr(to(varDecl(hasName("y")))).bind("arg");
-  TypeMatcher IntType = qualType(isInteger()).bind("type");
-  StatementMatcher CallExpr =
-    callExpr(forEachArgumentWithParamType(ArgumentY, IntType));
-
-  // IntParam does not match.
-  EXPECT_TRUE(notMatches("void f(int* i) { int* y; f(y); }", CallExpr));
-  // ArgumentY does not match.
-  EXPECT_TRUE(notMatches("void f(int i) { int x; f(x); }", CallExpr));
-}
-
-TEST(ForEachArgumentWithParamType, MatchesCXXMemberCallExpr) {
-  StatementMatcher ArgumentY =
-    declRefExpr(to(varDecl(hasName("y")))).bind("arg");
-  TypeMatcher IntType = qualType(isInteger()).bind("type");
-  StatementMatcher CallExpr =
-    callExpr(forEachArgumentWithParamType(ArgumentY, IntType));
-  EXPECT_TRUE(matchAndVerifyResultTrue(
-    "struct S {"
-      "  const S& operator[](int i) { return *this; }"
-      "};"
-      "void f(S S1) {"
-      "  int y = 1;"
-      "  S1[y];"
-      "}",
-    CallExpr, std::make_unique>("type", 1)));
-
-  StatementMatcher CallExpr2 =
-    callExpr(forEachArgumentWithParamType(ArgumentY, IntType));
-  EXPECT_TRUE(matchAndVerifyResultTrue(
-    "struct S {"
-      "  static void g(int i);"
-      "};"
-      "void f() {"
-      "  int y = 1;"
-      "  S::g(y);"
-      "}",
-    CallExpr2, std::make_unique>("type", 1)));
-}
-
-TEST(ForEachArgumentWithParamType, MatchesCallExpr) {
-  StatementMatcher ArgumentY =
-    declRefExpr(to(varDecl(hasName("y")))).bind("arg");
-  TypeMatcher IntType = qualType(isInteger()).bind("type");
-  StatementMatcher CallExpr =
-    callExpr(forEachArgumentWithParamType(ArgumentY, IntType));
-
-  EXPECT_TRUE(
-    matchAndVerifyResultTrue("void f(int i) { int y; f(y); }", CallExpr,
-                             std::make_unique>(
-                               "type")));
-  EXPECT_TRUE(
-    matchAndVerifyResultTrue("void f(int i) { int y; f(y); }", CallExpr,
-                             std::make_unique>(
-                               "arg")));
-
-  EXPECT_TRUE(matchAndVerifyResultTrue(
-    "void f(int i, int j) { int y; f(y, y); }", CallExpr,
-    std::make_unique>("type", 2)));
-  EXPECT_TRUE(matchAndVerifyResultTrue(
-    "void f(int i, int j) { int y; f(y, y); }", CallExpr,
-    std::make_unique>("arg", 2)));
-}
-
-TEST(ForEachArgumentWithParamType, MatchesConstructExpr) {
-  StatementMatcher ArgumentY =
-    declRefExpr(to(varDecl(hasName("y")))).bind("arg");
-  TypeMatcher IntType = qualType(isInteger()).bind("type");
-  StatementMatcher ConstructExpr =
-    cxxConstructExpr(forEachArgumentWithParamType(ArgumentY, IntType));
-
-  EXPECT_TRUE(matchAndVerifyResultTrue(
-    "struct C {"
-      "  C(int i) {}"
-      "};"
-      "int y = 0;"
-      "C Obj(y);",
-    ConstructExpr,
-    std::make_unique>("type")));
-  EXPECT_TRUE(matchAndVerifyResultTrue(
-    "struct C {"
-      "  C(int i) {}"
-      "};"
-      "int y = 0;"
-      "C Obj(y);",
-    ConstructExpr,
-    std::make_unique>("arg")));
-}
-
-TEST(ForEachArgumentWithParamType, HandlesKandRFunctions) {
-  StatementMatcher ArgumentY =
-      declRefExpr(to(varDecl(hasName("y")))).bind("arg");
-  TypeMatcher IntType = qualType(isInteger()).bind("type");
-  StatementMatcher CallExpr =
-      callExpr(forEachArgumentWithParamType(ArgumentY, IntType));
-
-  EXPECT_TRUE(matchesC("void f();\n"
-                       "void call_it(void) { int x, y; f(x, y); }\n"
-                       "void f(a, b) int a, b; {}\n"
-                       "void call_it2(void) { int x, y; f(x, y); }",
-                       CallExpr));
-}
-
-TEST(ForEachArgumentWithParamType, HandlesBoundNodesForNonMatches) {
-  EXPECT_TRUE(matchAndVerifyResultTrue(
-    "void g(int i, int j) {"
-      "  int a;"
-      "  int b;"
-      "  int c;"
-      "  g(a, 0);"
-      "  g(a, b);"
-      "  g(0, b);"
-      "}",
-    functionDecl(
-      forEachDescendant(varDecl().bind("v")),
-      forEachDescendant(callExpr(forEachArgumentWithParamType(
-        declRefExpr(to(decl(equalsBoundNode("v")))), qualType())))),
-    std::make_unique>("v", 4)));
-}
-
-TEST(ForEachArgumentWithParamType, MatchesFunctionPtrCalls) {
-  StatementMatcher ArgumentY =
-    declRefExpr(to(varDecl(hasName("y")))).bind("arg");
-  TypeMatcher IntType = qualType(builtinType()).bind("type");
-  StatementMatcher CallExpr =
-    callExpr(forEachArgumentWithParamType(ArgumentY, IntType));
-
-  EXPECT_TRUE(
-    matchAndVerifyResultTrue("void f(int i) {"
-                             "void (*f_ptr)(int) = f; int y; f_ptr(y); }",
-                             CallExpr,
-                             std::make_unique>("type")));
-  EXPECT_TRUE(
-    matchAndVerifyResultTrue("void f(int i) {"
-                             "void (*f_ptr)(int) = f; int y; f_ptr(y); }",
-                             CallExpr,
-                             std::make_unique>("arg")));
-}
-
-TEST(ForEachArgumentWithParamType, MatchesMemberFunctionPtrCalls) {
-  StatementMatcher ArgumentY =
-    declRefExpr(to(varDecl(hasName("y")))).bind("arg");
-  TypeMatcher IntType = qualType(builtinType()).bind("type");
-  StatementMatcher CallExpr =
-    callExpr(forEachArgumentWithParamType(ArgumentY, IntType));
-
-  StringRef S = "struct A {\n"
-                "  int f(int i) { return i + 1; }\n"
-                "  int (A::*x)(int);\n"
-                "};\n"
-                "void f() {\n"
-                "  int y = 42;\n"
-                "  A a;\n"
-                "  a.x = &A::f;\n"
-                "  (a.*(a.x))(y);\n"
-                "}";
-  EXPECT_TRUE(
-    matchAndVerifyResultTrue(S, CallExpr,
-    std::make_unique>("type")));
-  EXPECT_TRUE(
-    matchAndVerifyResultTrue(S, CallExpr,
-    std::make_unique>("arg")));
-}
-
 TEST(QualType, hasCanonicalType) {
   EXPECT_TRUE(notMatches("typedef int &int_ref;"
                            "int a;"