Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[mlir] avoid crash in transform.sequence verifier #66756

Merged
merged 1 commit into from
Sep 19, 2023
Merged

Conversation

ftynse
Copy link
Member

@ftynse ftynse commented Sep 19, 2023

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

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

llvmbot commented Sep 19, 2023

@llvm/pr-subscribers-mlir

Changes

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

Copy link
Contributor

@martin-luecke martin-luecke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ftynse ftynse merged commit a2a1dbb into llvm:main Sep 19, 2023
3 checks passed
@ftynse ftynse deleted the bugfix branch September 19, 2023 11:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants