[clang] d5c5ed3 - [clang][bytecode] Handle vector assignments (#155573)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Aug 27 02:55:40 PDT 2025
Author: Timm Baeder
Date: 2025-08-27T11:55:37+02:00
New Revision: d5c5ed3723a61b19c72c05f7dff31aa00917027a
URL: https://github.com/llvm/llvm-project/commit/d5c5ed3723a61b19c72c05f7dff31aa00917027a
DIFF: https://github.com/llvm/llvm-project/commit/d5c5ed3723a61b19c72c05f7dff31aa00917027a.diff
LOG: [clang][bytecode] Handle vector assignments (#155573)
Added:
Modified:
clang/lib/AST/ByteCode/Compiler.cpp
clang/test/AST/ByteCode/vectors.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp
index 6e64fc0a2a7ad..ea6195cc11ef9 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -1383,7 +1383,7 @@ bool Compiler<Emitter>::VisitVectorBinOp(const BinaryOperator *E) {
assert(E->getRHS()->getType()->isVectorType());
// Prepare storage for result.
- if (!Initializing && !E->isCompoundAssignmentOp()) {
+ if (!Initializing && !E->isCompoundAssignmentOp() && !E->isAssignmentOp()) {
UnsignedOrNone LocalIndex = allocateTemporary(E);
if (!LocalIndex)
return false;
@@ -1402,6 +1402,21 @@ bool Compiler<Emitter>::VisitVectorBinOp(const BinaryOperator *E) {
PrimType RHSElemT = this->classifyVectorElementType(RHS->getType());
PrimType ResultElemT = this->classifyVectorElementType(E->getType());
+ if (E->getOpcode() == BO_Assign) {
+ assert(Ctx.getASTContext().hasSameUnqualifiedType(
+ LHS->getType()->castAs<VectorType>()->getElementType(),
+ RHS->getType()->castAs<VectorType>()->getElementType()));
+ if (!this->visit(LHS))
+ return false;
+ if (!this->visit(RHS))
+ return false;
+ if (!this->emitCopyArray(ElemT, 0, 0, VecTy->getNumElements(), E))
+ return false;
+ if (DiscardResult)
+ return this->emitPopPtr(E);
+ return true;
+ }
+
// Evaluate LHS and save value to LHSOffset.
unsigned LHSOffset =
this->allocateLocalPrimitive(LHS, PT_Ptr, /*IsConst=*/true);
diff --git a/clang/test/AST/ByteCode/vectors.cpp b/clang/test/AST/ByteCode/vectors.cpp
index 091caf8c9a275..6b41c8d79d5b4 100644
--- a/clang/test/AST/ByteCode/vectors.cpp
+++ b/clang/test/AST/ByteCode/vectors.cpp
@@ -143,3 +143,28 @@ namespace {
constexpr __m128d v_mm_cvtps_pd = _mm_cvtps_pd(kf1);
static_assert(v_mm_cvtps_pd[0] == -1.0 && v_mm_cvtps_pd[1] == +2.0);
}
+
+namespace Assign {
+ constexpr int a2() {
+ VI a = {0, 0, 0, 0};
+ VI b; // both-warning {{C++20 extension}}
+
+ b = {1,1,1,1};
+ return b[0] + b[1] + b[2] + b[3];
+ }
+
+ static_assert(a2() == 4);
+
+ typedef short v2int16_t __attribute__((ext_vector_type(2)));
+ typedef unsigned short v2int_t __attribute__((ext_vector_type(2)));
+
+
+ constexpr bool invalid() {
+ v2int16_t a = {0, 0};
+ v2int_t b; // both-warning {{C++20 extension}}
+ b = a; // both-error {{incompatible type}}
+
+ return true;
+ }
+ static_assert(invalid()); // both-error {{not an integral constant expression}}
+}
More information about the cfe-commits
mailing list