https://github.com/AmrDeveloper created 
https://github.com/llvm/llvm-project/pull/199246

Fix ConstExpr comparing vec types with atomic qualified

Issue #54822

>From 59fa5e606ccaa9cff818e85dd4f2ecbeb9b69417 Mon Sep 17 00:00:00 2001
From: Amr Hesham <[email protected]>
Date: Tue, 19 May 2026 22:06:06 +0200
Subject: [PATCH] [Clang] Fix ConstExpr comparing qualified atomic vec types

---
 clang/lib/AST/ByteCode/Compiler.cpp     | 18 +++++++++++-------
 clang/lib/AST/ExprConstant.cpp          |  8 +++++---
 clang/test/AST/ByteCode/atomic-vector.c | 17 +++++++++++++++++
 3 files changed, 33 insertions(+), 10 deletions(-)
 create mode 100644 clang/test/AST/ByteCode/atomic-vector.c

diff --git a/clang/lib/AST/ByteCode/Compiler.cpp 
b/clang/lib/AST/ByteCode/Compiler.cpp
index 4d13cd7139f83..bd5e6f839ff72 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -1619,14 +1619,18 @@ template <class Emitter>
 bool Compiler<Emitter>::VisitVectorBinOp(const BinaryOperator *E) {
   const Expr *LHS = E->getLHS();
   const Expr *RHS = E->getRHS();
+
+  QualType LHSTy = LHS->getType().getAtomicUnqualifiedType();
+  QualType RHSTy = RHS->getType().getAtomicUnqualifiedType();
+
   assert(!E->isCommaOp() &&
          "Comma op should be handled in VisitBinaryOperator");
   assert(E->getType()->isVectorType());
-  assert(LHS->getType()->isVectorType());
-  assert(RHS->getType()->isVectorType());
+  assert(LHSTy->isVectorType());
+  assert(RHSTy->isVectorType());
 
   // We can only handle vectors with primitive element types.
-  if (!canClassify(LHS->getType()->castAs<VectorType>()->getElementType()))
+  if (!canClassify(LHSTy->castAs<VectorType>()->getElementType()))
     return false;
 
   // Prepare storage for result.
@@ -1643,14 +1647,14 @@ bool Compiler<Emitter>::VisitVectorBinOp(const 
BinaryOperator *E) {
                 ? BinaryOperator::getOpForCompoundAssignment(E->getOpcode())
                 : E->getOpcode();
 
-  PrimType ElemT = this->classifyVectorElementType(LHS->getType());
-  PrimType RHSElemT = this->classifyVectorElementType(RHS->getType());
+  PrimType ElemT = this->classifyVectorElementType(LHSTy);
+  PrimType RHSElemT = this->classifyVectorElementType(RHSTy);
   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()));
+        LHSTy->castAs<VectorType>()->getElementType(),
+        RHSTy->castAs<VectorType>()->getElementType()));
     if (!this->visit(LHS))
       return false;
     if (!this->visit(RHS))
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 38aa5798cfeb9..1aee5d307f59c 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -11879,13 +11879,15 @@ bool VectorExprEvaluator::VisitBinaryOperator(const 
BinaryOperator *E) {
   Expr *LHS = E->getLHS();
   Expr *RHS = E->getRHS();
 
-  assert(LHS->getType()->isVectorType() && RHS->getType()->isVectorType() &&
+  QualType LHSTy = LHS->getType().getAtomicUnqualifiedType();
+  QualType RHSTy = RHS->getType().getAtomicUnqualifiedType();
+  assert(LHSTy->isVectorType() && RHSTy->isVectorType() &&
          "Must both be vector types");
   // Checking JUST the types are the same would be fine, except shifts don't
   // need to have their types be the same (since you always shift by an int).
-  assert(LHS->getType()->castAs<VectorType>()->getNumElements() ==
+  assert(LHSTy->castAs<VectorType>()->getNumElements() ==
              E->getType()->castAs<VectorType>()->getNumElements() &&
-         RHS->getType()->castAs<VectorType>()->getNumElements() ==
+         RHSTy->castAs<VectorType>()->getNumElements() ==
              E->getType()->castAs<VectorType>()->getNumElements() &&
          "All operands must be the same size.");
 
diff --git a/clang/test/AST/ByteCode/atomic-vector.c 
b/clang/test/AST/ByteCode/atomic-vector.c
new file mode 100644
index 0000000000000..0562e92e9f975
--- /dev/null
+++ b/clang/test/AST/ByteCode/atomic-vector.c
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 -triple x86_64 -emit-llvm %s -o -                           
              | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64 -emit-llvm %s -o - 
-fexperimental-new-constant-interpreter | FileCheck %s
+
+typedef int A __attribute__((__vector_size__(16)));
+
+void vector_to_atomic_vector() {
+  _Atomic(A) atomic_vec;
+  A vec;
+  atomic_vec = vec;
+}
+
+// CHECK: %[[ATOMIC_VEC_ADDR:.*]] = alloca <4 x i32>, align 16
+// CHECK: %[[VEC_ADDR:.*]] = alloca <4 x i32>, align 16
+// CHECK: %[[ATOMIC_TMP:.*]] = alloca <4 x i32>, align 16
+// CHECK: %[[TMP_VEC:.*]] = load <4 x i32>, ptr %[[VEC_ADDR]], align 16
+// CHECK: store <4 x i32> %[[TMP_VEC]], ptr %[[ATOMIC_TMP]], align 16
+// CHECK: call void @__atomic_store(i64 noundef 16, ptr noundef 
%[[ATOMIC_VEC_ADDR]], ptr noundef %[[ATOMIC_TMP]], i32 noundef 5)

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to