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

    <tr>
        <th>Summary</th>
        <td>
            [MLIR]`-test-bytecode-roundtrip=test-kind=2` triggers Assertion Failure `val == 0 && "Value must be zero for unsigned 0-bit APInt"'
        </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-kind=2
```
test case:
```
module {
 func.func @combined_operations() -> () {
    %cst = arith.constant dense<[[true, true, true], [true, false, true]]> : tensor<2x3xi1>
 %reduction_output = tosa.reduce_all %cst {axis = 1 : i32} : (tensor<2x3xi1>) -> tensor<2x1xi1>
    return
  }
}
```
crash trace:
```
mlir-opt: /home/workdir/llvm-project-19/llvm/include/llvm/ADT/APInt.h:125: llvm::APInt::APInt(unsigned int, uint64_t, bool, bool): Assertion `val == 0 && "Value must be zero for unsigned 0-bit APInt"' 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-kind=2
 #0 0x00005ed14c5be998 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (./mlir-opt+0x108a998)
 #1 0x00005ed14c5bc4be llvm::sys::RunSignalHandlers() (./mlir-opt+0x10884be)
 #2 0x00005ed14c5bf3a8 SignalHandler(int) Signals.cpp:0:0
 #3 0x0000754d8cf4e520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #4 0x0000754d8cfa29fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
 #5 0x0000754d8cf4e476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
 #6 0x0000754d8cf347f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
 #7 0x0000754d8cf3471b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
 #8 0x0000754d8cf45e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
 #9 0x00005ed151965baa (anonymous namespace)::DialectReader::readAPIntWithKnownWidth(unsigned int) BytecodeReader.cpp:0:0
#10 0x00005ed14f9b300f (anonymous namespace)::BuiltinDialectBytecodeInterface::readAttribute(mlir::DialectBytecodeReader&) const BuiltinDialectBytecode.cpp:0:0
#11 0x00005ed1519663e4 (anonymous namespace)::AttrTypeReader::resolveAttribute(unsigned long) BytecodeReader.cpp:0:0
#12 0x00005ed151965777 (anonymous namespace)::DialectReader::readAttribute(mlir::Attribute&) BytecodeReader.cpp:0:0
#13 0x00005ed14c6784f1 llvm::LogicalResult mlir::DialectBytecodeReader::readAttribute<mlir::IntegerAttr>(mlir::IntegerAttr&) (./mlir-opt+0x11444f1)
#14 0x00005ed14eb65529 mlir::detail::BytecodeOpInterfaceInterfaceTraits::Model<mlir::tosa::ReduceAllOp>::readProperties(mlir::DialectBytecodeReader&, mlir::OperationState&) (./mlir-opt+0x3631529)
#15 0x00005ed1519630c8 mlir::BytecodeReader::Impl::parseRegions(std::vector<mlir::BytecodeReader::Impl::RegionReadState, std::allocator<mlir::BytecodeReader::Impl::RegionReadState>>&, mlir::BytecodeReader::Impl::RegionReadState&) (./mlir-opt+0x642f0c8)
#16 0x00005ed15195eadb mlir::BytecodeReader::Impl::parseIRSection(llvm::ArrayRef<unsigned char>, mlir::Block*) (./mlir-opt+0x642aadb)
#17 0x00005ed15195bf3d mlir::BytecodeReader::Impl::read(mlir::Block*, llvm::function_ref<bool (mlir::Operation*)>) (./mlir-opt+0x6427f3d)
#18 0x00005ed1519648be readBytecodeFileImpl(llvm::MemoryBufferRef, mlir::Block*, mlir::ParserConfig const&, std::shared_ptr<llvm::SourceMgr> const&) BytecodeReader.cpp:0:0
#19 0x00005ed15196474e mlir::readBytecodeFile(llvm::MemoryBufferRef, mlir::Block*, mlir::ParserConfig const&) (./mlir-opt+0x643074e)
#20 0x00005ed14f88c2ef mlir::parseSourceFile(llvm::SourceMgr const&, mlir::Block*, mlir::ParserConfig const&, mlir::LocationAttr*) (./mlir-opt+0x43582ef)
#21 0x00005ed14f88c988 mlir::parseSourceString(llvm::StringRef, mlir::Block*, mlir::ParserConfig const&, llvm::StringRef, mlir::LocationAttr*) (./mlir-opt+0x4358988)
#22 0x00005ed14f75de74 (anonymous namespace)::TestBytecodeRoundtripPass::doRoundtripWithConfigs(mlir::Operation*, mlir::BytecodeWriterConfig const&, mlir::ParserConfig const&) TestBytecodeRoundtrip.cpp:0:0
#23 0x00005ed14f75bcb0 (anonymous namespace)::TestBytecodeRoundtripPass::runOnOperation() TestBytecodeRoundtrip.cpp:0:0
#24 0x00005ed14f88f3bf mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (./mlir-opt+0x435b3bf)
#25 0x00005ed14f88fba2 mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) (./mlir-opt+0x435bba2)
#26 0x00005ed14f89234e mlir::PassManager::run(mlir::Operation*) (./mlir-opt+0x435e34e)
#27 0x00005ed14f88ae6b performActions(llvm::raw_ostream&, std::shared_ptr<llvm::SourceMgr> const&, mlir::MLIRContext*, mlir::MlirOptMainConfig const&) MlirOptMain.cpp:0:0
#28 0x00005ed14f88aacb 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
#29 0x00005ed14f933df5 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)
#30 0x00005ed14f8859b2 mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&) (./mlir-opt+0x43519b2)
#31 0x00005ed14f885c63 mlir::MlirOptMain(int, char**, llvm::StringRef, llvm::StringRef, mlir::DialectRegistry&) (./mlir-opt+0x4351c63)
#32 0x00005ed14f885e72 mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&) (./mlir-opt+0x4351e72)
#33 0x00005ed14c59dc27 main (./mlir-opt+0x1069c27)
#34 0x0000754d8cf35d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#35 0x0000754d8cf35e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#36 0x00005ed14c59d795 _start (./mlir-opt+0x1069795)
Aborted (core dumped)
```
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzcWd1u47oRfhrmhoghkfrjRS4cZ40G3SBBEvRcGqQ0stnIpEtSe5I-fUFJtn5iJ3FOT4t2sbFlUZz55psZzlDk1sq1ArhC8TWKby547TbaXL1Ky9U6uBC6eLt6BuuwVjjX2610iM7xxrmdRXSOyBKR5Vq6TS1mud4isqyqX_uvy53Rf4fcIbLsppIlZ1lG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