https://github.com/AmrDeveloper created https://github.com/llvm/llvm-project/pull/207811
Change the expected type to reflect the emitted AST after Clang 17, which will not emit the two extra ImplicitCastExpr to make the type totally equal to the subexpr type Issue #115664 >From dea1226be4780771665e68a9ecf693307d4213d1 Mon Sep 17 00:00:00 2001 From: Amr Hesham <[email protected]> Date: Sun, 5 Jul 2026 22:23:03 +0200 Subject: [PATCH] [Clang] Fix aggregate emitter assertion for Atomic cast --- clang/lib/CodeGen/CGExprAgg.cpp | 5 +++-- clang/test/CodeGen/agg-atomic-cast.cpp | 27 ++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 clang/test/CodeGen/agg-atomic-cast.cpp diff --git a/clang/lib/CodeGen/CGExprAgg.cpp b/clang/lib/CodeGen/CGExprAgg.cpp index bc35ffdaad2bd..0a107cb3146e2 100644 --- a/clang/lib/CodeGen/CGExprAgg.cpp +++ b/clang/lib/CodeGen/CGExprAgg.cpp @@ -1056,8 +1056,9 @@ void AggExprEmitter::VisitCastExpr(CastExpr *E) { case CK_NoOp: case CK_UserDefinedConversion: case CK_ConstructorConversion: - assert(CGF.getContext().hasSameUnqualifiedType(E->getSubExpr()->getType(), - E->getType()) && + assert(CGF.getContext().hasSameUnqualifiedType( + E->getSubExpr()->getType().getAtomicUnqualifiedType(), + E->getType().getAtomicUnqualifiedType()) && "Implicit cast types must be compatible"); Visit(E->getSubExpr()); break; diff --git a/clang/test/CodeGen/agg-atomic-cast.cpp b/clang/test/CodeGen/agg-atomic-cast.cpp new file mode 100644 index 0000000000000..fdb6a91ce40d0 --- /dev/null +++ b/clang/test/CodeGen/agg-atomic-cast.cpp @@ -0,0 +1,27 @@ +// RUN: %clang_cc1 %s -triple=x86_64-linux -emit-llvm -o - | FileCheck %s + +struct S { + char a; +}; + +void static_cast_non_atomic_to_atomic() { + _Atomic struct S sa; + S s; + sa = static_cast<_Atomic(struct S)>(s); +} + +// CHECK: %[[SA_ADDR:.*]] = alloca %struct.S, align 1 +// CHECK: %[[S_ADDR:.*]] = alloca %struct.S, align 1 +// CHECK: %[[TMP_ADDR:.*]] = alloca %struct.S, align 1 +// CHECK: call void @llvm.memcpy.p0.p0.i64(ptr align 1 %[[TMP_ADDR]], ptr align 1 %[[S_ADDR]], i64 1, i1 false) +// CHECK: %[[TMP:.*]] = load i8, ptr %[[TMP_ADDR]], align 1 +// CHECK: store atomic i8 %[[TMP]], ptr %[[SA_ADDR]] seq_cst, align 1 + +void non_atomic_to_atomic_cast() { + S s; + _Atomic(S) sa = (_Atomic(S)) s; +} + +// CHECK: %[[S_ADDR:.*]] = alloca %struct.S, align 1 +// CHECK: %[[SA_ADDR:.*]] = alloca %struct.S, align 1 +// CHECK: call void @llvm.memcpy.p0.p0.i64(ptr align 1 %[[SA_ADDR]], ptr align 1 %[[S_ADDR]], i64 1, i1 false) _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
