diff --git a/clang/docs/LibASTMatchersReference.html b/clang/docs/LibASTMatchersReference.html --- a/clang/docs/LibASTMatchersReference.html +++ b/clang/docs/LibASTMatchersReference.html @@ -2790,7 +2790,7 @@ int *p = 0; If the matcher is use from clang-query, CastKind parameter -should be passed as a quoted string. e.g., ofKind("CK_NullToPointer"). +should be passed as a quoted string. e.g., hasCastKind("CK_NullToPointer"). diff --git a/clang/include/clang/ASTMatchers/ASTMatchers.h b/clang/include/clang/ASTMatchers/ASTMatchers.h --- a/clang/include/clang/ASTMatchers/ASTMatchers.h +++ b/clang/include/clang/ASTMatchers/ASTMatchers.h @@ -4913,7 +4913,7 @@ /// \endcode /// /// If the matcher is use from clang-query, CastKind parameter -/// should be passed as a quoted string. e.g., ofKind("CK_NullToPointer"). +/// should be passed as a quoted string. e.g., hasCastKind("CK_NullToPointer"). AST_MATCHER_P(CastExpr, hasCastKind, CastKind, Kind) { return Node.getCastKind() == Kind; } diff --git a/clang/lib/ASTMatchers/Dynamic/Marshallers.h b/clang/lib/ASTMatchers/Dynamic/Marshallers.h --- a/clang/lib/ASTMatchers/Dynamic/Marshallers.h +++ b/clang/lib/ASTMatchers/Dynamic/Marshallers.h @@ -170,7 +170,7 @@ private: static Optional getCastKind(llvm::StringRef AttrKind) { return llvm::StringSwitch>(AttrKind) -#define CAST_OPERATION(Name) .Case( #Name, CK_##Name) +#define CAST_OPERATION(Name) .Case("CK_" #Name, CK_##Name) #include "clang/AST/OperationKinds.def" .Default(llvm::None); } diff --git a/clang/lib/ASTMatchers/Dynamic/Marshallers.cpp b/clang/lib/ASTMatchers/Dynamic/Marshallers.cpp --- a/clang/lib/ASTMatchers/Dynamic/Marshallers.cpp +++ b/clang/lib/ASTMatchers/Dynamic/Marshallers.cpp @@ -75,11 +75,12 @@ clang::ast_matchers::dynamic::internal::ArgTypeTraits< clang::CastKind>::getBestGuess(const VariantValue &Value) { static constexpr llvm::StringRef Allowed[] = { -#define CAST_OPERATION(Name) #Name, +#define CAST_OPERATION(Name) "CK_" #Name, #include "clang/AST/OperationKinds.def" }; if (Value.isString()) - return ::getBestGuess(Value.getString(), llvm::makeArrayRef(Allowed)); + return ::getBestGuess(Value.getString(), llvm::makeArrayRef(Allowed), + "CK_"); return llvm::None; } diff --git a/clang/unittests/ASTMatchers/Dynamic/ParserTest.cpp b/clang/unittests/ASTMatchers/Dynamic/ParserTest.cpp --- a/clang/unittests/ASTMatchers/Dynamic/ParserTest.cpp +++ b/clang/unittests/ASTMatchers/Dynamic/ParserTest.cpp @@ -221,6 +221,15 @@ EXPECT_FALSE(matches("int x = 1 - false;", M)); EXPECT_FALSE(matches("int x = true - 1;", M)); + Code = "implicitCastExpr(hasCastKind(\"CK_IntegralToBoolean\"))"; + llvm::Optional implicitIntBooleanCast( + Parser::parseMatcherExpression(Code, nullptr, nullptr, &Error)); + EXPECT_EQ("", Error.toStringFull()); + Matcher MCastStmt = + implicitIntBooleanCast->unconditionalConvertTo(); + EXPECT_TRUE(matches("bool X = 1;", MCastStmt)); + EXPECT_FALSE(matches("bool X = true;", MCastStmt)); + Code = "functionDecl(hasParameter(1, hasName(\"x\")))"; llvm::Optional HasParameter( Parser::parseMatcherExpression(Code, &Error));