Skip to content

Commit f34f824

Browse files
AmrDeveloperlanza
authored andcommitted
[CIR] Backport ChooseExpr for AggregateExpr (#1950)
Backporting support ChooseExpr for AggregateExpr from upstream
1 parent b7e916d commit f34f824

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

clang/lib/CIR/CodeGen/CIRGenExpr.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2706,6 +2706,8 @@ LValue CIRGenFunction::emitLValue(const Expr *E) {
27062706
llvm_unreachable("cannot emit a property reference directly");
27072707
case Expr::StmtExprClass:
27082708
return emitStmtExprLValue(cast<StmtExpr>(E));
2709+
case Expr::ChooseExprClass:
2710+
return emitLValue(cast<ChooseExpr>(E)->getChosenSubExpr());
27092711
}
27102712

27112713
llvm_unreachable("NYI");

clang/lib/CIR/CodeGen/CIRGenExprAgg.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ class AggExprEmitter : public StmtVisitor<AggExprEmitter> {
291291
}
292292

293293
void VisitAbstractConditionalOperator(const AbstractConditionalOperator *E);
294-
void VisitChooseExpr(const ChooseExpr *E) { llvm_unreachable("NYI"); }
294+
void VisitChooseExpr(const ChooseExpr *E) { Visit(E->getChosenSubExpr()); }
295295
void VisitInitListExpr(InitListExpr *E);
296296
void VisitCXXParenListInitExpr(CXXParenListInitExpr *E);
297297
void VisitCXXParenListOrInitListExpr(Expr *ExprToVisit, ArrayRef<Expr *> Args,

clang/test/CIR/CodeGen/struct.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,3 +195,15 @@ void designated_init_update_expr() {
195195
// CHECK: %[[CONST_1:.*]] = cir.const #cir.int<1> : !s32i
196196
// CHECK: cir.store{{.*}} %[[CONST_1]], %[[ELEM_0_PTR]] : !s32i, !cir.ptr<!s32i>
197197
// CHECK: %[[ELEM_1_PTR:.*]] = cir.get_member %[[C_ADDR]][1] {name = "b"} : !cir.ptr<!rec_CompleteS> -> !cir.ptr<!s8i>
198+
199+
void choose_expr() {
200+
CompleteS a;
201+
CompleteS b;
202+
CompleteS c = __builtin_choose_expr(true, a, b);
203+
}
204+
205+
// CHECK: cir.func{{.*}} @_Z11choose_exprv()
206+
// CHECK: %[[A_ADDR:.*]] = cir.alloca !rec_CompleteS, !cir.ptr<!rec_CompleteS>, ["a"]
207+
// CHECK: %[[B_ADDR:.*]] = cir.alloca !rec_CompleteS, !cir.ptr<!rec_CompleteS>, ["b"]
208+
// CHECK: %[[C_ADDR:.*]] = cir.alloca !rec_CompleteS, !cir.ptr<!rec_CompleteS>, ["c", init]
209+
// CHECK: cir.copy %[[A_ADDR]] to %[[C_ADDR]] : !cir.ptr<!rec_CompleteS>

0 commit comments

Comments
 (0)