Skip to content

Conversation

tbaederr
Copy link
Contributor

No description provided.

@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" clang:bytecode Issues for the clang bytecode constexpr interpreter labels Aug 27, 2025
@llvmbot
Copy link
Member

llvmbot commented Aug 27, 2025

@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/155573.diff

2 Files Affected:

  • (modified) clang/lib/AST/ByteCode/Compiler.cpp (+24-1)
  • (modified) clang/test/AST/ByteCode/vectors.cpp (+25)
diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp
index 0079d937e885b..fedaeea5bf4e0 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;
@@ -1418,6 +1418,29 @@ bool Compiler<Emitter>::VisitVectorBinOp(const BinaryOperator *E) {
   if (!this->emitSetLocal(PT_Ptr, RHSOffset, E))
     return false;
 
+  if (E->isAssignmentOp()) {
+    if (!this->emitGetLocal(PT_Ptr, LHSOffset, E))
+      return false;
+
+    for (unsigned I = 0; I != VecTy->getNumElements(); ++I) {
+      // Pointer to LHS element.
+      if (!this->emitConst(I, PT_Uint32, E))
+        return false;
+      if (!this->emitArrayElemPtrUint32(E))
+        return false;
+      // Value of RHS element.
+      if (!this->emitGetLocal(PT_Ptr, RHSOffset, E))
+        return false;
+      if (!this->emitArrayElemPop(ElemT, I, E))
+        return false;
+      if (!this->emitStorePop(ElemT, E))
+        return false;
+    }
+    if (DiscardResult)
+      return this->emitPopPtr(E);
+    return true;
+  }
+
   if (E->isCompoundAssignmentOp() && !this->emitGetLocal(PT_Ptr, LHSOffset, E))
     return false;
 
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}}
+}

@tbaederr tbaederr merged commit d5c5ed3 into llvm:main Aug 27, 2025
9 checks passed
@dyung
Copy link
Collaborator

dyung commented Aug 27, 2025

Hi @tbaederr, the test you added fails if run with a compiler that defaults to C++20 because the warning about a C++20 extension does not get emitted. If that warning is not really relevant to what you are testing could we perhaps add -Wno-c++20-extensions and remove the check for the C++20 warnings?

@tbaederr
Copy link
Contributor Author

Sure, makes sense.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:bytecode Issues for the clang bytecode constexpr interpreter clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants