Skip to content

Commit c9ca354

Browse files
authored
[CIR] Upstream Atomic init for ComplexType (#156518)
This change adds support for Atomic init for ComplexType Issue: #141365
1 parent 1b130e3 commit c9ca354

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

clang/lib/CIR/CodeGen/CIRGenAtomic.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,9 @@ bool AtomicInfo::requiresMemSetZero(mlir::Type ty) const {
159159
case cir::TEK_Scalar:
160160
return !isFullSizeType(cgf.cgm, ty, atomicSizeInBits);
161161
case cir::TEK_Complex:
162-
cgf.cgm.errorNYI(loc, "AtomicInfo::requiresMemSetZero: complex type");
163-
return false;
164-
162+
return !isFullSizeType(cgf.cgm,
163+
mlir::cast<cir::ComplexType>(ty).getElementType(),
164+
atomicSizeInBits / 2);
165165
// Padding in structs has an undefined bit pattern. User beware.
166166
case cir::TEK_Aggregate:
167167
return false;
@@ -556,9 +556,11 @@ void CIRGenFunction::emitAtomicInit(Expr *init, LValue dest) {
556556
return;
557557
}
558558

559-
case cir::TEK_Complex:
560-
cgm.errorNYI(init->getSourceRange(), "emitAtomicInit: complex type");
559+
case cir::TEK_Complex: {
560+
mlir::Value value = emitComplexExpr(init);
561+
atomics.emitCopyIntoMemory(RValue::get(value));
561562
return;
563+
}
562564

563565
case cir::TEK_Aggregate:
564566
cgm.errorNYI(init->getSourceRange(), "emitAtomicInit: aggregate type");

clang/test/CIR/CodeGen/complex.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -909,3 +909,21 @@ void foo33(__builtin_va_list a) {
909909
// OGCG: %[[B_IMAG_PTR:.*]] = getelementptr inbounds nuw { float, float }, ptr %[[B_ADDR]], i32 0, i32 1
910910
// OGCG: store float %[[RESULT_REAL]], ptr %[[B_REAL_PTR]], align 4
911911
// OGCG: store float %[[RESULT_IMAG]], ptr %[[B_IMAG_PTR]], align 4
912+
913+
void foo34() {
914+
_Atomic(float _Complex) a;
915+
__c11_atomic_init(&a, {1.0f, 2.0f});
916+
}
917+
918+
// CIR: %[[A_ADDR:.*]] = cir.alloca !cir.complex<!cir.float>, !cir.ptr<!cir.complex<!cir.float>>, ["a"]
919+
// CIR: %[[CONST_COMPLEX:.*]] = cir.const #cir.const_complex<#cir.fp<1.000000e+00> : !cir.float, #cir.fp<2.000000e+00> : !cir.float> : !cir.complex<!cir.float>
920+
// CIR: cir.store{{.*}} %[[CONST_COMPLEX]], %[[A_ADDR]] : !cir.complex<!cir.float>, !cir.ptr<!cir.complex<!cir.float>>
921+
922+
// LLVM: %[[A_ADDR:.*]] = alloca { float, float }, i64 1, align 8
923+
// LLVM: store { float, float } { float 1.000000e+00, float 2.000000e+00 }, ptr %[[A_ADDR]], align 8
924+
925+
// OGCG: %[[A_ADDR:.*]] = alloca { float, float }, align 8
926+
// OGCG: %[[A_REAL_PTR:.*]] = getelementptr inbounds nuw { float, float }, ptr %[[A_ADDR]], i32 0, i32 0
927+
// OGCG: %[[A_IMAG_PTR:.*]] = getelementptr inbounds nuw { float, float }, ptr %[[A_ADDR]], i32 0, i32 1
928+
// OGCG: store float 1.000000e+00, ptr %[[A_REAL_PTR]], align 8
929+
// OGCG: store float 2.000000e+00, ptr %[[A_IMAG_PTR]], align 4

0 commit comments

Comments
 (0)