summaryrefslogtreecommitdiff
path: root/clang/lib/CIR/CodeGen/CIRGenExprConstant.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'clang/lib/CIR/CodeGen/CIRGenExprConstant.cpp')
-rw-r--r--clang/lib/CIR/CodeGen/CIRGenExprConstant.cpp29
1 files changed, 25 insertions, 4 deletions
diff --git a/clang/lib/CIR/CodeGen/CIRGenExprConstant.cpp b/clang/lib/CIR/CodeGen/CIRGenExprConstant.cpp
index 9085ee2dfe50..c41ab54be09c 100644
--- a/clang/lib/CIR/CodeGen/CIRGenExprConstant.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenExprConstant.cpp
@@ -577,12 +577,33 @@ mlir::Attribute ConstantEmitter::tryEmitPrivate(const APValue &value,
case APValue::Union:
cgm.errorNYI("ConstExprEmitter::tryEmitPrivate struct or union");
return {};
- case APValue::FixedPoint:
case APValue::ComplexInt:
- case APValue::ComplexFloat:
+ case APValue::ComplexFloat: {
+ mlir::Type desiredType = cgm.convertType(destType);
+ cir::ComplexType complexType =
+ mlir::dyn_cast<cir::ComplexType>(desiredType);
+
+ mlir::Type complexElemTy = complexType.getElementType();
+ if (isa<cir::IntType>(complexElemTy)) {
+ llvm::APSInt real = value.getComplexIntReal();
+ llvm::APSInt imag = value.getComplexIntImag();
+ return builder.getAttr<cir::ConstComplexAttr>(
+ complexType, builder.getAttr<cir::IntAttr>(complexElemTy, real),
+ builder.getAttr<cir::IntAttr>(complexElemTy, imag));
+ }
+
+ assert(isa<cir::CIRFPTypeInterface>(complexElemTy) &&
+ "expected floating-point type");
+ llvm::APFloat real = value.getComplexFloatReal();
+ llvm::APFloat imag = value.getComplexFloatImag();
+ return builder.getAttr<cir::ConstComplexAttr>(
+ complexType, builder.getAttr<cir::FPAttr>(complexElemTy, real),
+ builder.getAttr<cir::FPAttr>(complexElemTy, imag));
+ }
+ case APValue::FixedPoint:
case APValue::AddrLabelDiff:
- cgm.errorNYI("ConstExprEmitter::tryEmitPrivate fixed point, complex int, "
- "complex float, addr label diff");
+ cgm.errorNYI(
+ "ConstExprEmitter::tryEmitPrivate fixed point, addr label diff");
return {};
}
llvm_unreachable("Unknown APValue kind");