if (eltType.isa<FloatType>())
return FloatAttr::get(eltType, 0);
+ // Handle complex elements.
+ if (auto complexTy = eltType.dyn_cast<ComplexType>()) {
+ auto eltType = complexTy.getElementType();
+ Attribute zero;
+ if (eltType.isa<FloatType>())
+ zero = FloatAttr::get(eltType, 0);
+ else // must be integer
+ zero = IntegerAttr::get(eltType, 0);
+ return ArrayAttr::get(complexTy.getContext(),
+ ArrayRef<Attribute>{zero, zero});
+ }
+
// Handle string type.
if (getValues().isa<DenseStringElementsAttr>())
return StringAttr::get("", eltType);
--- /dev/null
+// RUN: mlir-opt %s --convert-memref-to-llvm | \
+// RUN: mlir-cpu-runner -e entry -entry-point-result=void
+
+//
+// Code should not crash on the complex32 sparse constant.
+//
+module attributes {llvm.data_layout = ""} {
+ memref.global "private" constant @"__constant_32xcomplex<f32>_0" : memref<32xcomplex<f32>> =
+ sparse<[[1], [28], [31]],
+ [(1.000000e+00,0.000000e+00), (2.000000e+00,0.000000e+00), (3.000000e+00,0.000000e+00)]
+ > {alignment = 128 : i64}
+ llvm.func @entry() {
+ %0 = memref.get_global @"__constant_32xcomplex<f32>_0" : memref<32xcomplex<f32>>
+ llvm.return
+ }
+}