https://github.com/AmrDeveloper updated https://github.com/llvm/llvm-project/pull/204670
>From 15391b3d7cb4c3ba81010a3a629a30ccf6c03f88 Mon Sep 17 00:00:00 2001 From: Amr Hesham <[email protected]> Date: Thu, 18 Jun 2026 21:39:25 +0200 Subject: [PATCH 1/2] [CIR] Implement CXXRewrittenBinaryOperator for ComplexExpr --- clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp | 4 +- .../CodeGen/cxx-rewritten-binary-operator.cpp | 50 +++++++++++++++++++ 2 files changed, 51 insertions(+), 3 deletions(-) diff --git a/clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp b/clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp index c873124521f28..2d99d3111e903 100644 --- a/clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp @@ -273,9 +273,7 @@ class ComplexExprEmitter : public StmtVisitor<ComplexExprEmitter, mlir::Value> { #undef HANDLEBINOP mlir::Value VisitCXXRewrittenBinaryOperator(CXXRewrittenBinaryOperator *e) { - cgf.cgm.errorNYI(e->getExprLoc(), - "ComplexExprEmitter VisitCXXRewrittenBinaryOperator"); - return {}; + return Visit(e->getSemanticForm()); } // Compound assignments. diff --git a/clang/test/CIR/CodeGen/cxx-rewritten-binary-operator.cpp b/clang/test/CIR/CodeGen/cxx-rewritten-binary-operator.cpp index 3f386f6133560..e4ef439eb0b72 100644 --- a/clang/test/CIR/CodeGen/cxx-rewritten-binary-operator.cpp +++ b/clang/test/CIR/CodeGen/cxx-rewritten-binary-operator.cpp @@ -37,3 +37,53 @@ void cxx_rewritten_binary_operator_scalar_expr() { // OGCG: %[[NEQ_I1:.*]] = xor i1 %[[EQ]], true // OGCG: %[[NEQ:.*]] = zext i1 %[[NEQ_I1]] to i8 // OGCG: store i8 %[[NEQ]], ptr %[[NEQ_ADDR]], align 1 + +struct SpaceshipComplexResult { + int _Complex operator<(int) const { return {}; } +}; + +struct ComplexItem { + SpaceshipComplexResult operator<=>(const ComplexItem &) const { return {}; } +}; + +void cxx_rewritten_binary_operator_complex_expr() { + ComplexItem a; + ComplexItem b; + int _Complex r = a < b; +} + +// CIR: %[[A_ADDR:.*]] = cir.alloca "a" {{.*}} : !cir.ptr<!rec_ComplexItem> +// CIR: %[[B_ADDR:.*]] = cir.alloca "b" {{.*}} : !cir.ptr<!rec_ComplexItem> +// CIR: %[[R_ADDR:.*]] = cir.alloca "r" {{.*}} init : !cir.ptr<!cir.complex<!s32i>> +// CIR: %[[TMP_ADDR:.*]] = cir.alloca "ref.tmp0" {{.*}} : !cir.ptr<!rec_SpaceshipComplexResult> +// CIR: %[[OP_RESULT:.*]] = cir.call @_ZNK11ComplexItemssERKS_(%[[A_ADDR]], %[[B_ADDR]]) : (!cir.ptr<!rec_ComplexItem> {llvm.align = 1 : i64, llvm.dereferenceable = 1 : i64, llvm.nonnull, llvm.noundef}, !cir.ptr<!rec_ComplexItem> {llvm.align = 1 : i64, llvm.dereferenceable = 1 : i64, llvm.nonnull, llvm.noundef}) -> !rec_SpaceshipComplexResult +// CIR: cir.store {{.*}} %[[OP_RESULT]], %[[TMP_ADDR]] : !rec_SpaceshipComplexResult, !cir.ptr<!rec_SpaceshipComplexResult> +// CIR: %[[CONST_0:.*]] = cir.const #cir.int<0> : !s32i +// CIR: %[[RESULT:.*]] = cir.call @_ZNK22SpaceshipComplexResultltEi(%[[TMP_ADDR]], %[[CONST_0]]) : (!cir.ptr<!rec_SpaceshipComplexResult> {llvm.align = 1 : i64, llvm.dereferenceable = 1 : i64, llvm.nonnull, llvm.noundef}, !s32i {llvm.noundef}) -> (!cir.complex<!s32i> {llvm.noundef}) +// CIR: cir.store {{.*}} %[[RESULT]], %[[R_ADDR]] : !cir.complex<!s32i>, !cir.ptr<!cir.complex<!s32i>> + +// LLVM: %[[A_ADDR:.*]] = alloca %struct.ComplexItem, i64 1, align 1 +// LLVM: %[[B_ADDR:.*]] = alloca %struct.ComplexItem, i64 1, align 1 +// LLVM: %[[R_ADDR:.*]] = alloca { i32, i32 }, i64 1, align 4 +// LLVM: %[[TMP_ADDR:.*]] = alloca %struct.SpaceshipComplexResult, i64 1, align 1 +// LLVM: %[[OP_RESULT:.*]] = call %struct.SpaceshipComplexResult @_ZNK11ComplexItemssERKS_(ptr noundef nonnull align 1 dereferenceable(1) %[[A_ADDR]], ptr noundef nonnull align 1 dereferenceable(1) %[[B_ADDR]]) +// LLVM: store %struct.SpaceshipComplexResult %[[OP_RESULT]], ptr %[[TMP_ADDR]], align 1 +// LLVM: %[[RESULT:.*]] = call noundef { i32, i32 } @_ZNK22SpaceshipComplexResultltEi(ptr noundef nonnull align 1 dereferenceable(1) %[[TMP_ADDR]], i32 noundef 0) +// LLVM: store { i32, i32 } %[[RESULT]], ptr %[[R_ADDR]], align 4 + +// OGCG: %[[A_ADDR:.*]] = alloca %struct.ComplexItem, align 1 +// OGCG: %[[B_ADDR:.*]] = alloca %struct.ComplexItem, align 1 +// OGCG: %[[R_ADDR:.*]] = alloca { i32, i32 }, align 4 +// OGCG: %[[TMP_ADDR:.*]] = alloca %struct.SpaceshipComplexResult, align 1 +// OGCG: %[[TMP_RESULT_ADDR:.*]] = alloca { i32, i32 }, align 4 +// OGCG: call void @_ZNK11ComplexItemssERKS_(ptr noundef nonnull align 1 dereferenceable(1) %[[A_ADDR]], ptr noundef nonnull align 1 dereferenceable(1) %[[B_ADDR]]) +// OGCG: %[[RESULT:.*]] = call noundef i64 @_ZNK22SpaceshipComplexResultltEi(ptr noundef nonnull align 1 dereferenceable(1) %[[TMP_ADDR]], i32 noundef 0) +// OGCG: store i64 %[[RESULT]], ptr %[[TMP_RESULT_ADDR]], align 4 +// OGCG: %[[RESULT_REAL_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr %[[TMP_RESULT_ADDR]], i32 0, i32 0 +// OGCG: %[[RESULT_REAL:.*]] = load i32, ptr %[[RESULT_REAL_PTR]], align 4 +// OGCG: %[[RESULT_IMAG_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr %[[TMP_RESULT_ADDR]], i32 0, i32 1 +// OGCG: %[[RESULT_IMAG:.*]] = load i32, ptr %[[RESULT_IMAG_PTR]], align 4 +// OGCG: %[[R_REAL_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr %[[R_ADDR]], i32 0, i32 0 +// OGCG: %[[R_IMAG_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr %[[R_ADDR]], i32 0, i32 1 +// OGCG: store i32 %[[RESULT_REAL]], ptr %[[R_REAL_PTR]], align 4 +// OGCG: store i32 %[[RESULT_IMAG]], ptr %[[R_IMAG_PTR]], align 4 >From 9415abe36dc586a422bd6af4b88793fbb0bb99dc Mon Sep 17 00:00:00 2001 From: Amr Hesham <[email protected]> Date: Wed, 24 Jun 2026 19:38:29 +0200 Subject: [PATCH 2/2] Add note about ABI lowering --- clang/test/CIR/CodeGen/cxx-rewritten-binary-operator.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/clang/test/CIR/CodeGen/cxx-rewritten-binary-operator.cpp b/clang/test/CIR/CodeGen/cxx-rewritten-binary-operator.cpp index e4ef439eb0b72..b841eba7ba4eb 100644 --- a/clang/test/CIR/CodeGen/cxx-rewritten-binary-operator.cpp +++ b/clang/test/CIR/CodeGen/cxx-rewritten-binary-operator.cpp @@ -62,6 +62,8 @@ void cxx_rewritten_binary_operator_complex_expr() { // CIR: %[[RESULT:.*]] = cir.call @_ZNK22SpaceshipComplexResultltEi(%[[TMP_ADDR]], %[[CONST_0]]) : (!cir.ptr<!rec_SpaceshipComplexResult> {llvm.align = 1 : i64, llvm.dereferenceable = 1 : i64, llvm.nonnull, llvm.noundef}, !s32i {llvm.noundef}) -> (!cir.complex<!s32i> {llvm.noundef}) // CIR: cir.store {{.*}} %[[RESULT]], %[[R_ADDR]] : !cir.complex<!s32i>, !cir.ptr<!cir.complex<!s32i>> +// The difference between LLVM and OGCG is due to missing ABI lowering. + // LLVM: %[[A_ADDR:.*]] = alloca %struct.ComplexItem, i64 1, align 1 // LLVM: %[[B_ADDR:.*]] = alloca %struct.ComplexItem, i64 1, align 1 // LLVM: %[[R_ADDR:.*]] = alloca { i32, i32 }, i64 1, align 4 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
