[mlir] Add number of operands verification for shape.assuming_all operation
authormsifontes <sifontes@google.com>
Tue, 9 Jun 2020 16:55:35 +0000 (09:55 -0700)
committerJacques Pienaar <jpienaar@google.com>
Tue, 9 Jun 2020 16:59:04 +0000 (09:59 -0700)
Implemented a verification to ensure that the shape.assuming_all
operation always has at least one operand.

mlir/include/mlir/Dialect/Shape/IR/ShapeOps.td
mlir/lib/Dialect/Shape/IR/Shape.cpp
mlir/test/Dialect/Shape/invalid.mlir

index c51423e..2393aa1 100644 (file)
@@ -507,6 +507,8 @@ def Shape_AssumingAllOp : Shape_Op<"assuming_all", [Commutative, NoSideEffect]>
   let assemblyFormat = "$inputs attr-dict";
 
   let hasFolder = 1;
+
+  let verifier = [{ return ::verify(*this); }];
 }
 
 def Shape_AssumingOp : Shape_Op<"assuming",
index c46df3a..9df20e4 100644 (file)
@@ -219,6 +219,14 @@ OpFoldResult AssumingAllOp::fold(ArrayRef<Attribute> operands) {
   return BoolAttr::get(true, getContext());
 }
 
+static LogicalResult verify(AssumingAllOp op) {
+  // Ensure that AssumingAllOp contains at least one operand
+  if (op.getNumOperands() == 0)
+    return op.emitOpError("no operands specified");
+
+  return success();
+}
+
 //===----------------------------------------------------------------------===//
 // BroadcastOp
 //===----------------------------------------------------------------------===//
index 41105dc..da059a4 100644 (file)
@@ -60,3 +60,11 @@ func @yield_op_type_mismatch(%shape : !shape.shape, %init : !shape.size) {
       shape.yield %c0 : index
   }
 }
+
+// -----
+
+func @assuming_all_op_too_few_operands() {
+  // expected-error@+1 {{no operands specified}}
+  %w0 = shape.assuming_all
+  return
+}