[Mlir-commits] [mlir] 68033aa - [mlir][transform] Fix crash in transform.get_parent_op. (#66492)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Fri Sep 15 12:32:21 PDT 2023
Author: Ingo Müller
Date: 2023-09-15T21:32:17+02:00
New Revision: 68033aaac5c94d1199e6cc3e6406e4d3fa10b040
URL: https://github.com/llvm/llvm-project/commit/68033aaac5c94d1199e6cc3e6406e4d3fa10b040
DIFF: https://github.com/llvm/llvm-project/commit/68033aaac5c94d1199e6cc3e6406e4d3fa10b040.diff
LOG: [mlir][transform] Fix crash in transform.get_parent_op. (#66492)
The previous implementation crashed if run on a `builtin.module` using
an `op_name` filter (because the initial value of `parent` in the while
loop was a `nullptr`). This PR fixes the crash and adds a test.
Added:
Modified:
mlir/lib/Dialect/Transform/IR/TransformOps.cpp
mlir/test/Dialect/Transform/test-interpreter.mlir
Removed:
################################################################################
diff --git a/mlir/lib/Dialect/Transform/IR/TransformOps.cpp b/mlir/lib/Dialect/Transform/IR/TransformOps.cpp
index de3cd1b28e435bc..f1d07b85adb7576 100644
--- a/mlir/lib/Dialect/Transform/IR/TransformOps.cpp
+++ b/mlir/lib/Dialect/Transform/IR/TransformOps.cpp
@@ -1233,7 +1233,7 @@ transform::GetParentOp::apply(transform::TransformRewriter &rewriter,
DenseSet<Operation *> resultSet;
for (Operation *target : state.getPayloadOps(getTarget())) {
Operation *parent = target->getParentOp();
- do {
+ while (parent) {
bool checkIsolatedFromAbove =
!getIsolatedFromAbove() ||
parent->hasTrait<OpTrait::IsIsolatedFromAbove>();
@@ -1241,7 +1241,8 @@ transform::GetParentOp::apply(transform::TransformRewriter &rewriter,
parent->getName().getStringRef() == *getOpName();
if (checkIsolatedFromAbove && checkOpName)
break;
- } while ((parent = parent->getParentOp()));
+ parent = parent->getParentOp();
+ }
if (!parent) {
DiagnosedSilenceableFailure diag =
emitSilenceableError()
diff --git a/mlir/test/Dialect/Transform/test-interpreter.mlir b/mlir/test/Dialect/Transform/test-interpreter.mlir
index 68e3a4851539690..daa179cb15408b4 100644
--- a/mlir/test/Dialect/Transform/test-interpreter.mlir
+++ b/mlir/test/Dialect/Transform/test-interpreter.mlir
@@ -1891,6 +1891,18 @@ transform.sequence failures(propagate) {
test_print_number_of_associated_payload_ir_ops %4 : !transform.any_op
}
+
+// -----
+
+// expected-note @below {{target op}}
+module {
+ transform.sequence failures(propagate) {
+ ^bb0(%arg0: !transform.any_op):
+ // expected-error @below{{could not find a parent op that matches all requirements}}
+ %3 = get_parent_op %arg0 {op_name = "builtin.module"} : (!transform.any_op) -> !transform.any_op
+ }
+}
+
// -----
func.func @cast(%arg0: f32) -> f64 {
More information about the Mlir-commits
mailing list