From 0b438cf669dd4c9adbe873554dc3ccd44ec1aae3 Mon Sep 17 00:00:00 2001 From: AmrDeveloper Date: Mon, 1 Dec 2025 20:55:53 +0100 Subject: [PATCH] [CIR][NFC] Fix copy constructed AP real and imag values --- clang/lib/CIR/CodeGen/CIRGenExprConst.cpp | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/clang/lib/CIR/CodeGen/CIRGenExprConst.cpp b/clang/lib/CIR/CodeGen/CIRGenExprConst.cpp index d59b3cae94c2..e2994fb9df0c 100644 --- a/clang/lib/CIR/CodeGen/CIRGenExprConst.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenExprConst.cpp @@ -2052,25 +2052,24 @@ mlir::Attribute ConstantEmitter::tryEmitPrivate(const APValue &Value, case APValue::ComplexFloat: case APValue::ComplexInt: { 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::ComplexAttr::get(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::ComplexAttr::get(complexType, + cir::FPAttr::get(complexElemTy, real), + cir::FPAttr::get(complexElemTy, imag)); } case APValue::FixedPoint: case APValue::AddrLabelDiff: