[Mlir-commits] [mlir] [mlir][transform] Fix crash on empty type converter region (PR #237717)
Yi-Ping Pan
llvmlistbot at llvm.org
Sun Nov 1 03:59:22 PST 2026
https://github.com/TheCloudlet created https://github.com/llvm/llvm-project/pull/237717
The default type converter region of transform.apply_conversion_patterns is
declared MaxSizedRegion<1>, so it may have no blocks. The verifier called
front() on it unconditionally, which hits an assertion on an empty region.
Check for an empty region first and report the existing "expected exactly one op
in default type converter region" error. Add tests for both an empty block
(custom syntax) and a region without blocks, which is only expressible in the
generic form.
Fixes #234636
>From bc55aabd13c53e5d674916ade8c0aba0274baead Mon Sep 17 00:00:00 2001
From: "Yi-Ping Pan (Cloudlet)" <pan.yiping.fi at gmail.com>
Date: Sun, 1 Nov 2026 18:13:16 +0800
Subject: [PATCH] [mlir][transform] Fix crash on empty type converter region
The default type converter region of
transform.apply_conversion_patterns is declared MaxSizedRegion<1>, so
it may have no blocks. The verifier called front() on it
unconditionally, which hits an assertion on an empty region.
Check for an empty region first and report the existing "expected
exactly one op in default type converter region" error. Add tests for
both an empty block (custom syntax) and a region without blocks, which
is only expressible in the generic form.
Fixes #234636
---
.../lib/Dialect/Transform/IR/TransformOps.cpp | 3 +-
mlir/test/Dialect/Transform/ops-invalid.mlir | 28 +++++++++++++++++++
2 files changed, 30 insertions(+), 1 deletion(-)
diff --git a/mlir/lib/Dialect/Transform/IR/TransformOps.cpp b/mlir/lib/Dialect/Transform/IR/TransformOps.cpp
index e40f3b7885c273..1c6c5590a43e1e 100644
--- a/mlir/lib/Dialect/Transform/IR/TransformOps.cpp
+++ b/mlir/lib/Dialect/Transform/IR/TransformOps.cpp
@@ -613,7 +613,8 @@ LogicalResult transform::ApplyConversionPatternsOp::verify() {
}
if (getNumRegions() == 2) {
Region &typeConverterRegion = getRegion(1);
- if (!llvm::hasSingleElement(typeConverterRegion.front()))
+ if (typeConverterRegion.empty() ||
+ !llvm::hasSingleElement(typeConverterRegion.front()))
return emitOpError()
<< "expected exactly one op in default type converter region";
Operation *maybeTypeConverter = &typeConverterRegion.front().front();
diff --git a/mlir/test/Dialect/Transform/ops-invalid.mlir b/mlir/test/Dialect/Transform/ops-invalid.mlir
index 585736d30269e7..a5449580f0feb4 100644
--- a/mlir/test/Dialect/Transform/ops-invalid.mlir
+++ b/mlir/test/Dialect/Transform/ops-invalid.mlir
@@ -996,3 +996,31 @@ module attributes {transform.with_named_sequence} {
transform.yield
}
}
+
+// -----
+
+module attributes {transform.with_named_sequence} {
+ transform.named_sequence @__transform_main(%arg0: !transform.any_op) {
+ // The custom syntax creates an empty block for the type converter region.
+ // expected-error @below {{expected exactly one op in default type converter region}}
+ transform.apply_conversion_patterns to %arg0 {
+ } with type_converter {
+ } : !transform.any_op
+ transform.yield
+ }
+}
+
+// -----
+
+// The type converter region may have no blocks at all, which is only
+// expressible in the generic form. This used to crash the verifier.
+
+module attributes {transform.with_named_sequence} {
+ transform.named_sequence @__transform_main(%arg0: !transform.any_op) {
+ // expected-error @below {{expected exactly one op in default type converter region}}
+ "transform.apply_conversion_patterns"(%arg0) ({
+ }, {
+ }) : (!transform.any_op) -> ()
+ transform.yield
+ }
+}
More information about the Mlir-commits
mailing list