Skip to content

Commit 4509f80

Browse files
committed
[CIR] CompoundLiteralExpr for Aggregate types
1 parent aa70f66 commit 4509f80

File tree

3 files changed

+50
-3
lines changed

3 files changed

+50
-3
lines changed

clang/lib/CIR/CodeGen/CIRGenExprAggregate.cpp

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,35 @@ class AggExprEmitter : public StmtVisitor<AggExprEmitter> {
180180
cgf.cgm.errorNYI(e->getSourceRange(), "AggExprEmitter: VisitStringLiteral");
181181
}
182182
void VisitCompoundLiteralExpr(CompoundLiteralExpr *e) {
183-
cgf.cgm.errorNYI(e->getSourceRange(),
184-
"AggExprEmitter: VisitCompoundLiteralExpr");
183+
if (dest.isPotentiallyAliased() &&
184+
e->getType().isPODType(cgf.getContext())) {
185+
cgf.cgm.errorNYI(e->getSourceRange(),
186+
"AggExprEmitter: VisitCompoundLiteralExpr PODType");
187+
return;
188+
}
189+
190+
AggValueSlot slot =
191+
ensureSlot(cgf.getLoc(e->getSourceRange()), e->getType());
192+
193+
// Block-scope compound literals are destroyed at the end of the enclosing
194+
// scope in C.
195+
bool destruct =
196+
!cgf.getLangOpts().CPlusPlus && !slot.isExternallyDestructed();
197+
if (destruct) {
198+
cgf.cgm.errorNYI(
199+
e->getSourceRange(),
200+
"AggExprEmitter: VisitCompoundLiteralExpr setExternallyDestructed");
201+
return;
202+
}
203+
204+
cgf.emitAggExpr(e->getInitializer(), slot);
205+
206+
if (destruct && e->getType().isDestructedType())
207+
cgf.cgm.errorNYI(
208+
e->getSourceRange(),
209+
"AggExprEmitter: VisitCompoundLiteralExpr destructed type");
185210
}
211+
186212
void VisitPredefinedExpr(const PredefinedExpr *e) {
187213
cgf.cgm.errorNYI(e->getSourceRange(),
188214
"AggExprEmitter: VisitPredefinedExpr");
@@ -550,7 +576,7 @@ void AggExprEmitter::emitNullInitializationToLValue(mlir::Location loc,
550576
return;
551577
}
552578

553-
cgf.cgm.errorNYI("emitStoreThroughBitfieldLValue");
579+
cgf.emitStoreThroughBitfieldLValue(RValue::get(null), lv);
554580
return;
555581
}
556582

clang/lib/CIR/CodeGen/CIRGenValue.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,8 @@ class AggValueSlot {
390390

391391
IsZeroed_t isZeroed() const { return IsZeroed_t(zeroedFlag); }
392392

393+
IsAliased_t isPotentiallyAliased() const { return IsAliased_t(aliasedFlag); }
394+
393395
RValue asRValue() const {
394396
if (isIgnored())
395397
return RValue::getIgnored();

clang/test/CIR/CodeGen/struct.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,3 +280,22 @@ void bin_comma() {
280280
// OGCG: define{{.*}} void @_Z9bin_commav()
281281
// OGCG: %[[A_ADDR:.*]] = alloca %struct.CompleteS, align 4
282282
// OGCG: call void @llvm.memset.p0.i64(ptr align 4 %[[A_ADDR]], i8 0, i64 8, i1 false)
283+
284+
void compound_literal_expr() { CompleteS a = (CompleteS){}; }
285+
286+
// CIR: %[[A_ADDR:.*]] = cir.alloca !rec_CompleteS, !cir.ptr<!rec_CompleteS>, ["a", init]
287+
// CIR: %[[A_ELEM_0_PTR:.*]] = cir.get_member %[[A_ADDR]][0] {name = "a"} : !cir.ptr<!rec_CompleteS> -> !cir.ptr<!s32i>
288+
// CIR: %[[CONST_0:.*]] = cir.const #cir.int<0> : !s32i
289+
// CIR: cir.store{{.*}} %[[CONST_0]], %[[A_ELEM_0_PTR]] : !s32i, !cir.ptr<!s32i>
290+
// CIR: %[[A_ELEM_1_PTR:.*]] = cir.get_member %[[A_ADDR]][1] {name = "b"} : !cir.ptr<!rec_CompleteS> -> !cir.ptr<!s8i>
291+
// CIR: %[[CONST_0:.*]] = cir.const #cir.int<0> : !s8i
292+
// CIR: cir.store{{.*}} %[[CONST_0]], %[[A_ELEM_1_PTR]] : !s8i, !cir.ptr<!s8i>
293+
294+
// LLVM: %[[A_ADDR:.*]] = alloca %struct.CompleteS, i64 1, align 4
295+
// LLVM: %[[A_ELEM_0_PTR:.*]] = getelementptr %struct.CompleteS, ptr %[[A_ADDR]], i32 0, i32 0
296+
// LLVM: store i32 0, ptr %[[A_ELEM_0_PTR]], align 4
297+
// LLVM: %[[A_ELEM_1_PTR:.*]] = getelementptr %struct.CompleteS, ptr %[[A_ADDR]], i32 0, i32 1
298+
// LLVM: store i8 0, ptr %[[A_ELEM_1_PTR]], align 4
299+
300+
// OGCG: %[[A_ADDR:.*]] = alloca %struct.CompleteS, align 4
301+
// OGCG: call void @llvm.memset.p0.i64(ptr align 4 %[[A_ADDR]], i8 0, i64 8, i1 false)

0 commit comments

Comments
 (0)