<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/128321>128321</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [MLIR]`-test-bytecode-roundtrip=test-dialect-version=2.0` triggers Assertion Failure `succeeded(versionOr) && "expected reader to be able to access " "the version for test dialect"'
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            mlir
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          xisang0
      </td>
    </tr>
</table>

<pre>
    Test on commit: https://github.com/llvm/llvm-project/commit/a9882bda96228ca23e166a817f93a7dbc99763cb
steps to reproduce:
```
mlir-opt test.mlir -test-bytecode-roundtrip=test-dialect-version=2.0
```
test case:
```
module {
  func.func @main() -> () {
    return
 }
}
```
crash trace:
```
mlir-opt: /home/workdir/llvm-project-19/mlir/test/lib/IR/TestBytecodeRoundtrip.cpp:170: auto (anonymous namespace)::TestBytecodeRoundtripPass::runTest0(Operation *)::(anonymous class)::operator()(DialectBytecodeReader &, StringRef, Type &) const: Assertion `succeeded(versionOr) && "expected reader to be able to access " "the version for test dialect"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.      Program arguments: ./mlir-opt /home/workdir/test.mlir -test-bytecode-roundtrip=test-dialect-version=2.0
 #0 0x000063e93b4fa998 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (./mlir-opt+0x108a998)
 #1 0x000063e93b4f84be llvm::sys::RunSignalHandlers() (./mlir-opt+0x10884be)
 #2 0x000063e93b4fb3a8 SignalHandler(int) Signals.cpp:0:0
 #3 0x0000765ce93c9520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #4 0x0000765ce941d9fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
 #5 0x0000765ce93c9476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
 #6 0x0000765ce93af7f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
 #7 0x0000765ce93af71b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
 #8 0x0000765ce93c0e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
 #9 0x000063e93e69a424 (./mlir-opt+0x422a424)
#10 0x000063e9408a2b41 (anonymous namespace)::AttrTypeReader::resolveType(unsigned long) BytecodeReader.cpp:0:0
#11 0x000063e9408a1817 (anonymous namespace)::DialectReader::readType(mlir::Type&) BytecodeReader.cpp:0:0
#12 0x000063e93e8ee5ef (anonymous namespace)::BuiltinDialectBytecodeInterface::readAttribute(mlir::DialectBytecodeReader&) const BuiltinDialectBytecode.cpp:0:0
#13 0x000063e9408a23e4 (anonymous namespace)::AttrTypeReader::resolveAttribute(unsigned long) BytecodeReader.cpp:0:0
#14 0x000063e9408a1777 (anonymous namespace)::DialectReader::readAttribute(mlir::Attribute&) BytecodeReader.cpp:0:0
#15 0x000063e93b990911 llvm::LogicalResult mlir::DialectBytecodeReader::readAttribute<mlir::TypeAttr>(mlir::TypeAttr&) (./mlir-opt+0x1520911)
#16 0x000063e93bb8d517 mlir::func::FuncOp::readProperties(mlir::DialectBytecodeReader&, mlir::OperationState&) (./mlir-opt+0x171d517)
#17 0x000063e94089f0c8 mlir::BytecodeReader::Impl::parseRegions(std::vector<mlir::BytecodeReader::Impl::RegionReadState, std::allocator<mlir::BytecodeReader::Impl::RegionReadState>>&, mlir::BytecodeReader::Impl::RegionReadState&) (./mlir-opt+0x642f0c8)
#18 0x000063e94089aadb mlir::BytecodeReader::Impl::parseIRSection(llvm::ArrayRef<unsigned char>, mlir::Block*) (./mlir-opt+0x642aadb)
#19 0x000063e940897f3d mlir::BytecodeReader::Impl::read(mlir::Block*, llvm::function_ref<bool (mlir::Operation*)>) (./mlir-opt+0x6427f3d)
#20 0x000063e9408a08be readBytecodeFileImpl(llvm::MemoryBufferRef, mlir::Block*, mlir::ParserConfig const&, std::shared_ptr<llvm::SourceMgr> const&) BytecodeReader.cpp:0:0
#21 0x000063e9408a074e mlir::readBytecodeFile(llvm::MemoryBufferRef, mlir::Block*, mlir::ParserConfig const&) (./mlir-opt+0x643074e)
#22 0x000063e93e7c82ef mlir::parseSourceFile(llvm::SourceMgr const&, mlir::Block*, mlir::ParserConfig const&, mlir::LocationAttr*) (./mlir-opt+0x43582ef)
#23 0x000063e93e7c8988 mlir::parseSourceString(llvm::StringRef, mlir::Block*, mlir::ParserConfig const&, llvm::StringRef, mlir::LocationAttr*) (./mlir-opt+0x4358988)
#24 0x000063e93e699e74 (anonymous namespace)::TestBytecodeRoundtripPass::doRoundtripWithConfigs(mlir::Operation*, mlir::BytecodeWriterConfig const&, mlir::ParserConfig const&) TestBytecodeRoundtrip.cpp:0:0
#25 0x000063e93e697a00 (anonymous namespace)::TestBytecodeRoundtripPass::runOnOperation() TestBytecodeRoundtrip.cpp:0:0
#26 0x000063e93e7cb3bf mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (./mlir-opt+0x435b3bf)
#27 0x000063e93e7cbba2 mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) (./mlir-opt+0x435bba2)
#28 0x000063e93e7ce34e mlir::PassManager::run(mlir::Operation*) (./mlir-opt+0x435e34e)
#29 0x000063e93e7c6e6b performActions(llvm::raw_ostream&, std::shared_ptr<llvm::SourceMgr> const&, mlir::MLIRContext*, mlir::MlirOptMainConfig const&) MlirOptMain.cpp:0:0
#30 0x000063e93e7c6acb llvm::LogicalResult llvm::function_ref<llvm::LogicalResult (std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&)>::callback_fn<mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&)::$_0>(long, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&) MlirOptMain.cpp:0:0
#31 0x000063e93e86fdf5 mlir::splitAndProcessBuffer(std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::function_ref<llvm::LogicalResult (std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&)>, llvm::raw_ostream&, llvm::StringRef, llvm::StringRef) (./mlir-opt+0x43ffdf5)
#32 0x000063e93e7c19b2 mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&) (./mlir-opt+0x43519b2)
#33 0x000063e93e7c1c63 mlir::MlirOptMain(int, char**, llvm::StringRef, llvm::StringRef, mlir::DialectRegistry&) (./mlir-opt+0x4351c63)
#34 0x000063e93e7c1e72 mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&) (./mlir-opt+0x4351e72)
#35 0x000063e93b4d9c27 main (./mlir-opt+0x1069c27)
#36 0x0000765ce93b0d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#37 0x0000765ce93b0e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#38 0x000063e93b4d9795 _start (./mlir-opt+0x1069795)
Aborted (core dumped)
```
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzcWl9P47oS_zTmxaJy7DR_HnjoAtVFWgSClc5j5TiT4ktq59rOHvj2V07S5g8p3bI69-ie1ULT2J75zcxv7LENt1ZuFcAVWn5Dy5sLXrsXba7epOVqSy4ynb9f_QDrsFZY6N1OOsRW-MW5yiK2QnSN6Hor3UudLYTeIbouy5_7j8vK6H-DcIiuu6F0zdMk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