<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/108366>108366</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[mlir] -sroa crashes in LLVMMemorySlot.cpp:431: Type getTypeAtIndex(const DestructurableMemorySlot &, Attribute): Assertion `!subelementIndexMap->empty()' failed.
</td>
</tr>
<tr>
<th>Labels</th>
<td>
mlir
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
axeabc
</td>
</tr>
</table>
<pre>
git version: 8168088f0a9015b
system: `Ubuntu 18.04.6 LTS`
reproduce with: `mlir-opt -sroa a.mlir`
a.mlir:
```
module {
llvm.func private @f() ->!llvm.struct<()> attributes {llang.emit_c_interface, sym_visibility = "private", sym = "my_func"} {
%0 = llvm.mlir.constant(1 : index) : i64
%1 = llvm.alloca %0 x!llvm.struct<()> : (i64) ->!llvm.ptr
llvm.call @_mlir_ciface_my_func(%1) : (!llvm.ptr) -> ()
%2 = llvm.load %1 :!llvm.ptr ->!llvm.struct<()>
llvm.return %2 :!llvm.struct<()>
}
llvm.func @_mlir_ciface_my_func(!llvm.ptr) attributes {llvm.emit_c_interface, sym_visibility = "private", sym = "my_func"}
}
```
stack trace:
```
mlir-opt: /data/szy/MLIR/llvm-release/llvm-project/mlir/lib/Dialect/LLVMIR/IR/LLVMMemorySlot.cpp:431: Type getTypeAtIndex(const DestructurableMemorySlot &, Attribute): Assertion `!subelementIndexMap->empty()' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0. Program arguments: /data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt -sroa a.mlir
#0 0x000055bb6d92d2c8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x10dc2c8)
#1 0x000055bb6d92adde llvm::sys::RunSignalHandlers() (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x10d9dde)
#2 0x000055bb6d92dc5d SignalHandler(int) Signals.cpp:0:0
#3 0x00007f6f2bb93420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
#4 0x00007f6f2b1d000b raise /build/glibc-LcI20x/glibc-2.31/signal/../sysdeps/unix/sysv/linux/raise.c:51:1
#5 0x00007f6f2b1af859 abort /build/glibc-LcI20x/glibc-2.31/stdlib/abort.c:81:7
#6 0x00007f6f2b1af729 get_sysdep_segment_value /build/glibc-LcI20x/glibc-2.31/intl/loadmsgcat.c:509:8
#7 0x00007f6f2b1af729 _nl_load_domain /build/glibc-LcI20x/glibc-2.31/intl/loadmsgcat.c:970:34
#8 0x00007f6f2b1c0fd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)
#9 0x000055bb6ed7cef3 (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x252bef3)
#10 0x000055bb6ed7cd0e mlir::LLVM::LoadOp::canRewire(mlir::DestructurableMemorySlot const&, llvm::SmallPtrSetImpl<mlir::Attribute>&, llvm::SmallVectorImpl<mlir::MemorySlot>&, mlir::DataLayout const&) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x252bd0e)
#11 0x000055bb6ec81b51 mlir::detail::DestructurableAccessorOpInterfaceInterfaceTraits::Model<mlir::LLVM::LoadOp>::canRewire(mlir::detail::DestructurableAccessorOpInterfaceInterfaceTraits::Concept const*, mlir::Operation*, mlir::DestructurableMemorySlot const&, llvm::SmallPtrSetImpl<mlir::Attribute>&, llvm::SmallVectorImpl<mlir::MemorySlot>&, mlir::DataLayout const&) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x2430b51)
#12 0x000055bb70a90b53 mlir::tryToDestructureMemorySlots(llvm::ArrayRef<mlir::DestructurableAllocationOpInterface>, mlir::OpBuilder&, mlir::DataLayout const&, mlir::SROAStatistics) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x423fb53)
#13 0x000055bb70a948d8 (anonymous namespace)::SROA::runOnOperation() SROA.cpp:0:0
#14 0x000055bb70a54156 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x4203156)
#15 0x000055bb70a54ac0 mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x4203ac0)
#16 0x000055bb70a57102 mlir::PassManager::run(mlir::Operation*) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x4206102)
#17 0x000055bb70a4f931 performActions(llvm::raw_ostream&, std::shared_ptr<llvm::SourceMgr> const&, mlir::MLIRContext*, mlir::MlirOptMainConfig const&) MlirOptMain.cpp:0:0
#18 0x000055bb70a4f58b 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
#19 0x000055bb70afbf25 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) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x42aaf25)
#20 0x000055bb70a4a9b5 mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x41f99b5)
#21 0x000055bb70a4ac5f mlir::MlirOptMain(int, char**, llvm::StringRef, llvm::StringRef, mlir::DialectRegistry&) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x41f9c5f)
#22 0x000055bb70a4af8e mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x41f9f8e)
#23 0x000055bb6d90df07 main (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x10bcf07)
#24 0x00007f6f2b1b1083 __libc_start_main /build/glibc-LcI20x/glibc-2.31/csu/../csu/libc-start.c:342:3
#25 0x000055bb6d90da8e _start (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x10bca8e)
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsWVtv5Cj2_zTkBaWE8aXshzxUJyn9W0qUKMl_Xi0M2GEHgxdwOrWffgV2le3KpbtnunY0q5W6U8Zczu_8zoVjINaKRnF-AdIvIL06I7171uaCvHJS0bNKs91FIxx84cYKrUC8gXmU5SjPa0QKFKUVQFcAbYa_dmcdb_0gkKH_r3rlehjlK5SsMnjz9AgyNB9teGc06ymH34R7Hme1Uphz3Tl4bo0mkKz8i6OJ48t4bPre8A8O7VazXnII1l-GNpTypV3VvaKwM-KFOA5BgmqAc4ALeA7ia4CjMMY601MH4suhD8TXkDhnRNU7bv2CUhLVrHgrXElLoRw3NaEc4Etod235IqyohBRuB0F8BQHGozyA8Thm39HuSg_Id6yvZlAhhACnKAwLkLymK6qVdUQ5gPMIeqKEYvzVow-NLFnMjqbZREpNybDk6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