Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion clang/lib/CIR/CodeGen/CIRGenExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3272,7 +3272,9 @@ CIRGenFunction::tryEmitAsConstant(DeclRefExpr *refExpr) {

CIRGenFunction::ConstantEmission
CIRGenFunction::tryEmitAsConstant(const MemberExpr *ME) {
llvm_unreachable("NYI");
if (DeclRefExpr *dre = tryToConvertMemberExprToDeclRefExpr(*this, ME))
return tryEmitAsConstant(dre);
return ConstantEmission();
}

mlir::Value CIRGenFunction::emitScalarConstant(
Expand Down
9 changes: 8 additions & 1 deletion clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,14 @@ class ComplexExprEmitter : public StmtVisitor<ComplexExprEmitter, mlir::Value> {
llvm_unreachable("NYI");
}
mlir::Value VisitArraySubscriptExpr(Expr *E) { return emitLoadOfLValue(E); }
mlir::Value VisitMemberExpr(MemberExpr *ME) { llvm_unreachable("NYI"); }

mlir::Value VisitMemberExpr(MemberExpr *ME) {
if (CIRGenFunction::ConstantEmission constant = CGF.tryEmitAsConstant(ME)) {
llvm_unreachable("VisitMemberExpr tryEmitAsConstant");
}
return emitLoadOfLValue(ME);
}

mlir::Value VisitOpaqueValueExpr(OpaqueValueExpr *E) {
llvm_unreachable("NYI");
}
Expand Down
23 changes: 23 additions & 0 deletions clang/test/CIR/CodeGen/complex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,29 @@ int _Complex complex_real_operator_on_rvalue() {
// LLVM: %[[TMP_RET:.*]] = load { i32, i32 }, ptr %[[RET_ADDR]], align 4
// LLVM: ret { i32, i32 } %[[TMP_RET]]

void complex_member_expr() {
struct Wrapper {
int _Complex c;
};

Wrapper w;
int r = __real__ w.c;
}

// CIR: %[[W_ADDR:.*]] = cir.alloca !rec_Wrapper, !cir.ptr<!rec_Wrapper>, ["w"]
// CIR: %[[REAL_ADDR:.*]] = cir.alloca !s32i, !cir.ptr<!s32i>, ["r", init]
// CIR: %[[ELEM_PTR:.*]] = cir.get_member %[[W_ADDR]][0] {name = "c"} : !cir.ptr<!rec_Wrapper> -> !cir.ptr<!cir.complex<!s32i>>
// CIR: %[[TMP_ELEM_PTR:.*]] = cir.load{{.*}} %[[ELEM_PTR]] : !cir.ptr<!cir.complex<!s32i>>, !cir.complex<!s32i>
// CIR: %[[REAL:.*]] = cir.complex.real %[[TMP_ELEM_PTR]] : !cir.complex<!s32i> -> !s32i
// CIR: cir.store{{.*}} %[[REAL]], %[[REAL_ADDR]] : !s32i, !cir.ptr<!s32i>

// LLVM: %[[W_ADDR:.*]] = alloca %struct.Wrapper, i64 1, align 4
// LLVM: %[[REAL_ADDR:.*]] = alloca i32, i64 1, align 4
// LLVM: %[[ELEM_PTR:.*]] = getelementptr %struct.Wrapper, ptr %[[W_ADDR]], i32 0, i32 0
// LLVM: %[[TMP_ELEM_PTR:.*]] = load { i32, i32 }, ptr %[[ELEM_PTR]], align 4
// LLVM: %[[REAL:.*]] = extractvalue { i32, i32 } %[[TMP_ELEM_PTR]], 0
// LLVM: store i32 %[[REAL]], ptr %[[REAL_ADDR]], align 4

int _Complex complex_imag_operator_on_rvalue() {
int imag = __imag__ complex_imag_operator_on_rvalue();
return {};
Expand Down
Loading