[Mlir-commits] [mlir] [mlir][Transform] Fix crash with invalid ir for transform libraries (PR #75649)
Kunwar Grover
llvmlistbot at llvm.org
Fri Dec 15 12:19:45 PST 2023
https://github.com/Groverkss created https://github.com/llvm/llvm-project/pull/75649
This patch fixes a crash caused when the transform library interpreter is given an IR that fails to parse.
>From a871189a913e2867e516b6bd463c4b46d81f62c5 Mon Sep 17 00:00:00 2001
From: Kunwar Grover <groverkss at gmail.com>
Date: Sat, 16 Dec 2023 01:46:44 +0530
Subject: [PATCH] [mlir][Transform] Fix crash with invalid ir for transform
libraries
---
.../Transform/Transforms/TransformInterpreterUtils.cpp | 6 ++++++
.../Transform/include/test-interpreter-invalid.mlir | 8 ++++++++
2 files changed, 14 insertions(+)
create mode 100644 mlir/test/Dialect/Transform/include/test-interpreter-invalid.mlir
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
+ }
+}
More information about the Mlir-commits
mailing list