https://github.com/AmrDeveloper updated https://github.com/llvm/llvm-project/pull/204667
>From cc73945edc20cce456a27ea4bb6d160c54c3c1fa Mon Sep 17 00:00:00 2001 From: Amr Hesham <[email protected]> Date: Thu, 18 Jun 2026 21:17:00 +0200 Subject: [PATCH 1/2] [CIR] Implement CXXRewrittenBinaryOperator for AggregateExpr --- clang/lib/CIR/CodeGen/CIRGenExprAggregate.cpp | 3 +- .../CodeGen/cxx-rewritten-binary-operator.cpp | 46 +++++++++++++++++++ 2 files changed, 47 insertions(+), 2 deletions(-) diff --git a/clang/lib/CIR/CodeGen/CIRGenExprAggregate.cpp b/clang/lib/CIR/CodeGen/CIRGenExprAggregate.cpp index c53453bd3e88b..4d54519e4d25f 100644 --- a/clang/lib/CIR/CodeGen/CIRGenExprAggregate.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenExprAggregate.cpp @@ -443,8 +443,7 @@ class AggExprEmitter : public StmtVisitor<AggExprEmitter> { } void VisitCXXRewrittenBinaryOperator(CXXRewrittenBinaryOperator *e) { - cgf.cgm.errorNYI(e->getSourceRange(), - "AggExprEmitter: VisitCXXRewrittenBinaryOperator"); + Visit(e->getSemanticForm()); } void VisitObjCMessageExpr(ObjCMessageExpr *e) { cgf.cgm.errorNYI(e->getSourceRange(), diff --git a/clang/test/CIR/CodeGen/cxx-rewritten-binary-operator.cpp b/clang/test/CIR/CodeGen/cxx-rewritten-binary-operator.cpp index 3f386f6133560..6a7ea8e487aac 100644 --- a/clang/test/CIR/CodeGen/cxx-rewritten-binary-operator.cpp +++ b/clang/test/CIR/CodeGen/cxx-rewritten-binary-operator.cpp @@ -37,3 +37,49 @@ 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 Result { + int value; +}; + +struct SpaceshipResult { + Result operator<(int) const { return {}; } +}; + +struct Item { + SpaceshipResult operator<=>(const Item &) const { return {}; } +}; + +void cxx_rewritten_binary_operator_aggr_expr() { + Item a; + Item b; + Result r = a < b; +} + +// CIR: %[[A_ADDR:.*]] = cir.alloca "a" {{.*}} : !cir.ptr<!rec_Item> +// CIR: %[[B_ADDR:.*]] = cir.alloca "b" {{.*}} : !cir.ptr<!rec_Item> +// CIR: %[[R_ADDR:.*]] = cir.alloca "r" {{.*}} init : !cir.ptr<!rec_Result> +// CIR: %[[TMP_ADDR:.*]] = cir.alloca "ref.tmp0" {{.*}} : !cir.ptr<!rec_SpaceshipResult> +// CIR: %[[OP_RESULT:.*]] = cir.call @_ZNK4ItemssERKS_(%[[A_ADDR]], %[[B_ADDR]]) : (!cir.ptr<!rec_Item> {llvm.align = 1 : i64, llvm.dereferenceable = 1 : i64, llvm.nonnull, llvm.noundef}, !cir.ptr<!rec_Item> {llvm.align = 1 : i64, llvm.dereferenceable = 1 : i64, llvm.nonnull, llvm.noundef}) -> !rec_SpaceshipResult +// CIR: cir.store {{.*}} %[[OP_RESULT]], %[[TMP_ADDR]] : !rec_SpaceshipResult, !cir.ptr<!rec_SpaceshipResult> +// CIR: %[[CONST_0:.*]] = cir.const #cir.int<0> : !s32i +// CIR: %[[RESULT:.*]] = cir.call @_ZNK15SpaceshipResultltEi(%[[TMP_ADDR]], %[[CONST_0]]) : (!cir.ptr<!rec_SpaceshipResult> {llvm.align = 1 : i64, llvm.dereferenceable = 1 : i64, llvm.nonnull, llvm.noundef}, !s32i {llvm.noundef}) -> !rec_Result +// CIR: cir.store {{.*}} %[[RESULT]], %[[R_ADDR]] : !rec_Result, !cir.ptr<!rec_Result> + +// LLVM: %[[A_ADDR:.*]] = alloca %struct.Item, i64 1, align 1 +// LLVM: %[[B_ADDR:.*]] = alloca %struct.Item, i64 1, align 1 +// LLVM: %[[R_ADDR:.*]] = alloca %struct.Result, i64 1, align 4 +// LLVM: %[[TMP_ADDR:.*]] = alloca %struct.SpaceshipResult, i64 1, align 1 +// LLVM: %[[OP_RESULT:.*]] = call %struct.SpaceshipResult @_ZNK4ItemssERKS_(ptr noundef nonnull align 1 dereferenceable(1) %[[A_ADDR]], ptr noundef nonnull align 1 dereferenceable(1) %[[B_ADDR]]) +// LLVM: store %struct.SpaceshipResult %[[OP_RESULT]], ptr %[[TMP_ADDR]], align 1 +// LLVM: %[[RESULT:.*]] = call %struct.Result @_ZNK15SpaceshipResultltEi(ptr noundef nonnull align 1 dereferenceable(1) %[[TMP_ADDR]], i32 noundef 0) +// LLVM: store %struct.Result %[[RESULT]], ptr %[[R_ADDR]], align 4 + +// OGCG: %[[A_ADDR:.*]] = alloca %struct.Item, align 1 +// OGCG: %[[B_ADDR:.*]] = alloca %struct.Item, align 1 +// OGCG: %[[R_ADDR:.*]] = alloca %struct.Result, align 4 +// OGCG: %[[TMP_ADDR:.*]] = alloca %struct.SpaceshipResult, align 1 +// OGCG: call void @_ZNK4ItemssERKS_(ptr noundef nonnull align 1 dereferenceable(1) %[[A_ADDR]], ptr noundef nonnull align 1 dereferenceable(1) %[[B_ADDR]]) +// OGCG: %[[RESULT:.*]] = call i32 @_ZNK15SpaceshipResultltEi(ptr noundef nonnull align 1 dereferenceable(1) %[[TMP_ADDR]], i32 noundef 0) +// OGCG: %[[R_ADDR_PTR:.*]] = getelementptr inbounds nuw %struct.Result, ptr %[[R_ADDR:.*]], i32 0, i32 0 +// OGCG: store i32 %[[RESULT:.*]], ptr %[[R_ADDR_PTR]], align 4 >From 8c8c178f878c29a95f8caeced7790bb7fd1751de Mon Sep 17 00:00:00 2001 From: Amr Hesham <[email protected]> Date: Wed, 24 Jun 2026 19:51:58 +0200 Subject: [PATCH 2/2] Add note about ABI --- 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 6a7ea8e487aac..3fd82c5156754 100644 --- a/clang/test/CIR/CodeGen/cxx-rewritten-binary-operator.cpp +++ b/clang/test/CIR/CodeGen/cxx-rewritten-binary-operator.cpp @@ -66,6 +66,8 @@ void cxx_rewritten_binary_operator_aggr_expr() { // CIR: %[[RESULT:.*]] = cir.call @_ZNK15SpaceshipResultltEi(%[[TMP_ADDR]], %[[CONST_0]]) : (!cir.ptr<!rec_SpaceshipResult> {llvm.align = 1 : i64, llvm.dereferenceable = 1 : i64, llvm.nonnull, llvm.noundef}, !s32i {llvm.noundef}) -> !rec_Result // CIR: cir.store {{.*}} %[[RESULT]], %[[R_ADDR]] : !rec_Result, !cir.ptr<!rec_Result> +// The difference between LLVM and OGCG is due to missing ABI lowering. + // LLVM: %[[A_ADDR:.*]] = alloca %struct.Item, i64 1, align 1 // LLVM: %[[B_ADDR:.*]] = alloca %struct.Item, i64 1, align 1 // LLVM: %[[R_ADDR:.*]] = alloca %struct.Result, i64 1, align 4 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
