<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/68948>68948</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[mlir] --ownership-based-buffer-deallocation crashed with assertion failure "Value must already have been registered in the ownership map"
</td>
</tr>
<tr>
<th>Labels</th>
<td>
mlir
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
wangzhiyingh
</td>
</tr>
</table>
<pre>
git version: eb601430d3d7f45c30ef8d793a45cbcedf910577
system: `Ubuntu 20.04.6 LTS (Focal Fossa)`
reproduced with:: `mlir-opt --ownership-based-buffer-deallocation a.mlir`
a.mlir:
```
func.func private @func1() -> memref<?x?x?xf16> {
%15 = tensor.empty() : tensor<15x2x5xf16>
%cast = tensor.cast %15 : tensor<15x2x5xf16> to tensor<?x?x?xf16>
%16 = bufferization.to_memref %cast : memref<?x?x?xf16>
return %16 : memref<?x?x?xf16>
}
```
trace:
```
mlir-opt: /data/bin/llvm-project/mlir/lib/Dialect/Bufferization/IR/BufferDeallocationOpInterface.cpp:139: std::pair<mlir::Value, mlir::Value> mlir::bufferization::DeallocationState::getMemrefWithUniqueOwnership(mlir::OpBuilder&, mlir::Value, mlir::Block*): Assertion `iter != ownershipMap.end() && "Value must already have been registered in the ownership map"' 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/bin/llvm-project/build/bin/mlir-opt --ownership-based-buffer-deallocation a.mlir
#0 0x0000557a1a69993f llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/data/bin/llvm-project/build/bin/mlir-opt+0x15a693f)
#1 0x0000557a1a6969d4 SignalHandler(int) Signals.cpp:0:0
#2 0x00007ffa917f0420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
#3 0x00007ffa912db00b raise (/lib/x86_64-linux-gnu/libc.so.6+0x4300b)
#4 0x00007ffa912ba859 abort (/lib/x86_64-linux-gnu/libc.so.6+0x22859)
#5 0x00007ffa912ba729 (/lib/x86_64-linux-gnu/libc.so.6+0x22729)
#6 0x00007ffa912cbfd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)
#7 0x0000557a1aaf4be5 mlir::bufferization::DeallocationState::getMemrefWithUniqueOwnership(mlir::OpBuilder&, mlir::Value, mlir::Block*) (/data/bin/llvm-project/build/bin/mlir-opt+0x1a01be5)
#8 0x0000557a1abb5cff (anonymous namespace)::BufferDeallocation::materializeUniqueOwnership(mlir::OpBuilder&, mlir::Value, mlir::Block*) OwnershipBasedBufferDeallocation.cpp:0:0
#9 0x0000557a1abb5e14 (anonymous namespace)::BufferDeallocation::materializeMemrefWithGuaranteedOwnership(mlir::OpBuilder&, mlir::Value, mlir::Block*) OwnershipBasedBufferDeallocation.cpp:0:0
#10 0x0000557a1abba68b (anonymous namespace)::BufferDeallocation::deallocate(mlir::Block*) OwnershipBasedBufferDeallocation.cpp:0:0
#11 0x0000557a1abbac00 mlir::WalkResult llvm::function_ref<mlir::WalkResult (mlir::Block*)>::callback_fn<(anonymous namespace)::BufferDeallocation::deallocate(mlir::FunctionOpInterface)::'lambda'(mlir::Block*)>(long, mlir::Block*) OwnershipBasedBufferDeallocation.cpp:0:0
#12 0x0000557a1abbbcce mlir::WalkResult mlir::detail::walk<mlir::ForwardDominanceIterator<false>>(mlir::Operation*, llvm::function_ref<mlir::WalkResult (mlir::Block*)>, mlir::WalkOrder) (/data/bin/llvm-project/build/bin/mlir-opt+0x1ac8cce)
#13 0x0000557a1abbc1cb mlir::bufferization::deallocateBuffersOwnershipBased(mlir::FunctionOpInterface, bool) (/data/bin/llvm-project/build/bin/mlir-opt+0x1ac91cb)
#14 0x0000557a1abbcfa3 _ZN4llvm12function_refIFN4mlir10WalkResultEPNS1_9OperationEEE11callback_fnIZNS1_6detail4walkILNS1_9WalkOrderE1ENS1_15ForwardIteratorEZN12_GLOBAL__N_136OwnershipBasedBufferDeallocationPass14runOnOperationEvEUlNS1_4func6FuncOpEE_SF_S2_EENSt9enable_ifIXaantsrSt11disjunctionIJSt7is_sameIT2_S4_ESJ_ISK_PNS1_6RegionEESJ_ISK_PNS1_5BlockEEEE5valuesrSJ_IT3_S2_E5valueEST_E4typeES4_OT1_EUlS4_E_EES2_lS4_ OwnershipBasedBufferDeallocation.cpp:0:0
#15 0x0000557a1a7d9da2 mlir::WalkResult mlir::detail::walk<mlir::ForwardIterator>(mlir::Operation*, llvm::function_ref<mlir::WalkResult (mlir::Operation*)>, mlir::WalkOrder) (/data/bin/llvm-project/build/bin/mlir-opt+0x16e6da2)
#16 0x0000557a1abb3672 (anonymous namespace)::OwnershipBasedBufferDeallocationPass::runOnOperation() OwnershipBasedBufferDeallocation.cpp:0:0
#17 0x0000557a1d15115e mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (/data/bin/llvm-project/build/bin/mlir-opt+0x405e15e)
#18 0x0000557a1d15163a mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) (/data/bin/llvm-project/build/bin/mlir-opt+0x405e63a)
#19 0x0000557a1d151e64 mlir::PassManager::run(mlir::Operation*) (/data/bin/llvm-project/build/bin/mlir-opt+0x405ee64)
#20 0x0000557a1d14272b performActions(llvm::raw_ostream&, std::shared_ptr<llvm::SourceMgr> const&, mlir::MLIRContext*, mlir::MlirOptMainConfig const&) MlirOptMain.cpp:0:0
#21 0x0000557a1d143be4 processBuffer(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::MlirOptMainConfig const&, mlir::DialectRegistry&, llvm::ThreadPool*) MlirOptMain.cpp:0:0
#22 0x0000557a1d143d94 mlir::LogicalResult llvm::function_ref<mlir::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
#23 0x0000557a1d2406a4 mlir::splitAndProcessBuffer(std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::function_ref<mlir::LogicalResult (std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&)>, llvm::raw_ostream&, bool, bool) (/data/bin/llvm-project/build/bin/mlir-opt+0x414d6a4)
#24 0x0000557a1d13d067 mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&) (/data/bin/llvm-project/build/bin/mlir-opt+0x404a067)
#25 0x0000557a1d1440bb mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&) (/data/bin/llvm-project/build/bin/mlir-opt+0x40510bb)
#26 0x0000557a1a5d24ab main (/data/bin/llvm-project/build/bin/mlir-opt+0x14df4ab)
#27 0x00007ffa912bc083 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24083)
#28 0x0000557a1a66a2ee _start (/data/bin/llvm-project/build/bin/mlir-opt+0x15772ee)
Aborted (core dumped)
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzcWl1z27iS_TX0C8oqEPx-8INsU7OatWNX5OxszQurSTQlTCiQC4CJPb9-CyQlkbKdaGLPndybilUiQBz06T4NogmB1mItES-c4NIJr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