-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[mlir][Transform] Fix crash with invalid ir for transform libraries #75649
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
Conversation
@llvm/pr-subscribers-mlir Author: Kunwar Grover (Groverkss) ChangesThis patch fixes a crash caused when the transform library interpreter is given an IR that fails to parse. Full diff: https://github.com/llvm/llvm-project/pull/75649.diff 2 Files Affected:
diff --git a/mlir/lib/Dialect/Transform/Transforms/TransformInterpreterUtils.cpp b/mlir/lib/Dialect/Transform/Transforms/TransformInterpreterUtils.cpp
index 3fa26bce150992..2f74b76f07b77b 100644
--- a/mlir/lib/Dialect/Transform/Transforms/TransformInterpreterUtils.cpp
+++ b/mlir/lib/Dialect/Transform/Transforms/TransformInterpreterUtils.cpp
@@ -109,6 +109,12 @@ LogicalResult transform::detail::parseTransformModuleFromFile(
sourceMgr.AddNewSourceBuffer(std::move(memoryBuffer), llvm::SMLoc());
transformModule =
OwningOpRef<ModuleOp>(parseSourceFile<ModuleOp>(sourceMgr, context));
+ if (!transformModule) {
+ // Failed to parse the transform module.
+ // Don't need to emit an error here as the parsing should have already done
+ // that.
+ return failure();
+ }
return mlir::verify(*transformModule);
}
diff --git a/mlir/test/Dialect/Transform/include/test-interpreter-invalid.mlir b/mlir/test/Dialect/Transform/include/test-interpreter-invalid.mlir
new file mode 100644
index 00000000000000..8b5641293d27e6
--- /dev/null
+++ b/mlir/test/Dialect/Transform/include/test-interpreter-invalid.mlir
@@ -0,0 +1,8 @@
+// RUN: mlir-opt %s --verify-diagnostics
+
+module attributes {transform.with_named_sequence} {
+ transform.named_sequence private @private_helper(%arg0: !transform.any_op {transform.readonly}) {
+ // expected-error @below {{expected ','}}
+ transform.test_print_remark_at_operand %arg0 "message" : !transform.any_op
+ }
+}
|
mlir/test/Dialect/Transform/include/test-interpreter-invalid.mlir
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome, thanks for the fix!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the patch. Please add the test that actually tests the behavior the patch is fixing. Removing the changes in .cpp
doesn't make the test fail. This file should likely be passed as "library" via one of the mechanisms that ultimately invokes this function.
Thank you for checking. I pushed a test that uses the library mechanisms to check for failure. Also confirmed that the tests fail without the .cpp change now. |
This patch fixes a crash caused when the transform library interpreter is given an IR that fails to parse.