Skip to content

Commit 0a3d11c

Browse files
authored
[CIR] Backport MemberExpr with VarDecl for ComplexType (#1845)
Backporting support MemberExpr with VarDecl for ComplexType from the upstream
1 parent 7ad17f2 commit 0a3d11c

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@ class ComplexExprEmitter : public StmtVisitor<ComplexExprEmitter, mlir::Value> {
112112

113113
mlir::Value VisitMemberExpr(MemberExpr *ME) {
114114
if (CIRGenFunction::ConstantEmission constant = CGF.tryEmitAsConstant(ME)) {
115-
llvm_unreachable("VisitMemberExpr tryEmitAsConstant");
115+
CGF.emitIgnoredExpr(ME->getBase());
116+
return emitConstant(constant, ME);
116117
}
117118
return emitLoadOfLValue(ME);
118119
}

clang/test/CIR/CodeGen/complex.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,26 @@ int _Complex complex_imag_operator_on_rvalue() {
149149
// LLVM: %[[TMP_RET:.*]] = load { i32, i32 }, ptr %[[RET_ADDR]], align 4
150150
// LLVM: ret { i32, i32 } %[[TMP_RET]]
151151

152+
struct Container {
153+
static int _Complex c;
154+
};
155+
156+
void complex_member_expr_with_var_deal() {
157+
Container con;
158+
int r = __real__ con.c;
159+
}
160+
161+
// CIR: %[[REAL_ADDR:.*]] = cir.alloca !s32i, !cir.ptr<!s32i>, ["r", init]
162+
// CIR: %[[ELEM_PTR:.*]] = cir.get_global @_ZN9Container1cE : !cir.ptr<!cir.complex<!s32i>>
163+
// CIR: %[[ELEM:.*]] = cir.load{{.*}} %[[ELEM_PTR]] : !cir.ptr<!cir.complex<!s32i>>, !cir.complex<!s32i>
164+
// CIR: %[[REAL:.*]] = cir.complex.real %[[ELEM]] : !cir.complex<!s32i> -> !s32i
165+
// CIR: cir.store{{.*}} %[[REAL]], %[[REAL_ADDR]] : !s32i, !cir.ptr<!s32i>
166+
167+
// LLVM: %[[REAL_ADDR:.*]] = alloca i32, i64 1, align 4
168+
// LLVM: %[[ELEM:.*]] = load { i32, i32 }, ptr @_ZN9Container1cE, align 4
169+
// LLVM: %[[REAL:.*]] = extractvalue { i32, i32 } %[[ELEM]], 0
170+
// LLVM: store i32 %[[REAL]], ptr %[[REAL_ADDR]], align 4
171+
152172
void complex_comma_operator(int _Complex a, int _Complex b) {
153173
int _Complex c = (a, b);
154174
}

0 commit comments

Comments
 (0)