From 3b686c22a42b093b8e6316c00aa673512378b484 Mon Sep 17 00:00:00 2001 From: Sirui Mu Date: Tue, 2 Jan 2024 09:23:09 +0800 Subject: [PATCH] [CIR][CodeGen] codegen of lvalue comma expression --- clang/lib/CIR/CodeGen/CIRGenExpr.cpp | 3 ++- clang/test/CIR/CodeGen/comma.cpp | 13 +++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/clang/lib/CIR/CodeGen/CIRGenExpr.cpp b/clang/lib/CIR/CodeGen/CIRGenExpr.cpp index 9204a40f9f1e..cd1e0873e016 100644 --- a/clang/lib/CIR/CodeGen/CIRGenExpr.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenExpr.cpp @@ -868,7 +868,8 @@ LValue CIRGenFunction::buildDeclRefLValue(const DeclRefExpr *E) { LValue CIRGenFunction::buildBinaryOperatorLValue(const BinaryOperator *E) { // Comma expressions just emit their LHS then their RHS as an l-value. if (E->getOpcode() == BO_Comma) { - assert(0 && "not implemented"); + buildIgnoredExpr(E->getLHS()); + return buildLValue(E->getRHS()); } if (E->getOpcode() == BO_PtrMemD || E->getOpcode() == BO_PtrMemI) diff --git a/clang/test/CIR/CodeGen/comma.cpp b/clang/test/CIR/CodeGen/comma.cpp index a5338014bc85..04bb1c5b622b 100644 --- a/clang/test/CIR/CodeGen/comma.cpp +++ b/clang/test/CIR/CodeGen/comma.cpp @@ -15,3 +15,16 @@ int c0() { // CHECK: %[[#]] = cir.binop(add, %[[#LOADED_B]], %[[#]]) : !s32i // CHECK: %[[#LOADED_A:]] = cir.load %[[#A]] : cir.ptr , !s32i // CHECK: cir.store %[[#LOADED_A]], %[[#RET]] : !s32i, cir.ptr + +int &foo1(); +int &foo2(); + +void c1() { + int &x = (foo1(), foo2()); +} + +// CHECK: cir.func @_Z2c1v() +// CHECK: %0 = cir.alloca !cir.ptr, cir.ptr > +// CHECK: %1 = cir.call @_Z4foo1v() : () -> !cir.ptr +// CHECK: %2 = cir.call @_Z4foo2v() : () -> !cir.ptr +// CHECK: cir.store %2, %0 : !cir.ptr, cir.ptr >