diff --git a/clang/docs/LibASTMatchersReference.html b/clang/docs/LibASTMatchersReference.html --- a/clang/docs/LibASTMatchersReference.html +++ b/clang/docs/LibASTMatchersReference.html @@ -1491,6 +1491,11 @@ +
Matches builtin function __builtin_convertvector. +
Matches co_return statements. diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -228,6 +228,7 @@ AST Matchers ------------ +- Add ``convertVectorExpr``. clang-format ------------ 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 @@ -2519,6 +2519,10 @@ extern const internal::VariadicDynCastAllOfMatcherchooseExpr; +/// Matches builtin function __builtin_convertvector. +extern const internal::VariadicDynCastAllOfMatcher + convertVectorExpr; + /// Matches GNU __null expression. extern const internal::VariadicDynCastAllOfMatcher gnuNullExpr; diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp --- a/clang/lib/AST/ASTImporter.cpp +++ b/clang/lib/AST/ASTImporter.cpp @@ -615,6 +615,7 @@ ExpectedStmt VisitSourceLocExpr(SourceLocExpr *E); ExpectedStmt VisitVAArgExpr(VAArgExpr *E); ExpectedStmt VisitChooseExpr(ChooseExpr *E); + ExpectedStmt VisitConvertVectorExpr(ConvertVectorExpr *E); ExpectedStmt VisitShuffleVectorExpr(ShuffleVectorExpr *E); ExpectedStmt VisitGNUNullExpr(GNUNullExpr *E); ExpectedStmt VisitGenericSelectionExpr(GenericSelectionExpr *E); @@ -7038,6 +7039,21 @@ ToRParenLoc, CondIsTrue); } +ExpectedStmt ASTNodeImporter::VisitConvertVectorExpr(ConvertVectorExpr *E) { + Error Err = Error::success(); + auto *ToSrcExpr = importChecked(Err, E->getSrcExpr()); + auto ToRParenLoc = importChecked(Err, E->getRParenLoc()); + auto ToBuiltinLoc = importChecked(Err, E->getBuiltinLoc()); + auto ToType = importChecked(Err, E->getType()); + auto *ToTSI = importChecked(Err, E->getTypeSourceInfo()); + if (Err) + return std::move(Err); + + return new (Importer.getToContext()) + ConvertVectorExpr(ToSrcExpr, ToTSI, ToType, E->getValueKind(), + E->getObjectKind(), ToBuiltinLoc, ToRParenLoc); +} + ExpectedStmt ASTNodeImporter::VisitShuffleVectorExpr(ShuffleVectorExpr *E) { Error Err = Error::success(); auto ToRParenLoc = importChecked(Err, E->getRParenLoc()); diff --git a/clang/lib/ASTMatchers/ASTMatchersInternal.cpp b/clang/lib/ASTMatchers/ASTMatchersInternal.cpp --- a/clang/lib/ASTMatchers/ASTMatchersInternal.cpp +++ b/clang/lib/ASTMatchers/ASTMatchersInternal.cpp @@ -941,6 +941,8 @@ const internal::VariadicDynCastAllOfMatcher cxxNullPtrLiteralExpr; const internal::VariadicDynCastAllOfMatcher chooseExpr; +const internal::VariadicDynCastAllOfMatcher + convertVectorExpr; const internal::VariadicDynCastAllOfMatcher coawaitExpr; const internal::VariadicDynCastAllOfMatcher diff --git a/clang/lib/ASTMatchers/Dynamic/Registry.cpp b/clang/lib/ASTMatchers/Dynamic/Registry.cpp --- a/clang/lib/ASTMatchers/Dynamic/Registry.cpp +++ b/clang/lib/ASTMatchers/Dynamic/Registry.cpp @@ -178,6 +178,7 @@ REGISTER_MATCHER(constantExpr); REGISTER_MATCHER(containsDeclaration); REGISTER_MATCHER(continueStmt); + REGISTER_MATCHER(convertVectorExpr); REGISTER_MATCHER(coreturnStmt); REGISTER_MATCHER(coroutineBodyStmt); REGISTER_MATCHER(coyieldExpr); diff --git a/clang/unittests/AST/ASTImporterTest.cpp b/clang/unittests/AST/ASTImporterTest.cpp --- a/clang/unittests/AST/ASTImporterTest.cpp +++ b/clang/unittests/AST/ASTImporterTest.cpp @@ -1295,6 +1295,29 @@ ToChooseExpr->isConditionDependent()); } +TEST_P(ASTImporterOptionSpecificTestBase, ImportConvertVectorExpr) { + Decl *From, *To; + std::tie(From, To) = getImportedDecl( + "typedef double v4double __attribute__((__vector_size__(32)));" + "typedef float v4float __attribute__((__vector_size__(16)));" + "v4float vf;" + "void declToImport() { (void)__builtin_convertvector(vf, v4double); }", + Lang_CXX03, "", Lang_CXX03); + + auto ToResults = + match(convertVectorExpr().bind("convert"), To->getASTContext()); + auto FromResults = + match(convertVectorExpr().bind("convert"), From->getASTContext()); + + const ConvertVectorExpr *FromConvertVectorExpr = + selectFirst ("convert", FromResults); + ASSERT_TRUE(FromConvertVectorExpr); + + const ConvertVectorExpr *ToConvertVectorExpr = + selectFirst ("convert", ToResults); + ASSERT_TRUE(ToConvertVectorExpr); +} + TEST_P(ASTImporterOptionSpecificTestBase, ImportGenericSelectionExpr) { Decl *From, *To; std::tie(From, To) = getImportedDecl( diff --git a/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp b/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp --- a/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp +++ b/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp @@ -986,6 +986,17 @@ chooseExpr())); } +TEST_P(ASTMatchersTest, ConvertVectorExpr) { + EXPECT_TRUE(matches( + "typedef double vector4double __attribute__((__vector_size__(32)));" + "typedef float vector4float __attribute__((__vector_size__(16)));" + "vector4float vf;" + "void f() { (void)__builtin_convertvector(vf, vector4double); }", + convertVectorExpr())); + EXPECT_TRUE(notMatches("void f() { (void)__builtin_choose_expr(1, 2, 3); }", + convertVectorExpr())); +} + TEST_P(ASTMatchersTest, GNUNullExpr) { if (!GetParam().isCXX()) { return;