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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// RUN: mlir-opt %s --verify-diagnostics

// The only thing we check here is that it should fail to parse. The other
// check is in the preload test.

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 "should have ',' prior to this" : !transform.any_op
}
}
7 changes: 7 additions & 0 deletions mlir/test/Dialect/Transform/preload-library-invalid.mlir
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// RUN: mlir-opt %s \
// RUN: -transform-preload-library=transform-library-paths=%p%{fs-sep}include%{fs-sep}test-interpreter-library-invalid \
// RUN: -transform-interpreter=entry-point=private_helper \
// RUN: -verify-diagnostics

// This test checks if the preload mechanism fails gracefully when passed an
// invalid transform file.