Skip to content

Commit ac62c4a

Browse files
authored
[CIR] Implement UnaryExtension support for ComplexType (#159913)
This change implements UnaryExtension for ComplexType Issue: #141365
1 parent 6007a4d commit ac62c4a

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,7 @@ class ComplexExprEmitter : public StmtVisitor<ComplexExprEmitter, mlir::Value> {
193193
mlir::Value VisitUnaryNot(const UnaryOperator *e);
194194
// LNot,Real,Imag never return complex.
195195
mlir::Value VisitUnaryExtension(const UnaryOperator *e) {
196-
cgf.cgm.errorNYI(e->getExprLoc(), "ComplexExprEmitter VisitUnaryExtension");
197-
return {};
196+
return Visit(e->getSubExpr());
198197
}
199198
mlir::Value VisitCXXDefaultArgExpr(CXXDefaultArgExpr *dae) {
200199
cgf.cgm.errorNYI(dae->getExprLoc(),

clang/test/CIR/CodeGen/complex.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,3 +1001,29 @@ void foo36() {
10011001
// OGCG: %[[A_IMAG_F32:.*]] = fpext half %[[A_IMAG]] to float
10021002
// OGCG: %[[A_IMAG_F16:.*]] = fptrunc float %[[A_IMAG_F32]] to half
10031003
// OGCG: store half %[[A_IMAG_F16]], ptr %[[IMAG_ADDR]], align 2
1004+
1005+
void foo37() {
1006+
_Complex float a;
1007+
_Complex float b = __extension__ a;
1008+
}
1009+
1010+
// CIR: %[[A_ADDR:.*]] = cir.alloca !cir.complex<!cir.float>, !cir.ptr<!cir.complex<!cir.float>>, ["a"]
1011+
// CIR: %[[B_ADDR:.*]] = cir.alloca !cir.complex<!cir.float>, !cir.ptr<!cir.complex<!cir.float>>, ["b", init]
1012+
// CIR: %[[TMP_A:.*]] = cir.load{{.*}} %[[A_ADDR]] : !cir.ptr<!cir.complex<!cir.float>>, !cir.complex<!cir.float>
1013+
// CIR: cir.store{{.*}} %[[TMP_A]], %[[B_ADDR]] : !cir.complex<!cir.float>, !cir.ptr<!cir.complex<!cir.float>>
1014+
1015+
// LLVM: %[[A_ADDR:.*]] = alloca { float, float }, i64 1, align 4
1016+
// LLVM: %[[B_ADDR:.*]] = alloca { float, float }, i64 1, align 4
1017+
// LLVM: %[[TMP_A:.*]] = load { float, float }, ptr %[[A_ADDR]], align 4
1018+
// LLVM: store { float, float } %[[TMP_A]], ptr %[[B_ADDR]], align 4
1019+
1020+
// OGCG: %[[A_ADDR:.*]] = alloca { float, float }, align 4
1021+
// OGCG: %[[B_ADDR:.*]] = alloca { float, float }, align 4
1022+
// OGCG: %[[A_REAL_PTR:.*]] = getelementptr inbounds nuw { float, float }, ptr %[[A_ADDR]], i32 0, i32 0
1023+
// OGCG: %[[A_REAL:.*]] = load float, ptr %[[A_REAL_PTR]], align 4
1024+
// OGCG: %[[A_IMAG_PTR:.*]] = getelementptr inbounds nuw { float, float }, ptr %[[A_ADDR]], i32 0, i32 1
1025+
// OGCG: %[[A_IMAG:.*]] = load float, ptr %[[A_IMAG_PTR]], align 4
1026+
// OGCG: %[[B_REAL_PTR:.*]] = getelementptr inbounds nuw { float, float }, ptr %[[B_ADDR]], i32 0, i32 0
1027+
// OGCG: %[[B_IMAG_PTR:.*]] = getelementptr inbounds nuw { float, float }, ptr %[[B_ADDR]], i32 0, i32 1
1028+
// OGCG: store float %[[A_REAL]], ptr %[[B_REAL_PTR]], align 4
1029+
// OGCG: store float %[[A_IMAG]], ptr %[[B_IMAG_PTR]], align 4

0 commit comments

Comments
 (0)