summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTimm Bäder <tbaeder@redhat.com>2024-04-13 15:06:22 +0200
committerTimm Bäder <tbaeder@redhat.com>2024-04-16 11:21:41 +0200
commit58b49cef1d772a922a433fd4a42e41db3f18d34b (patch)
treef4da9d29694199c5a2d708cbf906b0d59756d6ea
parentcce026bf8f7dcf5aa402a6da20f0d4da56aee8b5 (diff)
[clang][Interp] Support __builtin_vectorelements
-rw-r--r--clang/lib/AST/Interp/ByteCodeExprGen.cpp9
-rw-r--r--clang/test/AST/Interp/vectors.cpp2
2 files changed, 11 insertions, 0 deletions
diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 5866228663dc..93059edc4622 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1251,6 +1251,15 @@ bool ByteCodeExprGen<Emitter>::VisitUnaryExprOrTypeTraitExpr(
return this->emitConst(Size.getQuantity(), E);
}
+ if (Kind == UETT_VectorElements) {
+ if (const auto *VT = E->getTypeOfArgument()->getAs<VectorType>())
+ return this->emitConst(VT->getNumElements(), E);
+
+ // FIXME: Apparently we need to catch the fact that a sizeless vector type
+ // has been passed and diagnose that (at run time).
+ assert(E->getTypeOfArgument()->isSizelessVectorType());
+ }
+
return false;
}
diff --git a/clang/test/AST/Interp/vectors.cpp b/clang/test/AST/Interp/vectors.cpp
index fb5787a9eda9..6c5d916f51f5 100644
--- a/clang/test/AST/Interp/vectors.cpp
+++ b/clang/test/AST/Interp/vectors.cpp
@@ -13,12 +13,14 @@ namespace Vector {
return VI4 { n * 3, n + 4, n - 5, n / 6 };
}
constexpr auto v1 = f(10);
+ static_assert(__builtin_vectorelements(v1) == (16 / sizeof(int)), "");
typedef double __attribute__((vector_size(32))) VD4;
constexpr VD4 g(int n) {
return (VD4) { n / 2.0, n + 1.5, n - 5.4, n * 0.9 };
}
constexpr auto v2 = g(4);
+ static_assert(__builtin_vectorelements(v2) == (32 / sizeof(double)), "");
}
/// FIXME: We need to support BitCasts between vector types.