From 1c189d71dbb9ea0f8dd2f396c051c4c89e0ad2df Mon Sep 17 00:00:00 2001 From: msifontes Date: Tue, 9 Jun 2020 09:55:35 -0700 Subject: [PATCH] [mlir] Add number of operands verification for shape.assuming_all operation 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 | 2 ++ mlir/lib/Dialect/Shape/IR/Shape.cpp | 8 ++++++++ mlir/test/Dialect/Shape/invalid.mlir | 8 ++++++++ 3 files changed, 18 insertions(+) diff --git a/mlir/include/mlir/Dialect/Shape/IR/ShapeOps.td b/mlir/include/mlir/Dialect/Shape/IR/ShapeOps.td index c51423e..2393aa186 100644 --- a/mlir/include/mlir/Dialect/Shape/IR/ShapeOps.td +++ b/mlir/include/mlir/Dialect/Shape/IR/ShapeOps.td @@ -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", diff --git a/mlir/lib/Dialect/Shape/IR/Shape.cpp b/mlir/lib/Dialect/Shape/IR/Shape.cpp index c46df3a..9df20e4 100644 --- a/mlir/lib/Dialect/Shape/IR/Shape.cpp +++ b/mlir/lib/Dialect/Shape/IR/Shape.cpp @@ -219,6 +219,14 @@ OpFoldResult AssumingAllOp::fold(ArrayRef 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 //===----------------------------------------------------------------------===// diff --git a/mlir/test/Dialect/Shape/invalid.mlir b/mlir/test/Dialect/Shape/invalid.mlir index 41105dc..da059a4 100644 --- a/mlir/test/Dialect/Shape/invalid.mlir +++ b/mlir/test/Dialect/Shape/invalid.mlir @@ -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 +} -- 2.7.4