[clang] [CIR] Upstream global initialization for ComplexType (PR #141369)
Amr Hesham via cfe-commits
cfe-commits at lists.llvm.org
Wed May 28 11:44:17 PDT 2025
================
@@ -577,12 +577,31 @@ mlir::Attribute ConstantEmitter::tryEmitPrivate(const APValue &value,
case APValue::Union:
cgm.errorNYI("ConstExprEmitter::tryEmitPrivate struct or union");
return {};
- case APValue::FixedPoint:
case APValue::ComplexInt:
- case APValue::ComplexFloat:
+ case APValue::ComplexFloat: {
+ mlir::Type desiredType = cgm.convertType(destType);
+ cir::ComplexType 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, builder.getAttr<cir::IntAttr>(complexElemTy, real),
+ builder.getAttr<cir::IntAttr>(complexElemTy, imag));
+ }
+
----------------
AmrDeveloper wrote:
Yes, I think `assert(isa<cir::CIRFPTypeInterface>(complexElemTy) && "...")`
https://github.com/llvm/llvm-project/pull/141369
More information about the cfe-commits
mailing list