@@ -230,8 +230,10 @@ struct ConstantCompositeOpPattern final
230
230
if (!srcType || srcType.getNumElements () == 1 )
231
231
return failure ();
232
232
233
- // arith.constant should only have vector or tensor types.
234
- assert ((isa<VectorType, RankedTensorType>(srcType)));
233
+ // arith.constant should only have vector or tensor types. This is a MLIR
234
+ // wide problem at the moment.
235
+ if (!isa<VectorType, RankedTensorType>(srcType))
236
+ return rewriter.notifyMatchFailure (constOp, " unsupported ShapedType" );
235
237
236
238
Type dstType = getTypeConverter ()->convertType (srcType);
237
239
if (!dstType)
@@ -246,12 +248,22 @@ struct ConstantCompositeOpPattern final
246
248
} else if (auto resourceAttr =
247
249
dyn_cast<DenseResourceElementsAttr>(constOp.getValue ())) {
248
250
249
- ArrayRef<char > ptr = resourceAttr.getRawHandle ().getBlob ()->getData ();
251
+ AsmResourceBlob *blob = resourceAttr.getRawHandle ().getBlob ();
252
+ if (!blob)
253
+ return constOp->emitError (" could not find resource blob" );
254
+
255
+ ArrayRef<char > ptr = blob->getData ();
256
+
257
+ // Check that the buffer meets the requirements to get converted to a
258
+ // DenseElementsAttr
259
+ bool detectedSplat = false ;
260
+ if (!DenseElementsAttr::isValidRawBuffer (srcType, ptr, detectedSplat))
261
+ return constOp->emitError (" resource is not a valid buffer" );
262
+
250
263
dstElementsAttr =
251
264
DenseElementsAttr::getFromRawBuffer (resourceAttr.getType (), ptr);
252
265
} else {
253
- return rewriter.notifyMatchFailure (constOp,
254
- " Could not decode ElementsAttr" );
266
+ return constOp->emitError (" unsupported elements attribute" );
255
267
}
256
268
257
269
ShapedType dstAttrType = dstElementsAttr.getType ();
0 commit comments