https://github.com/AmrDeveloper created https://github.com/llvm/llvm-project/pull/159935
Fix warning about copy-constructed APInt & APFloat values >From 3eae0e13b1d32fe96cee93fe80d0d023c2942f25 Mon Sep 17 00:00:00 2001 From: AmrDeveloper <[email protected]> Date: Sat, 20 Sep 2025 18:24:16 +0200 Subject: [PATCH] [CIR][NFC] Fix copy AP real and imag values --- clang/lib/CIR/CodeGen/CIRGenExprConstant.cpp | 23 ++++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) 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<cir::ComplexType>(desiredType); + auto 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, 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<cir::FPTypeInterface>(complexElemTy) && "expected floating-point type"); - llvm::APFloat real = value.getComplexFloatReal(); - llvm::APFloat imag = value.getComplexFloatImag(); - return builder.getAttr<cir::ConstComplexAttr>( - 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: _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
