[Mlir-commits] [mlir] 3b76b85 - [MLIR] Fix crash in test-bytecode-roundtrip when test dialect is absent (#189163)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Sat Mar 28 05:54:49 PDT 2026


Author: Mehdi Amini
Date: 2026-03-28T12:54:43Z
New Revision: 3b76b85b15a3e7aa004814944f6237f131b95961

URL: https://github.com/llvm/llvm-project/commit/3b76b85b15a3e7aa004814944f6237f131b95961
DIFF: https://github.com/llvm/llvm-project/commit/3b76b85b15a3e7aa004814944f6237f131b95961.diff

LOG: [MLIR] Fix crash in test-bytecode-roundtrip when test dialect is absent (#189163)

When invoking `-test-bytecode-roundtrip=test-dialect-version=X.Y` on a
module that contains no test dialect operations, the reader type
callback in `runTest0` called
`reader.getDialectVersion<test::TestDialect>()` and then immediately
asserted that it succeeded. However, if the test dialect was never
referenced in the bytecode (because no test dialect types appear in the
module), the dialect's version information is not stored in the
bytecode, so `getDialectVersion` legitimately returns failure.

When the test dialect version is unavailable in the bytecode being read,
the module contains no test dialect types, so no "funky"-group overrides
are needed and the callback can safely skip by returning `success()`.

A regression test is added with a module that has no test dialect ops,
exercising the `test-dialect-version=2.0` path that previously crashed.

Fixes #128321
Fixes #128325

Assisted-by: Claude Code

Added: 
    

Modified: 
    mlir/test/Bytecode/bytecode_callback.mlir
    mlir/test/lib/IR/TestBytecodeRoundtrip.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/test/Bytecode/bytecode_callback.mlir b/mlir/test/Bytecode/bytecode_callback.mlir
index 3b537bb974da9..a3f6883f53236 100644
--- a/mlir/test/Bytecode/bytecode_callback.mlir
+++ b/mlir/test/Bytecode/bytecode_callback.mlir
@@ -1,5 +1,6 @@
 // RUN: mlir-opt %s --test-bytecode-roundtrip="test-dialect-version=1.2" -verify-diagnostics | FileCheck %s --check-prefix=VERSION_1_2
 // RUN: mlir-opt %s --test-bytecode-roundtrip="test-dialect-version=2.0" -verify-diagnostics | FileCheck %s --check-prefix=VERSION_2_0
+// RUN: mlir-opt %s --split-input-file --test-bytecode-roundtrip="test-dialect-version=2.0" -verify-diagnostics | FileCheck %s --check-prefix=NO_TEST_DIALECT
 
 func.func @base_test(%arg0 : i32) -> f32 {
   %0 = "test.addi"(%arg0, %arg0) : (i32, i32) -> i32
@@ -12,3 +13,15 @@ func.func @base_test(%arg0 : i32) -> f32 {
 
 // VERSION_2_0-NOT: Overriding IntegerType encoding...
 // VERSION_2_0-NOT: Overriding parsing of IntegerType encoding...
+
+// -----
+
+// Regression test for https://github.com/llvm/llvm-project/issues/128321:
+// test-bytecode-roundtrip must not crash when the test dialect is absent from
+// the module (i.e., no test dialect types are present in the bytecode).
+
+// NO_TEST_DIALECT-NOT: Overriding IntegerType encoding...
+// NO_TEST_DIALECT: func.func @no_test_dialect_ops
+func.func @no_test_dialect_ops() {
+  return
+}

diff  --git a/mlir/test/lib/IR/TestBytecodeRoundtrip.cpp b/mlir/test/lib/IR/TestBytecodeRoundtrip.cpp
index e83a3432a0286..d7e224f8b04ea 100644
--- a/mlir/test/lib/IR/TestBytecodeRoundtrip.cpp
+++ b/mlir/test/lib/IR/TestBytecodeRoundtrip.cpp
@@ -166,10 +166,12 @@ struct TestBytecodeRoundtripPass
     parseConfig.getBytecodeReaderConfig().attachTypeCallback(
         [&](DialectBytecodeReader &reader, StringRef dialectName,
             Type &entry) -> LogicalResult {
-          // Get test dialect version from the version map.
+          // Get test dialect version from the version map. If the test dialect
+          // is not present in the bytecode (e.g., the module contains no test
+          // dialect types), version info will be absent -- just skip.
           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