diff --git a/clang/lib/CIR/CodeGen/CIRGenExprConstant.cpp b/clang/lib/CIR/CodeGen/CIRGenExprConstant.cpp index f660544d13cfa..178b276f19d41 100644 --- a/clang/lib/CIR/CodeGen/CIRGenExprConstant.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenExprConstant.cpp @@ -1464,25 +1464,24 @@ mlir::Attribute ConstantEmitter::tryEmitPrivate(const APValue &value, case APValue::ComplexInt: case APValue::ComplexFloat: { mlir::Type desiredType = cgm.convertType(destType); - cir::ComplexType complexType = - mlir::dyn_cast(desiredType); + auto complexType = mlir::dyn_cast(desiredType); mlir::Type complexElemTy = complexType.getElementType(); if (isa(complexElemTy)) { - llvm::APSInt real = value.getComplexIntReal(); - llvm::APSInt imag = value.getComplexIntImag(); - return builder.getAttr( - complexType, cir::IntAttr::get(complexElemTy, real), - cir::IntAttr::get(complexElemTy, imag)); + const llvm::APSInt &real = value.getComplexIntReal(); + const llvm::APSInt &imag = value.getComplexIntImag(); + return cir::ConstComplexAttr::get(builder.getContext(), complexType, + cir::IntAttr::get(complexElemTy, real), + cir::IntAttr::get(complexElemTy, imag)); } assert(isa(complexElemTy) && "expected floating-point type"); - llvm::APFloat real = value.getComplexFloatReal(); - llvm::APFloat imag = value.getComplexFloatImag(); - return builder.getAttr( - complexType, cir::FPAttr::get(complexElemTy, real), - cir::FPAttr::get(complexElemTy, imag)); + const llvm::APFloat &real = value.getComplexFloatReal(); + const llvm::APFloat &imag = value.getComplexFloatImag(); + return cir::ConstComplexAttr::get(builder.getContext(), complexType, + cir::FPAttr::get(complexElemTy, real), + cir::FPAttr::get(complexElemTy, imag)); } case APValue::FixedPoint: case APValue::AddrLabelDiff: