[Mlir-commits] [mlir] [mlir][bytecode] Avoid crash when test dialect version is missing (PR #170173)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Mon Dec 1 09:31:20 PST 2025
https://github.com/Men-cotton created https://github.com/llvm/llvm-project/pull/170173
- Guard the test bytecode roundtrip writer/reader in `mlir/test/lib/IR/TestBytecodeRoundtrip.cpp` so `--test-bytecode-roundtrip=test-dialect-version=2.0` no longer asserts when the test dialect version isn’t present.
- Add regression coverage for the missing-version scenario in `mlir/test/Bytecode/roundtrip-missing-dialect.mlir`.
Fixes: https://github.com/llvm/llvm-project/issues/128325
Fixes: https://github.com/llvm/llvm-project/issues/128321
>From f4dfe450373ae793cd481a246ee0864f2453a676 Mon Sep 17 00:00:00 2001
From: mencotton <mencotton0410 at gmail.com>
Date: Tue, 2 Dec 2025 02:09:25 +0900
Subject: [PATCH] [mlir][bytecode] Avoid crash when test dialect version is
missing
---
mlir/test/Bytecode/roundtrip-missing-dialect.mlir | 6 ++++++
mlir/test/lib/IR/TestBytecodeRoundtrip.cpp | 8 ++++----
2 files changed, 10 insertions(+), 4 deletions(-)
create mode 100644 mlir/test/Bytecode/roundtrip-missing-dialect.mlir
diff --git a/mlir/test/Bytecode/roundtrip-missing-dialect.mlir b/mlir/test/Bytecode/roundtrip-missing-dialect.mlir
new file mode 100644
index 0000000000000..8a93fcfd55695
--- /dev/null
+++ b/mlir/test/Bytecode/roundtrip-missing-dialect.mlir
@@ -0,0 +1,6 @@
+// RUN: mlir-opt %s --test-bytecode-roundtrip=test-dialect-version=2.0 | FileCheck %s
+
+// CHECK-LABEL: func.func @main
+func.func @main() {
+ return
+}
diff --git a/mlir/test/lib/IR/TestBytecodeRoundtrip.cpp b/mlir/test/lib/IR/TestBytecodeRoundtrip.cpp
index 4894ad5294990..f6ee97831c9dd 100644
--- a/mlir/test/lib/IR/TestBytecodeRoundtrip.cpp
+++ b/mlir/test/lib/IR/TestBytecodeRoundtrip.cpp
@@ -141,8 +141,8 @@ struct TestBytecodeRoundtripPass
DialectBytecodeWriter &writer) -> LogicalResult {
// Do not override anything if version greater than 2.0.
auto versionOr = writer.getDialectVersion<test::TestDialect>();
- assert(succeeded(versionOr) && "expected reader to be able to access "
- "the version for test dialect");
+ if (failed(versionOr))
+ return failure();
const auto *version =
reinterpret_cast<const test::TestDialectVersion *>(*versionOr);
if (version->major_ >= 2)
@@ -166,8 +166,8 @@ struct TestBytecodeRoundtripPass
Type &entry) -> LogicalResult {
// Get test dialect version from the version map.
auto versionOr = reader.getDialectVersion<test::TestDialect>();
- assert(succeeded(versionOr) && "expected reader to be able to access "
- "the version for test dialect");
+ if (failed(versionOr))
+ return success();
const auto *version =
reinterpret_cast<const test::TestDialectVersion *>(*versionOr);
if (version->major_ >= 2)
More information about the Mlir-commits
mailing list