Skip to content

Commit 3b0f00d

Browse files
committed
[CIR] Implement StmtExpr for ComplexType
1 parent c6e23ab commit 3b0f00d

File tree

2 files changed

+50
-2
lines changed

2 files changed

+50
-2
lines changed

clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -400,8 +400,13 @@ mlir::Value ComplexExprEmitter::VisitCallExpr(const CallExpr *e) {
400400
}
401401

402402
mlir::Value ComplexExprEmitter::VisitStmtExpr(const StmtExpr *e) {
403-
cgf.cgm.errorNYI(e->getExprLoc(), "ComplexExprEmitter VisitExpr");
404-
return {};
403+
CIRGenFunction::StmtExprEvaluation eval(cgf);
404+
Address retAlloca =
405+
cgf.createMemTemp(e->getType(), cgf.getLoc(e->getSourceRange()));
406+
(void)cgf.emitCompoundStmt(*e->getSubStmt(), &retAlloca);
407+
assert(retAlloca.isValid() && "Expected complex return value");
408+
return emitLoadOfLValue(cgf.makeAddrLValue(retAlloca, e->getType()),
409+
e->getExprLoc());
405410
}
406411

407412
mlir::Value ComplexExprEmitter::emitComplexToComplexCast(mlir::Value val,

clang/test/CIR/CodeGen/stmt-expr.cpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,46 @@ void cleanup() {
8888
// OGCG: %[[WD:.+]] = alloca %struct.with_dtor
8989
// OGCG: call void @_ZN9with_dtorD1Ev(ptr {{.*}} %[[WD]])
9090
// OGCG: ret void
91+
92+
void gnu_statement_extension() {
93+
float b = __real__ ({float _Complex a; a;});
94+
}
95+
96+
// CIR: %[[B_ADDR:.*]] = cir.alloca !cir.float, !cir.ptr<!cir.float>, ["b", init]
97+
// CIR: %[[TMP_ADDR:.*]] = cir.alloca !cir.complex<!cir.float>, !cir.ptr<!cir.complex<!cir.float>>, ["tmp"]
98+
// CIR: cir.scope {
99+
// CIR: %[[A_ADDR:.*]] = cir.alloca !cir.complex<!cir.float>, !cir.ptr<!cir.complex<!cir.float>>, ["a"]
100+
// CIR: %[[TMP_A:.*]] = cir.load {{.*}} %[[A_ADDR]] : !cir.ptr<!cir.complex<!cir.float>>, !cir.complex<!cir.float>
101+
// CIR: cir.store {{.*}} %[[TMP_A]], %[[TMP_ADDR]] : !cir.complex<!cir.float>, !cir.ptr<!cir.complex<!cir.float>>
102+
// CIR: }
103+
// CIR: %[[TMP:.*]] = cir.load {{.*}} %[[TMP_ADDR]] : !cir.ptr<!cir.complex<!cir.float>>, !cir.complex<!cir.float>
104+
// CIR: %[[REAL:.*]] = cir.complex.real %[[TMP]] : !cir.complex<!cir.float> -> !cir.float
105+
// CIR: cir.store {{.*}} %[[REAL]], %[[B_ADDR]] : !cir.float, !cir.ptr<!cir.float>
106+
107+
// LLVM: %[[A_ADDR:.*]] = alloca { float, float }, i64 1, align 4
108+
// LLVM: %[[B_ADDR:.*]] = alloca float, i64 1, align 4
109+
// LLVM: %[[TMP_ADDR:.*]] = alloca { float, float }, i64 1, align 4
110+
// LLVM: br label %[[LABEL_1:.*]]
111+
// LLVM: [[LABEL_1]]:
112+
// LLVM: %[[TMP_A:.*]] = load { float, float }, ptr %[[A_ADDR]], align 4
113+
// LLVM: store { float, float } %[[TMP_A]], ptr %[[TMP_ADDR]], align 4
114+
// LLVM: br label %[[LABEL_2:.*]]
115+
// LLVM: [[LABEL_2]]:
116+
// LLVM: %[[TMP:.*]] = load { float, float }, ptr %[[TMP_ADDR]], align 4
117+
// LLVM: %[[REAL:.*]] = extractvalue { float, float } %[[TMP]], 0
118+
// LLVM: store float %[[REAL]], ptr %[[B_ADDR]], align 4
119+
120+
// OGCG: %[[B_ADDR:.*]] = alloca float, align 4
121+
// OGCG: %[[A_ADDR:.*]] = alloca { float, float }, align 4
122+
// OGCG: %[[TMP_ADDR:.*]] = alloca { float, float }, align 4
123+
// OGCG: %[[A_REAL_PTR:.*]] = getelementptr inbounds nuw { float, float }, ptr %[[A_ADDR]], i32 0, i32 0
124+
// OGCG: %[[A_REAL:.*]] = load float, ptr %[[A_REAL_PTR]], align 4
125+
// OGCG: %[[A_IMAG_PTR:.*]] = getelementptr inbounds nuw { float, float }, ptr %[[A_ADDR]], i32 0, i32 1
126+
// OGCG: %[[A_IMAG:.*]] = load float, ptr %[[A_IMAG_PTR]], align 4
127+
// OGCG: %[[TMP_REAL_PTR:.*]] = getelementptr inbounds nuw { float, float }, ptr %[[TMP_ADDR]], i32 0, i32 0
128+
// OGCG: %[[TMP_IMAG_PTR:.*]] = getelementptr inbounds nuw { float, float }, ptr %[[TMP_ADDR]], i32 0, i32 1
129+
// OGCG: store float %[[A_REAL]], ptr %[[TMP_REAL_PTR]], align 4
130+
// OGCG: store float %[[A_IMAG]], ptr %[[TMP_IMAG_PTR]], align 4
131+
// OGCG: %[[TMP_REAL_PTR:.*]] = getelementptr inbounds nuw { float, float }, ptr %[[TMP_ADDR]], i32 0, i32 0
132+
// OGCG: %[[TMP_REAL:.*]] = load float, ptr %[[TMP_REAL_PTR]], align 4
133+
// OGCG: store float %[[TMP_REAL]], ptr %[[B_ADDR]], align 4

0 commit comments

Comments
 (0)