Author: Amr Hesham
Date: 2026-04-03T19:28:20+02:00
New Revision: 2108252f0e23c4e3adc61ab8097a73223a80843a

URL: 
https://github.com/llvm/llvm-project/commit/2108252f0e23c4e3adc61ab8097a73223a80843a
DIFF: 
https://github.com/llvm/llvm-project/commit/2108252f0e23c4e3adc61ab8097a73223a80843a.diff

LOG: [clang] Fixed a crash when explicitly casting to atomic complex (#172163)

Fixed a crash when explicitly casting a scalar to an atomic complex.

resolve: #114885

Added: 
    

Modified: 
    clang/docs/ReleaseNotes.rst
    clang/lib/CodeGen/CGExprComplex.cpp
    clang/test/CodeGen/complex.c

Removed: 
    


################################################################################
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

Reply via email to