Skip to content

Commit ee8394d

Browse files
authored
[CIR] Implement ChooseExpr for AggregateExpr (#160999)
Implement the ChooseExpr for aggregate expr
1 parent 66af942 commit ee8394d

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

clang/lib/CIR/CodeGen/CIRGenExprAggregate.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -211,9 +211,7 @@ class AggExprEmitter : public StmtVisitor<AggExprEmitter> {
211211
cgf.cgm.errorNYI(e->getSourceRange(),
212212
"AggExprEmitter: VisitAbstractConditionalOperator");
213213
}
214-
void VisitChooseExpr(const ChooseExpr *e) {
215-
cgf.cgm.errorNYI(e->getSourceRange(), "AggExprEmitter: VisitChooseExpr");
216-
}
214+
void VisitChooseExpr(const ChooseExpr *e) { Visit(e->getChosenSubExpr()); }
217215
void VisitCXXParenListInitExpr(CXXParenListInitExpr *e) {
218216
cgf.cgm.errorNYI(e->getSourceRange(),
219217
"AggExprEmitter: VisitCXXParenListInitExpr");

clang/lib/CIR/CodeGen/CIRGenFunction.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -841,6 +841,8 @@ LValue CIRGenFunction::emitLValue(const Expr *e) {
841841
return emitCastLValue(cast<CastExpr>(e));
842842
case Expr::MaterializeTemporaryExprClass:
843843
return emitMaterializeTemporaryExpr(cast<MaterializeTemporaryExpr>(e));
844+
case Expr::ChooseExprClass:
845+
return emitLValue(cast<ChooseExpr>(e)->getChosenSubExpr());
844846
}
845847
}
846848

clang/test/CIR/CodeGen/struct.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,3 +129,28 @@ void paren_expr() {
129129
// OGCG: %[[B_ADDR:.*]] = alloca %struct.Point, align 4
130130
// OGCG: call void @llvm.memset.p0.i64(ptr align 4 %[[A_ADDR]], i8 0, i64 8, i1 false)
131131
// OGCG: call void @llvm.memcpy.p0.p0.i64(ptr align 4 %[[B_ADDR]], ptr align 4 %[[A_ADDR]], i64 8, i1 false)
132+
133+
void choose_expr() {
134+
CompleteS a;
135+
CompleteS b;
136+
CompleteS c = __builtin_choose_expr(true, a, b);
137+
}
138+
139+
// CIR: cir.func{{.*}} @_Z11choose_exprv()
140+
// CIR: %[[A_ADDR:.*]] = cir.alloca !rec_CompleteS, !cir.ptr<!rec_CompleteS>, ["a"]
141+
// CIR: %[[B_ADDR:.*]] = cir.alloca !rec_CompleteS, !cir.ptr<!rec_CompleteS>, ["b"]
142+
// CIR: %[[C_ADDR:.*]] = cir.alloca !rec_CompleteS, !cir.ptr<!rec_CompleteS>, ["c", init]
143+
// TODO(cir): Call to default copy constructor should be replaced by `cir.copy` op
144+
// CIR: cir.call @_ZN9CompleteSC1ERKS_(%[[C_ADDR]], %[[A_ADDR]]) nothrow : (!cir.ptr<!rec_CompleteS>, !cir.ptr<!rec_CompleteS>) -> ()
145+
146+
// LLVM: define{{.*}} void @_Z11choose_exprv()
147+
// LLVM: %[[A_ADDR:.*]] = alloca %struct.CompleteS, i64 1, align 4
148+
// LLVM: %[[B_ADDR:.*]] = alloca %struct.CompleteS, i64 1, align 4
149+
// LLVM: %[[C_ADDR:.*]] = alloca %struct.CompleteS, i64 1, align 4
150+
// LLVM: call void @_ZN9CompleteSC1ERKS_(ptr %[[C_ADDR]], ptr %[[A_ADDR]])
151+
152+
// OGCG: define{{.*}} void @_Z11choose_exprv()
153+
// OGCG: %[[A_ADDR:.*]] = alloca %struct.CompleteS, align 4
154+
// OGCG: %[[B_ADDR:.*]] = alloca %struct.CompleteS, align 4
155+
// OGCG: %[[C_ADDR:.*]] = alloca %struct.CompleteS, align 4
156+
// OGCG: call void @llvm.memcpy.p0.p0.i64(ptr align 4 %[[C_ADDR]], ptr align 4 %[[A_ADDR]], i64 8, i1 false)

0 commit comments

Comments
 (0)