[Mlir-commits] [mlir] [mlir] avoid crash in transform.sequence verifier (PR #66756)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Tue Sep 19 02:48:24 PDT 2023


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-mlir

<details>
<summary>Changes</summary>

The verifier was unconditionally accessing the body block terminator, but it's not guaranteed that the block has one in general.

---
Full diff: https://github.com/llvm/llvm-project/pull/66756.diff


2 Files Affected:

- (modified) mlir/lib/Dialect/Transform/IR/TransformOps.cpp (+3) 
- (modified) mlir/test/Dialect/Transform/ops-invalid.mlir (+10) 


``````````diff
diff --git a/mlir/lib/Dialect/Transform/IR/TransformOps.cpp b/mlir/lib/Dialect/Transform/IR/TransformOps.cpp
index f1d07b85adb7576..dc004cd14dc0fbf 100644
--- a/mlir/lib/Dialect/Transform/IR/TransformOps.cpp
+++ b/mlir/lib/Dialect/Transform/IR/TransformOps.cpp
@@ -2188,6 +2188,9 @@ LogicalResult transform::SequenceOp::verify() {
     }
   }
 
+  if (!getBodyBlock()->hasTerminator())
+    return emitOpError() << "expects to have a terminator in the body";
+
   if (getBodyBlock()->getTerminator()->getOperandTypes() !=
       getOperation()->getResultTypes()) {
     InFlightDiagnostic diag = emitOpError()
diff --git a/mlir/test/Dialect/Transform/ops-invalid.mlir b/mlir/test/Dialect/Transform/ops-invalid.mlir
index 3e30947769eb403..096416158879812 100644
--- a/mlir/test/Dialect/Transform/ops-invalid.mlir
+++ b/mlir/test/Dialect/Transform/ops-invalid.mlir
@@ -22,6 +22,16 @@ transform.sequence failures(propagate) {
   }
 }
 
+// -----
+
+// expected-error @below {{expects to have a terminator in the body}}
+"transform.sequence"() <{failure_propagation_mode = 1 : i32, operandSegmentSizes = array<i32: 0, 0>}> ({
+^bb0(%arg0: !transform.any_op):
+  transform.apply_patterns to %arg0 {
+  } : !transform.any_op
+}) : () -> ()
+
+
 // -----
 
 // expected-error @below {{'transform.sequence' op expects trailing entry block arguments to be of type implementing TransformHandleTypeInterface, TransformValueHandleTypeInterface or TransformParamTypeInterface}}

``````````

</details>


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


More information about the Mlir-commits mailing list