[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
This commit is contained in:
Balazs Benics 2021-09-27 10:17:12 +02:00
parent 0bd9162fd7
commit 66d9d1012b
2 changed files with 38 additions and 0 deletions

View File

@ -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)

View File

@ -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, "",