https://github.com/AmrDeveloper updated https://github.com/llvm/llvm-project/pull/172163
>From 72a3d2f737120526a4b0d8cc3686516c1c91b4fa 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 | 10 +++++----- clang/test/CodeGen/complex.c | 15 +++++++++++++++ 3 files changed, 21 insertions(+), 5 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..d07ee00937171 100644 --- a/clang/lib/CodeGen/CGExprComplex.cpp +++ b/clang/lib/CodeGen/CGExprComplex.cpp @@ -181,14 +181,16 @@ class ComplexExprEmitter // here. if (E->changesVolatileQualification()) return EmitLoadOfLValue(E); - return EmitCast(E->getCastKind(), E->getSubExpr(), E->getType()); + return EmitCast(E->getCastKind(), E->getSubExpr(), + E->getType().getAtomicUnqualifiedType()); } ComplexPairTy VisitCastExpr(CastExpr *E) { if (const auto *ECE = dyn_cast<ExplicitCastExpr>(E)) CGF.CGM.EmitExplicitCastExprType(ECE, &CGF); if (E->changesVolatileQualification()) return EmitLoadOfLValue(E); - return EmitCast(E->getCastKind(), E->getSubExpr(), E->getType()); + return EmitCast(E->getCastKind(), E->getSubExpr(), + E->getType().getAtomicUnqualifiedType()); } ComplexPairTy VisitCallExpr(const CallExpr *E); ComplexPairTy VisitStmtExpr(const StmtExpr *E); @@ -1219,9 +1221,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..de6fbb57319dc 100644 --- a/clang/test/CodeGen/complex.c +++ b/clang/test/CodeGen/complex.c @@ -678,6 +678,21 @@ 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
