Skip to content

[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

Merged
merged 3 commits into from
Dec 19, 2023

Conversation

Groverkss
Copy link
Member

This patch fixes a crash caused when the transform library interpreter is given an IR that fails to parse.

@llvmbot
Copy link
Member

llvmbot commented Dec 15, 2023

@llvm/pr-subscribers-mlir

Author: Kunwar Grover (Groverkss)

Changes

This 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:

  • (modified) mlir/lib/Dialect/Transform/Transforms/TransformInterpreterUtils.cpp (+6)
  • (added) mlir/test/Dialect/Transform/include/test-interpreter-invalid.mlir (+8)
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
+  }
+}

Copy link
Contributor

@ingomueller-net ingomueller-net left a 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!

Copy link
Member

@ftynse ftynse left a 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.

@Groverkss Groverkss closed this Dec 16, 2023
@Groverkss Groverkss reopened this Dec 16, 2023
@Groverkss
Copy link
Member Author

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.

@Groverkss Groverkss requested a review from ftynse December 16, 2023 12:54
@Groverkss Groverkss merged commit 282d501 into llvm:main Dec 19, 2023
@Groverkss Groverkss deleted the parserinvalidlibrarycrash branch December 19, 2023 17:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants