Fix ConstShapeOp::inferReturnTypes to be resilient to lack of properties
authorMehdi Amini <joker.eph@gmail.com>
Mon, 15 May 2023 19:12:28 +0000 (12:12 -0700)
committerMehdi Amini <joker.eph@gmail.com>
Mon, 15 May 2023 19:12:28 +0000 (12:12 -0700)
The Python bindings test aren't using properties yet, this is a bit
of a hack to support this here, but hopefully it'll be temporary.

mlir/lib/Dialect/Shape/IR/Shape.cpp

index 2430254..58d0e6a 100644 (file)
@@ -921,7 +921,13 @@ LogicalResult mlir::shape::ConstShapeOp::inferReturnTypes(
     SmallVectorImpl<Type> &inferredReturnTypes) {
   Builder b(context);
   Properties *prop = properties.as<Properties *>();
-  DenseIntElementsAttr shape = prop->shape;
+  DenseIntElementsAttr shape;
+  // TODO: this is only exercised by the Python bindings codepath which does not
+  // support properties
+  if (prop)
+    shape = prop->shape;
+  else
+    shape = attributes.getAs<DenseIntElementsAttr>("shape");
   if (!shape)
     return emitOptionalError(location, "missing shape attribute");
   inferredReturnTypes.assign({RankedTensorType::get(