[clang] [Clang] Fix ConstExpr comparing qualified atomic vec types (PR #199246)
Amr Hesham via cfe-commits
cfe-commits at lists.llvm.org
Wed May 27 09:51:29 PDT 2026
https://github.com/AmrDeveloper updated https://github.com/llvm/llvm-project/pull/199246
>From 652f8c8299948afa313d3c44e645fe0b1b3d0c08 Mon Sep 17 00:00:00 2001
From: Amr Hesham <amr96 at programmer.net>
Date: Tue, 19 May 2026 22:06:06 +0200
Subject: [PATCH 1/2] [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 1e58d91861ad5..5e9700adb542f 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 0522d6f1dc944..d14e6e61454ea 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)
>From 2bcca142f6f05f9549f2be511b1f3c4afaa2e15f Mon Sep 17 00:00:00 2001
From: Amr Hesham <amr96 at programmer.net>
Date: Wed, 27 May 2026 18:50:40 +0200
Subject: [PATCH 2/2] Add releasenote
---
clang/docs/ReleaseNotes.rst | 1 +
1 file changed, 1 insertion(+)
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 4fe64e88e7ff2..2c7a693352326 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -643,6 +643,7 @@ Bug Fixes in This Version
an array via an element-at-a-time copy loop (#GH192026)
- Fixed an issue where certain designated initializers would be rejected for constexpr variables. (#GH193373)
- Fixed a crash when ``#embed`` is used with C++ modules (#GH195350)
+- Fixed an assertion failure when assigning atomic vector to vector type in C (#GH54822).
Bug Fixes to Compiler Builtins
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
More information about the cfe-commits
mailing list