Skip to content

[mlir] arith.bitcast crashes on verify when a type is index #121397

@hatoo

Description

@hatoo

mlir-opt crashes to the code

module {
  func.func @f() {
    %x = arith.constant 0 : i64
    %xi64 = arith.bitcast %x : i64 to index
    return
  }
}
./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

//===----------------------------------------------------------------------===//
// BitcastOp
//===----------------------------------------------------------------------===//
bool arith::BitcastOp::areCastCompatible(TypeRange inputs, TypeRange outputs) {
if (!areValidCastInputsAndOutputs(inputs, outputs))
return false;
auto srcType =
getTypeIfLikeOrMemRef<IntegerType, IndexType, FloatType>(inputs.front());
auto dstType =
getTypeIfLikeOrMemRef<IntegerType, IndexType, FloatType>(outputs.front());
if (!srcType || !dstType)
return false;
return srcType.getIntOrFloatBitWidth() == dstType.getIntOrFloatBitWidth();
}

getIntOrFloatBitWidth() requires IntegerType or FloatType but it can pass IndexType and crashes.

Metadata

Metadata

Assignees

Labels

crashPrefer [crash-on-valid] or [crash-on-invalid]mlir:arith

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions