Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions clang/lib/CIR/CodeGen/CIRGenAtomic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -718,10 +718,26 @@ void CIRGenFunction::emitAtomicInit(Expr *init, LValue dest) {
return;
}

case cir::TEK_Aggregate:
cgm.errorNYI(init->getSourceRange(), "emitAtomicInit: aggregate type");
case cir::TEK_Aggregate: {
// Fix up the destination if the initializer isn't an expression
// of atomic type.
bool zeroed = false;
if (!init->getType()->isAtomicType()) {
zeroed = atomics.emitMemSetZeroIfNecessary();
dest = atomics.projectValue();
}

// Evaluate the expression directly into the destination.
assert(!cir::MissingFeatures::aggValueSlotGC());
AggValueSlot slot = AggValueSlot::forLValue(
dest, AggValueSlot::IsNotDestructed, AggValueSlot::IsNotAliased,
AggValueSlot::DoesNotOverlap,
zeroed ? AggValueSlot::IsZeroed : AggValueSlot::IsNotZeroed);

emitAggExpr(init, slot);
return;
}
}

llvm_unreachable("bad evaluation kind");
}
28 changes: 28 additions & 0 deletions clang/test/CIR/CodeGen/struct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,34 @@ void generic_selection() {
// OGCG: %[[D_ADDR:.*]] = alloca %struct.CompleteS, align 4
// OGCG: call void @llvm.memcpy.p0.p0.i64(ptr align 4 %[[D_ADDR]], ptr align 4 %[[A_ADDR]], i64 8, i1 false)

void atomic_init() {
_Atomic CompleteS a;
__c11_atomic_init(&a, {});
}

// CIR: cir.func{{.*}} @_Z11atomic_initv()
// CIR: %[[A_ADDR:.*]] = cir.alloca !rec_CompleteS, !cir.ptr<!rec_CompleteS>, ["a"]
// CIR: %[[ELEM_0_PTR:.*]] = cir.get_member %[[A_ADDR]][0] {name = "a"} : !cir.ptr<!rec_CompleteS> -> !cir.ptr<!s32i>
// CIR: %[[CONST_0:.*]] = cir.const #cir.int<0> : !s32i
// CIR: cir.store{{.*}} %[[CONST_0]], %[[ELEM_0_PTR]] : !s32i, !cir.ptr<!s32i>
// CIR: %[[ELEM_1_PTR:.*]] = cir.get_member %[[A_ADDR]][1] {name = "b"} : !cir.ptr<!rec_CompleteS> -> !cir.ptr<!s8i>
// CIR: %[[CONST_0:.*]] = cir.const #cir.int<0> : !s8i
// CIR: cir.store{{.*}} %[[CONST_0]], %[[ELEM_1_PTR]] : !s8i, !cir.ptr<!s8i>

// LLVM: define{{.*}} void @_Z11atomic_initv()
// LLVM: %[[A_ADDR:.*]] = alloca %struct.CompleteS, i64 1, align 8
// LLVM: %[[ELEM_0_PTR:.*]] = getelementptr %struct.CompleteS, ptr %[[A_ADDR]], i32 0, i32 0
// LLVM: store i32 0, ptr %[[ELEM_0_PTR]], align 8
// LLVM: %[[ELEM_1_PTR:.*]] = getelementptr %struct.CompleteS, ptr %[[A_ADDR]], i32 0, i32 1
// LLVM: store i8 0, ptr %[[ELEM_1_PTR]], align 4

// OGCG: define{{.*}} void @_Z11atomic_initv()
// OGCG: %[[A_ADDR:.*]] = alloca %struct.CompleteS, align 8
// OGCG: %[[ELEM_0_PTR:.*]] = getelementptr inbounds nuw %struct.CompleteS, ptr %[[A_ADDR]], i32 0, i32 0
// OGCG: store i32 0, ptr %[[ELEM_0_PTR]], align 8
// OGCG: %[[ELEM_1_PTR:.*]] = getelementptr inbounds nuw %struct.CompleteS, ptr %[[A_ADDR]], i32 0, i32 1
// OGCG: store i8 0, ptr %[[ELEM_1_PTR]], align 4

void unary_extension() {
CompleteS a = __extension__ CompleteS();
}
Expand Down