[Mlir-commits] [mlir] [mlir][memref.expand_shape] Add verifier check to ensure correct output_shape is provided by user (PR #91245)

Benoit Jacob llvmlistbot at llvm.org
Wed May 8 09:11:35 PDT 2024


================
@@ -2353,6 +2353,16 @@ LogicalResult ExpandShapeOp::verify() {
            << " dynamic dims while output_shape has " << getOutputShape().size()
            << " values";
 
+  // Verify if provided output shapes are in agreement with output type.
+  DenseI64ArrayAttr staticOutputShapes = getStaticOutputShapeAttr();
+  ArrayRef<int64_t> resShape = getResult().getType().getShape();
+  unsigned staticShapeNum = 0;
+
+  for (auto [pos, shape] : llvm::enumerate(resShape))
+    if (!ShapedType::isDynamic(shape) &&
+        shape != staticOutputShapes[staticShapeNum++])
+      emitOpError("invalid output shape provided at pos ") << pos;
+
----------------
bjacob wrote:

Is this correct? Concretely, this verifier is producing an error when `resShape` and `staticOutputShape` are equal, and contain a mix of static and `kDynamic` values. Indeed, since in C++ the `&&` operator is a sequence point, the `staticShapeNum++` increment is only happening if the left hand side, `!ShapedType::isDynamic(shape)`, evaluated to true. In other words, this verifier code requires `staticOutputShape` to only list static dimensions and omit `kDynamic` values. 


https://github.com/llvm/llvm-project/pull/91245


More information about the Mlir-commits mailing list