diff --git a/clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp b/clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp index c9b4ac21be2d..1dbfc1866609 100644 --- a/clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp @@ -147,7 +147,7 @@ class ComplexExprEmitter : public StmtVisitor { mlir::Value VisitUnaryPreInc(const UnaryOperator *E) { return VisitPrePostIncDec(E, true, true); } - mlir::Value VisitUnaryDeref(const Expr *E) { llvm_unreachable("NYI"); } + mlir::Value VisitUnaryDeref(const Expr *E) { return emitLoadOfLValue(E); } mlir::Value VisitUnaryPlus(const UnaryOperator *E, QualType PromotionType = QualType()); diff --git a/clang/test/CIR/CodeGen/complex.cpp b/clang/test/CIR/CodeGen/complex.cpp index 8f639b8248ad..dbc3f04b8808 100644 --- a/clang/test/CIR/CodeGen/complex.cpp +++ b/clang/test/CIR/CodeGen/complex.cpp @@ -15,6 +15,22 @@ void complex_functional_cast() { // LLVM: %[[INIT:.*]] = alloca { i32, i32 }, i64 1, align 4 // LLVM: store { i32, i32 } zeroinitializer, ptr %[[INIT]], align 4 +void complex_deref_expr(int _Complex* a) { + int _Complex b = *a; +} + +// CIR: %[[COMPLEX_A_PTR:.*]] = cir.alloca !cir.ptr>, !cir.ptr>>, ["a", init] +// CIR: %[[COMPLEX_B:.*]] = cir.alloca !cir.complex, !cir.ptr>, ["b", init] +// CIR: %[[COMPLEX_A:.*]] = cir.load deref {{.*}} %[[COMPLEX_A_PTR]] : !cir.ptr>>, !cir.ptr> +// CIR: %[[TMP:.*]] = cir.load{{.*}} %[[COMPLEX_A]] : !cir.ptr>, !cir.complex +// CIR: cir.store{{.*}} %[[TMP]], %[[COMPLEX_B]] : !cir.complex, !cir.ptr> + +// LLVM: %[[COMPLEX_A_PTR:.*]] = alloca ptr, i64 1, align 8 +// LLVM: %[[COMPLEX_B:.*]] = alloca { i32, i32 }, i64 1, align 4 +// LLVM: %[[COMPLEX_A:.*]] = load ptr, ptr %[[COMPLEX_A_PTR]], align 8 +// LLVM: %[[TMP:.*]] = load { i32, i32 }, ptr %[[COMPLEX_A]], align 4 +// LLVM: store { i32, i32 } %[[TMP]], ptr %[[COMPLEX_B]], align 4 + void complex_cxx_scalar_value_init_expr() { using IntComplex = int _Complex; int _Complex a = IntComplex();