Skip to content

Commit d9f88a3

Browse files
committed
[CIR] Implement GenericSelectionExpr for AggregateExpr
1 parent ee8394d commit d9f88a3

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

clang/lib/CIR/CodeGen/CIRGenExprAggregate.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,7 @@ class AggExprEmitter : public StmtVisitor<AggExprEmitter> {
133133
}
134134
void VisitParenExpr(ParenExpr *pe) { Visit(pe->getSubExpr()); }
135135
void VisitGenericSelectionExpr(GenericSelectionExpr *ge) {
136-
cgf.cgm.errorNYI(ge->getSourceRange(),
137-
"AggExprEmitter: VisitGenericSelectionExpr");
136+
Visit(ge->getResultExpr());
138137
}
139138
void VisitCoawaitExpr(CoawaitExpr *e) {
140139
cgf.cgm.errorNYI(e->getSourceRange(), "AggExprEmitter: VisitCoawaitExpr");

clang/lib/CIR/CodeGen/CIRGenFunction.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -832,6 +832,8 @@ LValue CIRGenFunction::emitLValue(const Expr *e) {
832832
return emitCallExprLValue(cast<CallExpr>(e));
833833
case Expr::ParenExprClass:
834834
return emitLValue(cast<ParenExpr>(e)->getSubExpr());
835+
case Expr::GenericSelectionExprClass:
836+
return emitLValue(cast<GenericSelectionExpr>(e)->getResultExpr());
835837
case Expr::DeclRefExprClass:
836838
return emitDeclRefLValue(cast<DeclRefExpr>(e));
837839
case Expr::CStyleCastExprClass:

clang/test/CIR/CodeGen/struct.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,3 +154,31 @@ void choose_expr() {
154154
// OGCG: %[[B_ADDR:.*]] = alloca %struct.CompleteS, align 4
155155
// OGCG: %[[C_ADDR:.*]] = alloca %struct.CompleteS, align 4
156156
// OGCG: call void @llvm.memcpy.p0.p0.i64(ptr align 4 %[[C_ADDR]], ptr align 4 %[[A_ADDR]], i64 8, i1 false)
157+
158+
void generic_selection() {
159+
CompleteS a;
160+
CompleteS b;
161+
int c;
162+
CompleteS d = _Generic(c, int : a, default: b);
163+
}
164+
165+
// CIR: cir.func{{.*}} @_Z17generic_selectionv()
166+
// CIR: %[[A_ADDR:.*]] = cir.alloca !rec_CompleteS, !cir.ptr<!rec_CompleteS>, ["a"]
167+
// CIR: %[[B_ADDR:.*]] = cir.alloca !rec_CompleteS, !cir.ptr<!rec_CompleteS>, ["b"]
168+
// CIR: %[[C_ADDR:.*]] = cir.alloca !s32i, !cir.ptr<!s32i>, ["c"]
169+
// CIR: %[[D_ADDR:.*]] = cir.alloca !rec_CompleteS, !cir.ptr<!rec_CompleteS>, ["d", init]
170+
// CIR: cir.call @_ZN9CompleteSC1ERKS_(%[[D_ADDR]], %[[A_ADDR]]) nothrow : (!cir.ptr<!rec_CompleteS>, !cir.ptr<!rec_CompleteS>) -> ()
171+
172+
// LLVM: define{{.*}} void @_Z17generic_selectionv()
173+
// LLVM: %1 = alloca %struct.CompleteS, i64 1, align 4
174+
// LLVM: %2 = alloca %struct.CompleteS, i64 1, align 4
175+
// LLVM: %3 = alloca i32, i64 1, align 4
176+
// LLVM: %4 = alloca %struct.CompleteS, i64 1, align 4
177+
// LLVM: call void @_ZN9CompleteSC1ERKS_(ptr %4, ptr %1)
178+
179+
// OGCG: define{{.*}} void @_Z17generic_selectionv()
180+
// OGCG: %[[A_ADDR:.*]] = alloca %struct.CompleteS, align 4
181+
// OGCG: %[[B_ADDR:.*]] = alloca %struct.CompleteS, align 4
182+
// OGCG: %[[C_ADDR:.*]] = alloca i32, align 4
183+
// OGCG: %[[D_ADDR:.*]] = alloca %struct.CompleteS, align 4
184+
// OGCG: call void @llvm.memcpy.p0.p0.i64(ptr align 4 %[[D_ADDR]], ptr align 4 %[[A_ADDR]], i64 8, i1 false)

0 commit comments

Comments
 (0)