<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/131323>131323</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[MLIR] crash when initializing complex tensor using dense<scalar>
</td>
</tr>
<tr>
<th>Labels</th>
<td>
mlir
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
zitongzhoueric
</td>
</tr>
</table>
<pre>
To reproduce: https://godbolt.org/z/EKeYbMnab
The program causing the crash:
```
func.func @test_constant_complex_tensor_with_scalar_initialization() -> () {
%0 = arith.constant dense<1> : tensor<complex<i32>>
return
}
```
It appears that the use of `dense<1>` for initializing a complex tensor triggered the segfault. The type mismatch should be checked and invalidated.
Stack dump
```
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0. Program arguments: /opt/compiler-explorer/mlir-trunk/bin/mlir-opt -o /app/example.out.mlir <source>
#0 0x00000000018efff8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/mlir-trunk/bin/mlir-opt+0x18efff8)
#1 0x00000000018ed934 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
#2 0x00007145a4042520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
#3 0x00007145a41a7ca5 (/lib/x86_64-linux-gnu/libc.so.6+0x1a7ca5)
#4 0x00000000041b6f15 mlir::DenseElementsAttr::ComplexIntElementIterator::operator*() const (/opt/compiler-explorer/mlir-trunk/bin/mlir-opt+0x41b6f15)
#5 0x000000000417c8d1 void llvm::function_ref<void (unsigned int)>::callback_fn<mlir::AsmPrinter::Impl::printDenseIntOrFPElementsAttr(mlir::DenseIntOrFPElementsAttr, bool)::'lambda'(unsigned int)>(long, unsigned int) AsmPrinter.cpp:0:0
#6 0x000000000417f307 printDenseElementsAttrImpl(bool, mlir::ShapedType, llvm::raw_ostream&, llvm::function_ref<void (unsigned int)>) AsmPrinter.cpp:0:0
#7 0x000000000418abee mlir::AsmPrinter::Impl::printDenseIntOrFPElementsAttr(mlir::DenseIntOrFPElementsAttr, bool) (/opt/compiler-explorer/mlir-trunk/bin/mlir-opt+0x418abee)
#8 0x0000000004193cb9 mlir::AsmPrinter::Impl::printAttributeImpl(mlir::Attribute, mlir::AsmPrinter::Impl::AttrTypeElision) (/opt/compiler-explorer/mlir-trunk/bin/mlir-opt+0x4193cb9)
#9 0x0000000001afcbb7 mlir::arith::ConstantOp::print(mlir::OpAsmPrinter&) (/opt/compiler-explorer/mlir-trunk/bin/mlir-opt+0x1afcbb7)
#10 0x0000000001b7430f void llvm::detail::UniqueFunctionBase<void, mlir::Operation*, mlir::OpAsmPrinter&, llvm::StringRef>::CallImpl<mlir::Op<mlir::arith::ConstantOp, mlir::OpTrait::ZeroRegions, mlir::OpTrait::OneResult, mlir::OpTrait::OneTypedResult<mlir::Type>::Impl, mlir::OpTrait::ZeroSuccessors, mlir::OpTrait::ZeroOperands, mlir::OpTrait::OpInvariants, mlir::BytecodeOpInterface::Trait, mlir::OpTrait::ConstantLike, mlir::ConditionallySpeculatable::Trait, mlir::OpTrait::AlwaysSpeculatableImplTrait, mlir::MemoryEffectOpInterface::Trait, mlir::OpAsmOpInterface::Trait, mlir::InferIntRangeInterface::Trait, mlir::InferTypeOpInterface::Trait>::getPrintAssemblyFn()::'lambda'(mlir::Operation*, mlir::OpAsmPrinter&, llvm::StringRef) const>(void*, mlir::Operation*, mlir::OpAsmPrinter&, llvm::StringRef) (/opt/compiler-explorer/mlir-trunk/bin/mlir-opt+0x1b7430f)
#11 0x0000000001b97d50 mlir::RegisteredOperationName::Model<mlir::arith::ConstantOp>::printAssembly(mlir::Operation*, mlir::OpAsmPrinter&, llvm::StringRef) (/opt/compiler-explorer/mlir-trunk/bin/mlir-opt+0x1b97d50)
#12 0x0000000004197c8a (anonymous namespace)::OperationPrinter::printCustomOrGenericOp(mlir::Operation*) AsmPrinter.cpp:0:0
#13 0x00000000041981b5 (anonymous namespace)::OperationPrinter::printFullOpWithIndentAndLoc(mlir::Operation*) AsmPrinter.cpp:0:0
#14 0x0000000004198833 (anonymous namespace)::OperationPrinter::print(mlir::Block*, bool, bool) AsmPrinter.cpp:0:0
#15 0x0000000004198f19 (anonymous namespace)::OperationPrinter::printRegion(mlir::Region&, bool, bool, bool) (.part.0) AsmPrinter.cpp:0:0
#16 0x00000000076e00bf mlir::function_interface_impl::printFunctionOp(mlir::OpAsmPrinter&, mlir::FunctionOpInterface, bool, llvm::StringRef, mlir::StringAttr, mlir::StringAttr) (/opt/compiler-explorer/mlir-trunk/bin/mlir-opt+0x76e00bf)
#17 0x0000000001f0924e void llvm::detail::UniqueFunctionBase<void, mlir::Operation*, mlir::OpAsmPrinter&, llvm::StringRef>::CallImpl<mlir::Op<mlir::func::FuncOp, mlir::OpTrait::OneRegion, mlir::OpTrait::ZeroResults, mlir::OpTrait::ZeroSuccessors, mlir::OpTrait::ZeroOperands, mlir::OpTrait::OpInvariants, mlir::BytecodeOpInterface::Trait, mlir::OpTrait::AffineScope, mlir::OpTrait::AutomaticAllocationScope, mlir::SymbolOpInterface::Trait, mlir::CallableOpInterface::Trait, mlir::FunctionOpInterface::Trait, mlir::OpTrait::IsIsolatedFromAbove, mlir::OpAsmOpInterface::Trait>::getPrintAssemblyFn()::'lambda'(mlir::Operation*, mlir::OpAsmPrinter&, llvm::StringRef) const>(void*, mlir::Operation*, mlir::OpAsmPrinter&, llvm::StringRef) (/opt/compiler-explorer/mlir-trunk/bin/mlir-opt+0x1f0924e)
#18 0x0000000001efdd71 mlir::RegisteredOperationName::Model<mlir::func::FuncOp>::printAssembly(mlir::Operation*, mlir::OpAsmPrinter&, llvm::StringRef) (/opt/compiler-explorer/mlir-trunk/bin/mlir-opt+0x1efdd71)
#19 0x0000000004197c8a (anonymous namespace)::OperationPrinter::printCustomOrGenericOp(mlir::Operation*) AsmPrinter.cpp:0:0
#20 0x00000000041981b5 (anonymous namespace)::OperationPrinter::printFullOpWithIndentAndLoc(mlir::Operation*) AsmPrinter.cpp:0:0
#21 0x0000000004198833 (anonymous namespace)::OperationPrinter::print(mlir::Block*, bool, bool) AsmPrinter.cpp:0:0
#22 0x0000000004198f19 (anonymous namespace)::OperationPrinter::printRegion(mlir::Region&, bool, bool, bool) (.part.0) AsmPrinter.cpp:0:0
#23 0x00000000041e3ddb mlir::ModuleOp::print(mlir::OpAsmPrinter&) (/opt/compiler-explorer/mlir-trunk/bin/mlir-opt+0x41e3ddb)
#24 0x00000000041e3e4f void llvm::detail::UniqueFunctionBase<void, mlir::Operation*, mlir::OpAsmPrinter&, llvm::StringRef>::CallImpl<mlir::Op<mlir::ModuleOp, mlir::OpTrait::OneRegion, mlir::OpTrait::ZeroResults, mlir::OpTrait::ZeroSuccessors, mlir::OpTrait::ZeroOperands, mlir::OpTrait::NoRegionArguments, mlir::OpTrait::NoTerminator, mlir::OpTrait::SingleBlock, mlir::OpTrait::OpInvariants, mlir::BytecodeOpInterface::Trait, mlir::OpTrait::AffineScope, mlir::OpTrait::IsIsolatedFromAbove, mlir::OpTrait::SymbolTable, mlir::SymbolOpInterface::Trait, mlir::OpAsmOpInterface::Trait, mlir::RegionKindInterface::Trait, mlir::OpTrait::HasOnlyGraphRegion>::getPrintAssemblyFn()::'lambda'(mlir::Operation*, mlir::OpAsmPrinter&, llvm::StringRef) const>(void*, mlir::Operation*, mlir::OpAsmPrinter&, llvm::StringRef) (/opt/compiler-explorer/mlir-trunk/bin/mlir-opt+0x41e3e4f)
#25 0x00000000041de221 mlir::RegisteredOperationName::Model<mlir::ModuleOp>::printAssembly(mlir::Operation*, mlir::OpAsmPrinter&, llvm::StringRef) (/opt/compiler-explorer/mlir-trunk/bin/mlir-opt+0x41de221)
#26 0x0000000004197c8a (anonymous namespace)::OperationPrinter::printCustomOrGenericOp(mlir::Operation*) AsmPrinter.cpp:0:0
#27 0x00000000041981b5 (anonymous namespace)::OperationPrinter::printFullOpWithIndentAndLoc(mlir::Operation*) AsmPrinter.cpp:0:0
#28 0x000000000419d406 mlir::Operation::print(llvm::raw_ostream&, mlir::AsmState&) (/opt/compiler-explorer/mlir-trunk/bin/mlir-opt+0x419d406)
#29 0x00000000040695ef performActions(llvm::raw_ostream&, std::shared_ptr<llvm::SourceMgr> const&, mlir::MLIRContext*, mlir::MlirOptMainConfig const&) MlirOptMain.cpp:0:0
#30 0x0000000004069ccb processBuffer(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::MlirOptMainConfig const&, mlir::DialectRegistry&, llvm::ThreadPoolInterface*) MlirOptMain.cpp:0:0
#31 0x0000000004069df3 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&)::'lambda'(std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&)>(long, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&) MlirOptMain.cpp:0:0
#32 0x000000000416832e 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) (/opt/compiler-explorer/mlir-trunk/bin/mlir-opt+0x416832e)
#33 0x0000000004062115 mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&) (/opt/compiler-explorer/mlir-trunk/bin/mlir-opt+0x4062115)
#34 0x0000000004069f20 mlir::MlirOptMain(int, char**, llvm::StringRef, llvm::StringRef, mlir::DialectRegistry&) (/opt/compiler-explorer/mlir-trunk/bin/mlir-opt+0x4069f20)
#35 0x000000000406a3af mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&) (/opt/compiler-explorer/mlir-trunk/bin/mlir-opt+0x406a3af)
#36 0x000000000180064f main (/opt/compiler-explorer/mlir-trunk/bin/mlir-opt+0x180064f)
#37 0x00007145a4029d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#38 0x00007145a4029e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#39 0x00000000018ca5d5 _start (/opt/compiler-explorer/mlir-trunk/bin/mlir-opt+0x18ca5d5)
Program terminated with signal: SIGSEGV
Compiler returned: 139
```
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzsW1tz27gZ_TXwC8YaEqRE6cEPtGxlNRuvM5HbTvuiAQmQQgMCLAAmVn59ByBlXizJSqxN7c7uZHclEpdzvhsOqS9Ya5YLSq_A-BqMby5wZTZSXX1nRor8-0ZWVLH0IpFke_UgoaKlkqRKKQhiuDGm1CCIAVoAtMglSSQ3I6lygBbfAVrc_k7_mdwJnAAvBl78sKGwVDJXuIAprjQTOTQbClOF9cYu48Vg4jV_vDirRDqy_4Eg9AzVZp1KoQ0W9kNRcvq4NlRoqdbfmNmsdYo5VmsmmGGYs-_YMCkAmgI0g5cguIXNZxBdAy-GEEKAxh4EwQ3EipnNaLc6JFRoCoK572YFMay3AcG82RcEcxYgENzaP_VaippKCcsguunygMCLlwbisqRYaWg22DjOlaZQZhBMvO5udkImFXwiYU2EYbNtgwMaxfKcKkrcSprmGa64GUFrX7MtKSyYLrBJN1BvZMUJTChMNzT9QgnEgkAmvmLOCDaUjGrPrAxOv0BSFeXAB58-3sarW6irpGAGYphUuQ0BqQw0cuh_ZjZVMkplAdCC86-7_12WSv6bpgagBdO6ohqgRYMj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