Author: Amr Hesham Date: 2026-01-27T17:30:46+01:00 New Revision: 023bfa20131f93a35c405117af3f5267921baa0e
URL: https://github.com/llvm/llvm-project/commit/023bfa20131f93a35c405117af3f5267921baa0e DIFF: https://github.com/llvm/llvm-project/commit/023bfa20131f93a35c405117af3f5267921baa0e.diff LOG: [CIR] ExprWithCleanups for Complex expr (#178032) Upstream support ExprWithCleanups for Complex expr Added: Modified: clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp clang/test/CIR/CodeGen/cleanup.cpp Removed: ################################################################################ diff --git a/clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp b/clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp index f85d98f279a1c..e35e630d06c4f 100644 --- a/clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp @@ -210,9 +210,12 @@ class ComplexExprEmitter : public StmtVisitor<ComplexExprEmitter, mlir::Value> { return Visit(die->getExpr()); } mlir::Value VisitExprWithCleanups(ExprWithCleanups *e) { - cgf.cgm.errorNYI(e->getExprLoc(), - "ComplexExprEmitter VisitExprWithCleanups"); - return {}; + CIRGenFunction::RunCleanupsScope scope(cgf); + mlir::Value complexVal = Visit(e->getSubExpr()); + // Defend against dominance problems caused by jumps out of expression + // evaluation through the shared cleanup block. + scope.forceCleanup(); + return complexVal; } mlir::Value VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *e) { mlir::Location loc = cgf.getLoc(e->getExprLoc()); diff --git a/clang/test/CIR/CodeGen/cleanup.cpp b/clang/test/CIR/CodeGen/cleanup.cpp index 0400d4b275fbb..e935bf71a26ab 100644 --- a/clang/test/CIR/CodeGen/cleanup.cpp +++ b/clang/test/CIR/CodeGen/cleanup.cpp @@ -95,3 +95,26 @@ void test_expr_with_cleanup() { // CHECK: cir.call @_ZN5StrukD1Ev(%[[S]]) nothrow : (!cir.ptr<!rec_Struk>) -> () // CHECK: } // CHECK: cir.return + +struct ComplexContainer { + int _Complex value; + ComplexContainer(int _Complex v) : value(v) {} +}; + +void complex_expr_with_cleanup() { + int _Complex result = ComplexContainer(10).value; +} + +// CHECK: cir.func{{.*}} @_Z25complex_expr_with_cleanupv() +// CHECK: %[[RESULT:.*]] = cir.alloca !cir.complex<!s32i>, !cir.ptr<!cir.complex<!s32i>>, ["result", init] +// CHECK: %[[CONTAINER_ADDR:.*]] = cir.alloca !rec_ComplexContainer, !cir.ptr<!rec_ComplexContainer>, ["ref.tmp0"] +// CHECK: %[[ARG_ADDR:.*]] = cir.alloca !cir.complex<!s32i>, !cir.ptr<!cir.complex<!s32i>>, ["coerce"] +// CHECK: %[[CONST_10:.*]] = cir.const #cir.int<10> : !s32i +// CHECK: %[[CONST_0:.*]] = cir.const #cir.int<0> : !s32i +// CHECK: %[[ARG_COMPLEX:.*]] = cir.complex.create %[[CONST_10]], %[[CONST_0]] : !s32i -> !cir.complex<!s32i> +// CHECK: cir.store {{.*}} %[[ARG_COMPLEX]], %[[ARG_ADDR]] : !cir.complex<!s32i>, !cir.ptr<!cir.complex<!s32i>> +// CHECK: %[[TMP_ARG:.*]] = cir.load {{.*}} %[[ARG_ADDR]] : !cir.ptr<!cir.complex<!s32i>>, !cir.complex<!s32i> +// CHECK: cir.call @_ZN16ComplexContainerC1ECi(%[[CONTAINER_ADDR]], %[[TMP_ARG]]) : (!cir.ptr<!rec_ComplexContainer>, !cir.complex<!s32i>) -> () +// CHECK: %[[ELEM_0:.*]] = cir.get_member %[[CONTAINER_ADDR]][0] {name = "value"} : !cir.ptr<!rec_ComplexContainer> -> !cir.ptr<!cir.complex<!s32i>> +// CHECK: %[[TMP_ELEM_0:.*]] = cir.load {{.*}} %[[ELEM_0]] : !cir.ptr<!cir.complex<!s32i>>, !cir.complex<!s32i> +// CHECK: cir.store {{.*}} %[[TMP_ELEM_0]], %[[RESULT]] : !cir.complex<!s32i>, !cir.ptr<!cir.complex<!s32i>> _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
