Skip to content

Commit e93a346

Browse files
authored
[CIR] Upstream SubstNonTypeTemplateParmExpr support for ComplexType (llvm#146755)
Upstream SubstNonTypeTemplateParmExpr support for ComplexType llvm#141365
1 parent 59d641a commit e93a346

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ class ComplexExprEmitter : public StmtVisitor<ComplexExprEmitter, mlir::Value> {
5050
mlir::Value VisitInitListExpr(const InitListExpr *e);
5151
mlir::Value VisitImaginaryLiteral(const ImaginaryLiteral *il);
5252
mlir::Value VisitParenExpr(ParenExpr *e);
53+
mlir::Value
54+
VisitSubstNonTypeTemplateParmExpr(SubstNonTypeTemplateParmExpr *e);
5355
};
5456
} // namespace
5557

@@ -231,6 +233,11 @@ mlir::Value ComplexExprEmitter::VisitParenExpr(ParenExpr *e) {
231233
return Visit(e->getSubExpr());
232234
}
233235

236+
mlir::Value ComplexExprEmitter::VisitSubstNonTypeTemplateParmExpr(
237+
SubstNonTypeTemplateParmExpr *e) {
238+
return Visit(e->getReplacement());
239+
}
240+
234241
LValue CIRGenFunction::emitComplexAssignmentLValue(const BinaryOperator *e) {
235242
assert(e->getOpcode() == BO_Assign && "Expected assign op");
236243

clang/test/CIR/CodeGen/complex.cpp

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -Wno-unused-value -fclangir -emit-cir %s -o %t.cir
1+
// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-linux-gnu -Wno-unused-value -fclangir -emit-cir %s -o %t.cir
22
// RUN: FileCheck --input-file=%t.cir %s -check-prefix=CIR
3-
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -Wno-unused-value -fclangir -emit-llvm %s -o %t-cir.ll
3+
// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-linux-gnu -Wno-unused-value -fclangir -emit-llvm %s -o %t-cir.ll
44
// RUN: FileCheck --input-file=%t-cir.ll %s -check-prefix=LLVM
5-
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -Wno-unused-value -emit-llvm %s -o %t.ll
5+
// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-linux-gnu -Wno-unused-value -emit-llvm %s -o %t.ll
66
// RUN: FileCheck --input-file=%t.ll %s -check-prefix=OGCG
77

88
int _Complex ci;
@@ -607,3 +607,22 @@ void foo24() {
607607
// OGCG: %[[RESULT_IMAG_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr %[[RESULT]], i32 0, i32 1
608608
// OGCG: store i32 %[[ELEM_REAL]], ptr %[[RESULT_REAL_PTR]], align 4
609609
// OGCG: store i32 %[[ELEM_IMAG]], ptr %[[RESULT_IMAG_PTR]], align 4
610+
611+
template <double _Complex N> void template_foo() { double _Complex C = N; }
612+
613+
void foo25() {
614+
template_foo<__builtin_complex(1.0, 2.0)>();
615+
}
616+
617+
// CIR: %[[INIT:.*]] = cir.alloca !cir.complex<!cir.double>, !cir.ptr<!cir.complex<!cir.double>>, ["C", init]
618+
// CIR: %[[COMPLEX:.*]] = cir.const #cir.const_complex<#cir.fp<1.000000e+00> : !cir.double, #cir.fp<2.000000e+00> : !cir.double> : !cir.complex<!cir.double>
619+
// CIR: cir.store{{.*}} %[[COMPLEX]], %[[INIT]] : !cir.complex<!cir.double>, !cir.ptr<!cir.complex<!cir.double>>
620+
621+
// LLVM: %[[INIT:.*]] = alloca { double, double }, i64 1, align 8
622+
// LLVM: store { double, double } { double 1.000000e+00, double 2.000000e+00 }, ptr %[[INIT]], align 8
623+
624+
// OGCG: %[[INIT:.*]] = alloca { double, double }, align 8
625+
// OGCG: %[[INIT_REAL_PTR:.*]] = getelementptr inbounds nuw { double, double }, ptr %[[INIT]], i32 0, i32 0
626+
// OGCG: %[[INIT_IMAG_PTR:.*]] = getelementptr inbounds nuw { double, double }, ptr %[[INIT]], i32 0, i32 1
627+
// OGCG: store double 1.000000e+00, ptr %[[INIT_REAL_PTR]], align 8
628+
// OGCG: store double 2.000000e+00, ptr %[[INIT_IMAG_PTR]], align 8

0 commit comments

Comments
 (0)