Skip to content

Commit 66c5964

Browse files
authored
[CIR] Backport GenericSelectionExpr for AggregateExpr (#1947)
Backporting support the GenericSelectionExpr for AggregateExpr from upstream
1 parent 1cc8176 commit 66c5964

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

clang/lib/CIR/CodeGen/CIRGenExpr.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2671,6 +2671,8 @@ LValue CIRGenFunction::emitLValue(const Expr *E) {
26712671
}
26722672
case Expr::ParenExprClass:
26732673
return emitLValue(cast<ParenExpr>(E)->getSubExpr());
2674+
case Expr::GenericSelectionExprClass:
2675+
return emitLValue(cast<GenericSelectionExpr>(E)->getResultExpr());
26742676
case Expr::DeclRefExprClass:
26752677
return emitDeclRefLValue(cast<DeclRefExpr>(E));
26762678
case Expr::UnaryOperatorClass:

clang/lib/CIR/CodeGen/CIRGenExprAgg.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ class AggExprEmitter : public StmtVisitor<AggExprEmitter> {
179179
}
180180
void VisitParenExpr(ParenExpr *PE) { Visit(PE->getSubExpr()); }
181181
void VisitGenericSelectionExpr(GenericSelectionExpr *GE) {
182-
llvm_unreachable("NYI");
182+
Visit(GE->getResultExpr());
183183
}
184184
void VisitCoawaitExpr(CoawaitExpr *E) {
185185
CGF.emitCoawaitExpr(*E, Dest, IsResultUnused);

clang/test/CIR/CodeGen/struct.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,19 @@ void designated_init_update_expr() {
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>
198198

199+
void generic_selection() {
200+
CompleteS a;
201+
CompleteS b;
202+
int c;
203+
CompleteS d = _Generic(c, int : a, default: b);
204+
}
205+
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 !s32i, !cir.ptr<!s32i>, ["c"]
209+
// CHECK: %[[D_ADDR:.*]] = cir.alloca !rec_CompleteS, !cir.ptr<!rec_CompleteS>, ["d", init]
210+
// CHECK: cir.copy %[[A_ADDR]] to %[[D_ADDR]] : !cir.ptr<!rec_CompleteS>
211+
199212
void choose_expr() {
200213
CompleteS a;
201214
CompleteS b;
@@ -206,4 +219,4 @@ void choose_expr() {
206219
// CHECK: %[[A_ADDR:.*]] = cir.alloca !rec_CompleteS, !cir.ptr<!rec_CompleteS>, ["a"]
207220
// CHECK: %[[B_ADDR:.*]] = cir.alloca !rec_CompleteS, !cir.ptr<!rec_CompleteS>, ["b"]
208221
// 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>
222+
// CHECK: cir.copy %[[A_ADDR]] to %[[C_ADDR]] : !cir.ptr<!rec_CompleteS>

0 commit comments

Comments
 (0)