[clang] [CIR][NFC] Fix copy constructed AP real and imag values (PR #159935)
via cfe-commits
cfe-commits at lists.llvm.org
Sat Sep 20 09:42:06 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Amr Hesham (AmrDeveloper)
<details>
<summary>Changes</summary>
Fix warning about copy-constructed APInt & APFloat values
---
Full diff: https://github.com/llvm/llvm-project/pull/159935.diff
1 Files Affected:
- (modified) clang/lib/CIR/CodeGen/CIRGenExprConstant.cpp (+11-12)
``````````diff
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:
``````````
</details>
https://github.com/llvm/llvm-project/pull/159935
More information about the cfe-commits
mailing list