https://github.com/AmrDeveloper updated https://github.com/llvm/llvm-project/pull/172163
>From bd0fb833c84c4c3c50eb8685a94b4edbc97642ce Mon Sep 17 00:00:00 2001 From: Amr Hesham <[email protected]> Date: Sat, 13 Dec 2025 16:46:33 +0100 Subject: [PATCH] [clang] Fixed a crash when explicitly casting to atomic complex --- clang/docs/ReleaseNotes.rst | 1 + clang/lib/CodeGen/CGExprComplex.cpp | 5 ++--- clang/test/CodeGen/complex.c | 14 ++++++++++++++ 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 442ec58adc25a..3f28890a03d40 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -463,6 +463,7 @@ Miscellaneous Clang Crashes Fixed - Fixed a crash when ``decltype(__builtin_FUNCTION())`` is used as a template type argument. (#GH167433) - Fixed an assertion failure when parsing an invalid ``decltype`` specifier with missing parentheses or extra semicolons. (#GH188014) - Fixed a crash when explicitly casting a complex type to or from an atomic complex type. (#GH172208) +- Fixed a crash when explicitly casting a scalar to an atomic complex. (#GH114885) OpenACC Specific Changes ------------------------ diff --git a/clang/lib/CodeGen/CGExprComplex.cpp b/clang/lib/CodeGen/CGExprComplex.cpp index a97441d3b63c4..757663eb50f58 100644 --- a/clang/lib/CodeGen/CGExprComplex.cpp +++ b/clang/lib/CodeGen/CGExprComplex.cpp @@ -538,6 +538,7 @@ ComplexPairTy ComplexExprEmitter::EmitScalarToComplexCast(llvm::Value *Val, ComplexPairTy ComplexExprEmitter::EmitCast(CastKind CK, Expr *Op, QualType DestTy) { + DestTy = DestTy.getAtomicUnqualifiedType(); switch (CK) { case CK_Dependent: llvm_unreachable("dependent cast kind in IR gen!"); @@ -1219,9 +1220,7 @@ LValue ComplexExprEmitter::EmitCompoundAssignLValue( ComplexPairTy (ComplexExprEmitter::*Func)(const BinOpInfo &), RValue &Val) { TestAndClearIgnoreReal(); TestAndClearIgnoreImag(); - QualType LHSTy = E->getLHS()->getType(); - if (const AtomicType *AT = LHSTy->getAs<AtomicType>()) - LHSTy = AT->getValueType(); + QualType LHSTy = E->getLHS()->getType().getAtomicUnqualifiedType(); BinOpInfo OpInfo; OpInfo.FPFeatures = E->getFPFeaturesInEffect(CGF.getLangOpts()); diff --git a/clang/test/CodeGen/complex.c b/clang/test/CodeGen/complex.c index c6fe7c23072a6..ffa23badba09e 100644 --- a/clang/test/CodeGen/complex.c +++ b/clang/test/CodeGen/complex.c @@ -678,6 +678,20 @@ void explicit_cast_complex_to_atomic_complex() { _Atomic _Complex int b = (_Atomic _Complex int)a; } +// CHECK-LABEL: define dso_local void @explicit_cast_scalar_to_atomic_complex( +// CHECK-SAME: ) #[[ATTR0]] { +// CHECK-NEXT: [[ENTRY:.*:]] +// CHECK-NEXT: [[A:%.*]] = alloca { float, float }, align 8 +// CHECK-NEXT: [[A_REALP:%.*]] = getelementptr inbounds nuw { float, float }, ptr [[A]], i32 0, i32 0 +// CHECK-NEXT: [[A_IMAGP:%.*]] = getelementptr inbounds nuw { float, float }, ptr [[A]], i32 0, i32 1 +// CHECK-NEXT: store float 2.000000e+00, ptr [[A_REALP]], align 8 +// CHECK-NEXT: store float 0.000000e+00, ptr [[A_IMAGP]], align 4 +// CHECK-NEXT: ret void +// +void explicit_cast_scalar_to_atomic_complex() { + _Atomic _Complex float a = (_Atomic _Complex float)2.0f; +} + //. // CHECK: [[PROF2]] = !{!"branch_weights", i32 1, i32 1048575} //. _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
