<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/121397>121397</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[mlir] `arith.bitcast` crashes on verify when a type is `index`
</td>
</tr>
<tr>
<th>Labels</th>
<td>
mlir
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
hatoo
</td>
</tr>
</table>
<pre>
mlir-opt crashes to the code
```mlir
module {
func.func @f() {
%x = arith.constant 0 : i64
%xi64 = arith.bitcast %x : i64 to index
return
}
}
```
```bash
./build/bin/mlir-opt ~/tmp/report.mlir
mlir-opt: /home/hatoo/llvm-project/mlir/lib/IR/Types.cpp:134: unsigned int mlir::Type::getIntOrFloatBitWidth() const: Assertion `isIntOrFloat() && "only integers and floats have a bitwidth"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0. Program arguments: ./build/bin/mlir-opt /home/hatoo/tmp/report.mlir
#0 0x00005633802829c8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (./build/bin/mlir-opt+0x14fa9c8)
#1 0x000056338028059e llvm::sys::RunSignalHandlers() (./build/bin/mlir-opt+0x14f859e)
#2 0x00005633802833a8 SignalHandler(int) Signals.cpp:0:0
#3 0x00007f117e8e7320 (/lib/x86_64-linux-gnu/libc.so.6+0x45320)
#4 0x00007f117e940b1c __pthread_kill_implementation ./nptl/pthread_kill.c:44:76
#5 0x00007f117e940b1c __pthread_kill_internal ./nptl/pthread_kill.c:78:10
#6 0x00007f117e940b1c pthread_kill ./nptl/pthread_kill.c:89:10
#7 0x00007f117e8e726e raise ./signal/../sysdeps/posix/raise.c:27:6
#8 0x00007f117e8ca8ff abort ./stdlib/abort.c:81:7
#9 0x00007f117e8ca81b _nl_load_domain ./intl/loadmsgcat.c:1177:9
#10 0x00007f117e8dd507 (/lib/x86_64-linux-gnu/libc.so.6+0x3b507)
#11 0x00005633836f2da2 mlir::Type::getIntOrFloatBitWidth() const (./build/bin/mlir-opt+0x496ada2)
#12 0x00005633804bf9ce mlir::arith::BitcastOp::areCastCompatible(mlir::TypeRange, mlir::TypeRange) (./build/bin/mlir-opt+0x17379ce)
#13 0x0000563383517a95 mlir::impl::verifyCastInterfaceOp(mlir::Operation*) (./build/bin/mlir-opt+0x478fa95)
#14 0x0000563380541fe1 llvm::LogicalResult mlir::op_definition_impl::verifyTraits<mlir::OpTrait::ZeroRegions<mlir::arith::BitcastOp>, mlir::OpTrait::OneResult<mlir::arith::BitcastOp>, mlir::OpTrait::OneTypedResult<mlir::Type>::Impl<mlir::arith::BitcastOp>, mlir::OpTrait::ZeroSuccessors<mlir::arith::BitcastOp>, mlir::OpTrait::OneOperand<mlir::arith::BitcastOp>, mlir::OpTrait::OpInvariants<mlir::arith::BitcastOp>, mlir::ConditionallySpeculatable::Trait<mlir::arith::BitcastOp>, mlir::OpTrait::AlwaysSpeculatableImplTrait<mlir::arith::BitcastOp>, mlir::MemoryEffectOpInterface::Trait<mlir::arith::BitcastOp>, mlir::OpTrait::SameOperandsAndResultShape<mlir::arith::BitcastOp>, mlir::CastOpInterface::Trait<mlir::arith::BitcastOp>, mlir::VectorUnrollOpInterface::Trait<mlir::arith::BitcastOp>, mlir::OpTrait::Elementwise<mlir::arith::BitcastOp>, mlir::OpTrait::Scalarizable<mlir::arith::BitcastOp>, mlir::OpTrait::Vectorizable<mlir::arith::BitcastOp>, mlir::OpTrait::Tensorizable<mlir::arith::BitcastOp>>(mlir::Operation*) (./build/bin/mlir-opt+0x17b9fe1)
#15 0x0000563380541ea0 mlir::Op<mlir::arith::BitcastOp, mlir::OpTrait::ZeroRegions, mlir::OpTrait::OneResult, mlir::OpTrait::OneTypedResult<mlir::Type>::Impl, mlir::OpTrait::ZeroSuccessors, mlir::OpTrait::OneOperand, mlir::OpTrait::OpInvariants, mlir::ConditionallySpeculatable::Trait, mlir::OpTrait::AlwaysSpeculatableImplTrait, mlir::MemoryEffectOpInterface::Trait, mlir::OpTrait::SameOperandsAndResultShape, mlir::CastOpInterface::Trait, mlir::VectorUnrollOpInterface::Trait, mlir::OpTrait::Elementwise, mlir::OpTrait::Scalarizable, mlir::OpTrait::Vectorizable, mlir::OpTrait::Tensorizable>::verifyInvariants(mlir::Operation*) (./build/bin/mlir-opt+0x17b9ea0)
#16 0x000056338053ff0e mlir::RegisteredOperationName::Model<mlir::arith::BitcastOp>::verifyInvariants(mlir::Operation*) (./build/bin/mlir-opt+0x17b7f0e)
#17 0x00005633836f6089 (anonymous namespace)::OperationVerifier::verifyOpAndDominance(mlir::Operation&) Verifier.cpp:0:0
#18 0x00005633836f6440 (anonymous namespace)::OperationVerifier::verifyOpAndDominance(mlir::Operation&) Verifier.cpp:0:0
#19 0x00005633836f6440 (anonymous namespace)::OperationVerifier::verifyOpAndDominance(mlir::Operation&) Verifier.cpp:0:0
#20 0x00005633836f54f6 mlir::verify(mlir::Operation*, bool) (./build/bin/mlir-opt+0x496d4f6)
#21 0x00005633866dab30 mlir::parseAsmSourceFile(llvm::SourceMgr const&, mlir::Block*, mlir::ParserConfig const&, mlir::AsmParserState*, mlir::AsmParserCodeCompleteContext*) (./build/bin/mlir-opt+0x7952b30)
#22 0x0000563383523bef mlir::parseSourceFile(std::shared_ptr<llvm::SourceMgr> const&, mlir::Block*, mlir::ParserConfig const&, mlir::LocationAttr*) (./build/bin/mlir-opt+0x479bbef)
#23 0x000056338352275e mlir::parseSourceFileForTool(std::shared_ptr<llvm::SourceMgr> const&, mlir::ParserConfig const&, bool) (./build/bin/mlir-opt+0x479a75e)
#24 0x0000563383521f71 performActions(llvm::raw_ostream&, std::shared_ptr<llvm::SourceMgr> const&, mlir::MLIRContext*, mlir::MlirOptMainConfig const&) MlirOptMain.cpp:0:0
#25 0x0000563383521cef 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
#26 0x00005633835cc7f5 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) (./build/bin/mlir-opt+0x48447f5)
#27 0x000056338351b7f5 mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&) (./build/bin/mlir-opt+0x47937f5)
#28 0x000056338351baa3 mlir::MlirOptMain(int, char**, llvm::StringRef, llvm::StringRef, mlir::DialectRegistry&) (./build/bin/mlir-opt+0x4793aa3)
#29 0x000056338351bcb2 mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&) (./build/bin/mlir-opt+0x4793cb2)
#30 0x00005633802612a7 main (./build/bin/mlir-opt+0x14d92a7)
#31 0x00007f117e8cc1ca __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:74:3
#32 0x00007f117e8cc28b call_init ./csu/../csu/libc-start.c:128:20
#33 0x00007f117e8cc28b __libc_start_main ./csu/../csu/libc-start.c:347:5
#34 0x0000563380260e15 _start (./build/bin/mlir-opt+0x14d8e15)
Aborted (core dumped)
```
It crashes in
https://github.com/llvm/llvm-project/blob/b195bb87e1a0120d8bc6f7fd7e6a7424bd664004/mlir/lib/Dialect/Arith/IR/ArithOps.cpp#L1711-L1728
`getIntOrFloatBitWidth()` requires `IntegerType` or `FloatType` but it can pass `IndexType` and crashes.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzcWllz4yra_jXkhmoXQvtFLpTF9aWq-0tX0nOmam5cCF7ZTEugA6g7mYv57VMIObac5ThLz5yZrrQtszw87woImLVyrQBOUXqG0osTNriNNqcb5rQ-qbW4P-1aaT7p3mFumN2AxU5jtwHMtQBEKv-XkfDnmyJSdVoMLWCUnyFSYdwMii_8B0YJaRAtEC0fKjFGNL3DKL7AzEi3WXCtrGPKYYJRXGGZJXvtZJbsNa2l48y6LcLY2LOTSsCd72XADUaN_VF-4ZmGzy3fA_o1sxtEqgWiy3qQrfDfUiG6fFDBPxFduq5HdGmg18YtfA32Ik8tPAtElxvdgf_yWkR02bY_uk-90X8H7iY4XyprRJdXN4guv933YBe871FcRXHiUQY1GkZgqRwee8QViivfMjytwV0pd22WrWbuTLq_SuE2k3ZHJXqUylowTmqFUUak3XXYmoFmiGYYUapVe-_HgjUYi5kSuPHtLN6wH4AZrqX7GUagiOa4YbIFsUCk-vr5srq9xHaoO-l8w2GNg3a8LTbO9dYTpktEl2vpNkO94LqbtPJYOdLaASyiy5GDVLwdBASH8_6Ha8a_O8M4-LFvHePfsRg6rzhEKrLA47-vRq8N6zAz66ED5TwD_IJdH5vskZW9FyEaE0zuCCEkzeK4ILSgJS_wKMloFHtvw8NXI5Ub6X3zZBEtdo0M-7nS1hlg3aj_c6_3YI3ieZKInpG7KGlYyb3pJj7RAR-SlvAUn5tB3cq1Yu3_MSVaMPbBAY4YskhL2A1JD4aMY1bgGTiixSRRKN66Nhn_B5R4QsmbKMqhgDymBI-kpsC4K7JVlnxqpRruPq3VECr4wupFNhJL0piSHa1kBlgmpI44Xq16tzHAxOq7bNuV7PoWvEOwMSa85Kp3LaLL_WYLjuIq8VGYZxN4egy4cmAUa1-EzQsf4lslZE_B7vd5Easo97HyQ4XSDLBh0sIIYkdLILpcjL_urYDeh1mvrbzzru5bjrA0R3G1FbyYo3JWNA1mtY_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