<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/114765>114765</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [MLIR]-test-ir-visitors triggers Assertion Failure `use_empty() && "Cannot destroy a value that still has uses!"'
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            mlir
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          xisang0
      </td>
    </tr>
</table>

<pre>
    Test on commit: [c3edeaa61bf0e7faed6c26f693b4fcd9102ba1ec](url)
steps to reproduce:
```
mlir-opt test7.mlir --test-ir-visitors
```
test case:
```
module {
  func.func @branchCondProp(%arg0: i1) {
 llvm.cond_br %arg0, ^bb1, ^bb2
  ^bb1: "test.consumer1"(%arg0) : (i1) -> ()
  ^bb2: "test.consumer2"(%arg0) : (i1) -> ()
    return
 }
}
```
crash trace:
```
mlir-opt: /home/workdir/llvm-project-19/mlir/include/mlir/IR/UseDefLists.h:198: mlir::IRObjectWithUseList<mlir::OpOperand>::~IRObjectWithUseList() [OperandType = mlir::OpOperand]: Assertion `use_empty() && "Cannot destroy a value that still has uses!"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.      Program arguments: ./mlir-opt /home/workdir/test7.mlir --test-ir-visitors
 #0 0x00005dee86b4c228 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (./mlir-opt+0x1062228)
 #1 0x00005dee86b49d4e llvm::sys::RunSignalHandlers() (./mlir-opt+0x105fd4e)
 #2 0x00005dee86b4cc38 SignalHandler(int) Signals.cpp:0:0
 #3 0x00007043ac723520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #4 0x00007043ac7779fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
 #5 0x00007043ac723476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
 #6 0x00007043ac7097f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
 #7 0x00007043ac70971b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
 #8 0x00007043ac71ae96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
 #9 0x00005dee89e54727 mlir::Block::~Block() (./mlir-opt+0x436a727)
#10 0x00005dee89e54b4d mlir::Block::erase() (./mlir-opt+0x436ab4d)
#11 0x00005dee894291be void mlir::detail::walk<mlir::ForwardIterator>(mlir::Operation*, llvm::function_ref<void (mlir::Block*)>, mlir::WalkOrder) (./mlir-opt+0x393f1be)
#12 0x00005dee894291a3 void mlir::detail::walk<mlir::ForwardIterator>(mlir::Operation*, llvm::function_ref<void (mlir::Block*)>, mlir::WalkOrder) (./mlir-opt+0x393f1a3)
#13 0x00005dee89c63519 (anonymous namespace)::TestIRVisitorsPass::runOnOperation() TestVisitors.cpp:0:0
#14 0x00005dee89d74e9f mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (./mlir-opt+0x428ae9f)
#15 0x00005dee89d75682 mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) (./mlir-opt+0x428b682)
#16 0x00005dee89d77e2e mlir::PassManager::run(mlir::Operation*) (./mlir-opt+0x428de2e)
#17 0x00005dee89d70952 performActions(llvm::raw_ostream&, std::shared_ptr<llvm::SourceMgr> const&, mlir::MLIRContext*, mlir::MlirOptMainConfig const&) MlirOptMain.cpp:0:0
#18 0x00005dee89d705bb 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 0x00005dee89e1a2a5 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) (./mlir-opt+0x43302a5)
#20 0x00005dee89d6b7b2 mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&) (./mlir-opt+0x42817b2)
#21 0x00005dee89d6ba63 mlir::MlirOptMain(int, char**, llvm::StringRef, llvm::StringRef, mlir::DialectRegistry&) (./mlir-opt+0x4281a63)
#22 0x00005dee89d6bc72 mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&) (./mlir-opt+0x4281c72)
#23 0x00005dee86b2b477 main (./mlir-opt+0x1041477)
#24 0x00007043ac70ad90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#25 0x00007043ac70ae40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#26 0x00005dee86b2afe5 _start (./mlir-opt+0x1040fe5)
Aborted (core dumped)
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzcWN1u47oRfhr6hrBBUX_WhS8cO0YDbJAgu6fn0qDIkcyGJlWS2k1u-uwFJceRHDt7fHDaorvYJJJIfjPzzQ_JYc7JWgMsUHqD0vWEtX5n7OJFOqZrMimNeF18A-ex0Zib_V56FC8xSm94DAIYy6KyIpBXDETGaVZlRVwmFRdFRGjJIuAoXSM6b61CtEBkjcjSeWgc9gZba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