diff --git a/mlir/lib/Bindings/Python/IRAttributes.cpp b/mlir/lib/Bindings/Python/IRAttributes.cpp --- a/mlir/lib/Bindings/Python/IRAttributes.cpp +++ b/mlir/lib/Bindings/Python/IRAttributes.cpp @@ -629,8 +629,17 @@ } } if (bulkLoadElementType) { - auto shapedType = mlirRankedTensorTypeGet( - shape.size(), shape.data(), *bulkLoadElementType, encodingAttr); + MlirType shapedType; + if (mlirTypeIsAShaped(*bulkLoadElementType)) { + if (explicitShape) { + throw std::invalid_argument("Shape can only be specified explicitly " + "when the type is not a shaped type."); + } + shapedType = *bulkLoadElementType; + } else { + shapedType = mlirRankedTensorTypeGet( + shape.size(), shape.data(), *bulkLoadElementType, encodingAttr); + } size_t rawBufferSize = arrayInfo.size * arrayInfo.itemsize; MlirAttribute attr = mlirDenseElementsAttrRawBufferGet( shapedType, rawBufferSize, arrayInfo.ptr);