Skip to content

Commit 282d501

Browse files
authored
[mlir][Transform] Fix crash with invalid ir for transform libraries (#75649)
This patch fixes a crash caused when the transform library interpreter is given an IR that fails to parse.
1 parent 899c2be commit 282d501

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

mlir/lib/Dialect/Transform/Transforms/TransformInterpreterUtils.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,12 @@ LogicalResult transform::detail::parseTransformModuleFromFile(
109109
sourceMgr.AddNewSourceBuffer(std::move(memoryBuffer), llvm::SMLoc());
110110
transformModule =
111111
OwningOpRef<ModuleOp>(parseSourceFile<ModuleOp>(sourceMgr, context));
112+
if (!transformModule) {
113+
// Failed to parse the transform module.
114+
// Don't need to emit an error here as the parsing should have already done
115+
// that.
116+
return failure();
117+
}
112118
return mlir::verify(*transformModule);
113119
}
114120

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// RUN: mlir-opt %s --verify-diagnostics
2+
3+
// The only thing we check here is that it should fail to parse. The other
4+
// check is in the preload test.
5+
6+
module attributes {transform.with_named_sequence} {
7+
transform.named_sequence private @private_helper(%arg0: !transform.any_op {transform.readonly}) {
8+
// expected-error @below {{expected ','}}
9+
transform.test_print_remark_at_operand %arg0 "should have ',' prior to this" : !transform.any_op
10+
}
11+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// RUN: mlir-opt %s \
2+
// RUN: -transform-preload-library=transform-library-paths=%p%{fs-sep}include%{fs-sep}test-interpreter-library-invalid \
3+
// RUN: -transform-interpreter=entry-point=private_helper \
4+
// RUN: -verify-diagnostics
5+
6+
// This test checks if the preload mechanism fails gracefully when passed an
7+
// invalid transform file.

0 commit comments

Comments
 (0)