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

llvmlistbot at llvm.org llvmlistbot at llvm.org
Tue Sep 19 04:28:57 PDT 2023


Author: Oleksandr "Alex" Zinenko
Date: 2023-09-19T13:28:53+02:00
New Revision: a2a1dbb518ab836ca644275867b33b24bb7df8ab

URL: https://github.com/llvm/llvm-project/commit/a2a1dbb518ab836ca644275867b33b24bb7df8ab
DIFF: https://github.com/llvm/llvm-project/commit/a2a1dbb518ab836ca644275867b33b24bb7df8ab.diff

LOG: [mlir] avoid crash in transform.sequence verifier (#66756)

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

Added: 
    

Modified: 
    mlir/lib/Dialect/Transform/IR/TransformOps.cpp
    mlir/test/Dialect/Transform/ops-invalid.mlir

Removed: 
    


################################################################################
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}}


        


More information about the Mlir-commits mailing list