[clang] 66d9d10 - [clang][AST] Add support for ShuffleVectorExpr to ASTImporter

Balazs Benics via cfe-commits cfe-commits at lists.llvm.org
Mon Sep 27 01:17:43 PDT 2021


Author: Balazs Benics
Date: 2021-09-27T10:17:12+02:00
New Revision: 66d9d1012b031e7f7559e8f0e03b9e7bfb6c20a1

URL: https://github.com/llvm/llvm-project/commit/66d9d1012b031e7f7559e8f0e03b9e7bfb6c20a1
DIFF: https://github.com/llvm/llvm-project/commit/66d9d1012b031e7f7559e8f0e03b9e7bfb6c20a1.diff

LOG: [clang][AST] Add support for ShuffleVectorExpr to ASTImporter

Addresses https://bugs.llvm.org/show_bug.cgi?id=51902

Reviewed By: shafik, martong

Differential Revision: https://reviews.llvm.org/D110052

Added: 
    

Modified: 
    clang/lib/AST/ASTImporter.cpp
    clang/unittests/AST/ASTImporterTest.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp
index 4e4ca7a207f5..6c624b2bf7e7 100644
--- a/clang/lib/AST/ASTImporter.cpp
+++ b/clang/lib/AST/ASTImporter.cpp
@@ -583,6 +583,7 @@ namespace clang {
     ExpectedStmt VisitSourceLocExpr(SourceLocExpr *E);
     ExpectedStmt VisitVAArgExpr(VAArgExpr *E);
     ExpectedStmt VisitChooseExpr(ChooseExpr *E);
+    ExpectedStmt VisitShuffleVectorExpr(ShuffleVectorExpr *E);
     ExpectedStmt VisitGNUNullExpr(GNUNullExpr *E);
     ExpectedStmt VisitGenericSelectionExpr(GenericSelectionExpr *E);
     ExpectedStmt VisitPredefinedExpr(PredefinedExpr *E);
@@ -6730,6 +6731,24 @@ ExpectedStmt ASTNodeImporter::VisitChooseExpr(ChooseExpr *E) {
                  ToRParenLoc, CondIsTrue);
 }
 
+ExpectedStmt ASTNodeImporter::VisitShuffleVectorExpr(ShuffleVectorExpr *E) {
+  Error Err = Error::success();
+  auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
+  auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
+  auto ToType = importChecked(Err, E->getType());
+  const unsigned NumSubExprs = E->getNumSubExprs();
+
+  llvm::SmallVector<Expr *, 8> ToSubExprs;
+  llvm::ArrayRef<Expr *> FromSubExprs(E->getSubExprs(), NumSubExprs);
+  ToSubExprs.resize(NumSubExprs);
+
+  if ((Err = ImportContainerChecked(FromSubExprs, ToSubExprs)))
+    return std::move(Err);
+
+  return new (Importer.getToContext()) ShuffleVectorExpr(
+      Importer.getToContext(), ToSubExprs, ToType, ToBeginLoc, ToRParenLoc);
+}
+
 ExpectedStmt ASTNodeImporter::VisitGNUNullExpr(GNUNullExpr *E) {
   ExpectedType TypeOrErr = import(E->getType());
   if (!TypeOrErr)

diff  --git a/clang/unittests/AST/ASTImporterTest.cpp b/clang/unittests/AST/ASTImporterTest.cpp
index f14232257bbb..66ec873ffb89 100644
--- a/clang/unittests/AST/ASTImporterTest.cpp
+++ b/clang/unittests/AST/ASTImporterTest.cpp
@@ -290,6 +290,25 @@ TEST_P(ImportExpr, ImportChooseExpr) {
              functionDecl(hasDescendant(chooseExpr())));
 }
 
+const internal::VariadicDynCastAllOfMatcher<Stmt, ShuffleVectorExpr>
+    shuffleVectorExpr;
+
+TEST_P(ImportExpr, ImportShuffleVectorExpr) {
+  MatchVerifier<Decl> Verifier;
+  constexpr auto Code = R"code(
+    typedef double vector4double __attribute__((__vector_size__(32)));
+    vector4double declToImport(vector4double a, vector4double b) {
+      return __builtin_shufflevector(a, b, 0, 1, 2, 3);
+    }
+  )code";
+  const auto Pattern = functionDecl(hasDescendant(shuffleVectorExpr(
+      allOf(has(declRefExpr(to(parmVarDecl(hasName("a"))))),
+            has(declRefExpr(to(parmVarDecl(hasName("b"))))),
+            has(integerLiteral(equals(0))), has(integerLiteral(equals(1))),
+            has(integerLiteral(equals(2))), has(integerLiteral(equals(3)))))));
+  testImport(Code, Lang_C99, "", Lang_C99, Verifier, Pattern);
+}
+
 TEST_P(ImportExpr, ImportGNUNullExpr) {
   MatchVerifier<Decl> Verifier;
   testImport("void declToImport() { (void)__null; }", Lang_CXX03, "",


        


More information about the cfe-commits mailing list