Skip to content

Commit cc9ff3a

Browse files
authored
[CIR][NFC] Fix copy constructed AP real and imag values (#2043)
Fix copy-constructed AP real and imaginary values from the upstream
1 parent 31a82d4 commit cc9ff3a

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

clang/lib/CIR/CodeGen/CIRGenExprConst.cpp

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2052,25 +2052,24 @@ mlir::Attribute ConstantEmitter::tryEmitPrivate(const APValue &Value,
20522052
case APValue::ComplexFloat:
20532053
case APValue::ComplexInt: {
20542054
mlir::Type desiredType = CGM.convertType(DestType);
2055-
cir::ComplexType complexType =
2056-
mlir::dyn_cast<cir::ComplexType>(desiredType);
2055+
auto complexType = mlir::dyn_cast<cir::ComplexType>(desiredType);
20572056

20582057
mlir::Type complexElemTy = complexType.getElementType();
20592058
if (isa<cir::IntType>(complexElemTy)) {
2060-
llvm::APSInt real = Value.getComplexIntReal();
2061-
llvm::APSInt imag = Value.getComplexIntImag();
2062-
return builder.getAttr<cir::ComplexAttr>(
2063-
complexType, cir::IntAttr::get(complexElemTy, real),
2064-
cir::IntAttr::get(complexElemTy, imag));
2059+
const llvm::APSInt &real = Value.getComplexIntReal();
2060+
const llvm::APSInt &imag = Value.getComplexIntImag();
2061+
return cir::ComplexAttr::get(complexType,
2062+
cir::IntAttr::get(complexElemTy, real),
2063+
cir::IntAttr::get(complexElemTy, imag));
20652064
}
20662065

20672066
assert(isa<cir::FPTypeInterface>(complexElemTy) &&
20682067
"expected floating-point type");
2069-
llvm::APFloat real = Value.getComplexFloatReal();
2070-
llvm::APFloat imag = Value.getComplexFloatImag();
2071-
return builder.getAttr<cir::ComplexAttr>(
2072-
complexType, cir::FPAttr::get(complexElemTy, real),
2073-
cir::FPAttr::get(complexElemTy, imag));
2068+
const llvm::APFloat &real = Value.getComplexFloatReal();
2069+
const llvm::APFloat &imag = Value.getComplexFloatImag();
2070+
return cir::ComplexAttr::get(complexType,
2071+
cir::FPAttr::get(complexElemTy, real),
2072+
cir::FPAttr::get(complexElemTy, imag));
20742073
}
20752074
case APValue::FixedPoint:
20762075
case APValue::AddrLabelDiff:

0 commit comments

Comments
 (0)