diff --git a/clang/lib/CIR/CodeGen/CIRGenExprAggregate.cpp b/clang/lib/CIR/CodeGen/CIRGenExprAggregate.cpp index af42d1d882ae0..1e987f3bedc7e 100644 --- a/clang/lib/CIR/CodeGen/CIRGenExprAggregate.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenExprAggregate.cpp @@ -133,8 +133,7 @@ class AggExprEmitter : public StmtVisitor { } void VisitParenExpr(ParenExpr *pe) { Visit(pe->getSubExpr()); } void VisitGenericSelectionExpr(GenericSelectionExpr *ge) { - cgf.cgm.errorNYI(ge->getSourceRange(), - "AggExprEmitter: VisitGenericSelectionExpr"); + Visit(ge->getResultExpr()); } void VisitCoawaitExpr(CoawaitExpr *e) { cgf.cgm.errorNYI(e->getSourceRange(), "AggExprEmitter: VisitCoawaitExpr"); diff --git a/clang/lib/CIR/CodeGen/CIRGenFunction.cpp b/clang/lib/CIR/CodeGen/CIRGenFunction.cpp index 9d98361a8b6a2..f836e29866036 100644 --- a/clang/lib/CIR/CodeGen/CIRGenFunction.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenFunction.cpp @@ -832,6 +832,8 @@ LValue CIRGenFunction::emitLValue(const Expr *e) { return emitCallExprLValue(cast(e)); case Expr::ParenExprClass: return emitLValue(cast(e)->getSubExpr()); + case Expr::GenericSelectionExprClass: + return emitLValue(cast(e)->getResultExpr()); case Expr::DeclRefExprClass: return emitDeclRefLValue(cast(e)); case Expr::CStyleCastExprClass: diff --git a/clang/test/CIR/CodeGen/struct.cpp b/clang/test/CIR/CodeGen/struct.cpp index 1dc16f3b79497..96db82a89977c 100644 --- a/clang/test/CIR/CodeGen/struct.cpp +++ b/clang/test/CIR/CodeGen/struct.cpp @@ -154,3 +154,32 @@ void choose_expr() { // OGCG: %[[B_ADDR:.*]] = alloca %struct.CompleteS, align 4 // OGCG: %[[C_ADDR:.*]] = alloca %struct.CompleteS, align 4 // OGCG: call void @llvm.memcpy.p0.p0.i64(ptr align 4 %[[C_ADDR]], ptr align 4 %[[A_ADDR]], i64 8, i1 false) + +void generic_selection() { + CompleteS a; + CompleteS b; + int c; + CompleteS d = _Generic(c, int : a, default: b); +} + +// CIR: cir.func{{.*}} @_Z17generic_selectionv() +// CIR: %[[A_ADDR:.*]] = cir.alloca !rec_CompleteS, !cir.ptr, ["a"] +// CIR: %[[B_ADDR:.*]] = cir.alloca !rec_CompleteS, !cir.ptr, ["b"] +// CIR: %[[C_ADDR:.*]] = cir.alloca !s32i, !cir.ptr, ["c"] +// CIR: %[[D_ADDR:.*]] = cir.alloca !rec_CompleteS, !cir.ptr, ["d", init] +// TODO(cir): Call to default copy constructor should be replaced by `cir.copy` op +// CIR: cir.call @_ZN9CompleteSC1ERKS_(%[[D_ADDR]], %[[A_ADDR]]) nothrow : (!cir.ptr, !cir.ptr) -> () + +// LLVM: define{{.*}} void @_Z17generic_selectionv() +// LLVM: %1 = alloca %struct.CompleteS, i64 1, align 4 +// LLVM: %2 = alloca %struct.CompleteS, i64 1, align 4 +// LLVM: %3 = alloca i32, i64 1, align 4 +// LLVM: %4 = alloca %struct.CompleteS, i64 1, align 4 +// LLVM: call void @_ZN9CompleteSC1ERKS_(ptr %4, ptr %1) + +// OGCG: define{{.*}} void @_Z17generic_selectionv() +// OGCG: %[[A_ADDR:.*]] = alloca %struct.CompleteS, align 4 +// OGCG: %[[B_ADDR:.*]] = alloca %struct.CompleteS, align 4 +// OGCG: %[[C_ADDR:.*]] = alloca i32, align 4 +// OGCG: %[[D_ADDR:.*]] = alloca %struct.CompleteS, align 4 +// OGCG: call void @llvm.memcpy.p0.p0.i64(ptr align 4 %[[D_ADDR]], ptr align 4 %[[A_ADDR]], i64 8, i1 false)