diff --git a/mlir/test/Bytecode/bytecode_callback.mlir b/mlir/test/Bytecode/bytecode_callback.mlir index 3b537bb974da..a3f6883f5323 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 e83a3432a028..d7e224f8b04e 100644 --- a/mlir/test/lib/IR/TestBytecodeRoundtrip.cpp +++ b/mlir/test/lib/IR/TestBytecodeRoundtrip.cpp @@ -166,10 +166,12 @@ private: 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(); - 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(*versionOr); if (version->major_ >= 2)