Skip to content

Commit a941e15

Browse files
[MLIR][Transform] Return empty handles when the included sequence fails (#169782)
This fixes a bug in the interpreter for transform.include op, which crashes when attempting to copy out the handles from the yield op of a failing sequence.
1 parent 442f853 commit a941e15

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

mlir/lib/Dialect/Transform/IR/TransformOps.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2062,6 +2062,10 @@ transform::IncludeOp::apply(transform::TransformRewriter &rewriter,
20622062

20632063
DiagnosedSilenceableFailure result = applySequenceBlock(
20642064
callee.getBody().front(), getFailurePropagationMode(), state, results);
2065+
2066+
if (!result.succeeded())
2067+
return result;
2068+
20652069
mappings.clear();
20662070
detail::prepareValueMappings(
20672071
mappings, callee.getBody().front().getTerminator()->getOperands(), state);
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// RUN: mlir-opt %s --transform-interpreter -allow-unregistered-dialect --verify-diagnostics
2+
3+
module attributes { transform.with_named_sequence } {
4+
// Callee returns a silenceable failure when given a module instead of func.func.
5+
transform.named_sequence @callee(%root: !transform.any_op {transform.consumed}) -> (!transform.any_op) {
6+
transform.test_consume_operand_of_op_kind_or_fail %root, "func.func" : !transform.any_op
7+
transform.yield %root : !transform.any_op
8+
}
9+
10+
transform.named_sequence @__transform_main(%root: !transform.any_op) {
11+
%res = transform.sequence %root : !transform.any_op -> !transform.any_op failures(suppress) {
12+
^bb0(%arg0: !transform.any_op):
13+
// This include returns a silenceable failure; it must not remap results.
14+
%included = transform.include @callee failures(propagate) (%arg0) : (!transform.any_op) -> (!transform.any_op)
15+
transform.yield %included : !transform.any_op
16+
}
17+
18+
%count = transform.num_associations %res : (!transform.any_op) -> !transform.param<i64>
19+
// expected-remark @below {{0}}
20+
transform.debug.emit_param_as_remark %count : !transform.param<i64>
21+
22+
// If the include incorrectly forwarded mappings on failure, this would run
23+
// and produce an unexpected remark under --verify-diagnostics.
24+
transform.foreach %res : !transform.any_op {
25+
^bb0(%it: !transform.any_op):
26+
transform.debug.emit_remark_at %it, "include result unexpectedly populated" : !transform.any_op
27+
}
28+
transform.yield
29+
}
30+
}
31+
32+
// -----
33+
34+
module {
35+
func.func @payload() {
36+
return
37+
}
38+
}

0 commit comments

Comments
 (0)