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

    <tr>
        <th>Summary</th>
        <td>
            [MLIR]-test-print-topological-sort triggers Assertion Failure `isa<To>(Val) && "cast<Ty>() argument of incompatible type!"'
        </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: https://github.com/llvm/llvm-project/commit/6548b6354d1d990e1c98736f5e7c3de876bedc8e
steps to reproduce:
```
mlir-opt test.mlir --test-print-topological-sort
```
test case:
```
module {
 func.func @test_reverse(%arg0: tensor<13x21x3xf32>) -> tensor<13x21x3xf32> {
    %0 = tosa.reverse %arg0 {axis = 0 : i32} : (tensor<13x21x3xf32>) -> tensor<13x21x3xf32>
    return %0 : tensor<13x21x3xf32>
 }
}
```
crash trace:
```
mlir-opt: /home/workdir/llvm-project-19/llvm/include/llvm/Support/Casting.h:578: decltype(auto) llvm::cast(From *) [To = mlir::SymbolOpInterface, From = mlir::Operation]: Assertion `isa<To>(Val) && "cast<Ty>() argument of incompatible type!"' 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/test.mlir --test-print-topological-sort
 #0 0x0000568cfb1243b8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (./mlir-opt+0x10723b8)
 #1 0x0000568cfb121ede llvm::sys::RunSignalHandlers() (./mlir-opt+0x106fede)
 #2 0x0000568cfb124dc8 SignalHandler(int) Signals.cpp:0:0
 #3 0x00007273270f5520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #4 0x00007273271499fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
 #5 0x00007273270f5476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
 #6 0x00007273270db7f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
 #7 0x00007273270db71b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
 #8 0x00007273270ece96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
 #9 0x0000568cfd7c6e0f decltype(auto) llvm::cast<mlir::SymbolOpInterface, mlir::Operation>(mlir::Operation*) (./mlir-opt+0x3714e0f)
#10 0x0000568cfde54e9d (anonymous namespace)::TestTopologicalSortPass::runOnOperation() TestSlice.cpp:0:0
#11 0x0000568cfe3a06df mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (./mlir-opt+0x42ee6df)
#12 0x0000568cfe3a0ec2 mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) (./mlir-opt+0x42eeec2)
#13 0x0000568cfe3a366e mlir::PassManager::run(mlir::Operation*) (./mlir-opt+0x42f166e)
#14 0x0000568cfe39c192 performActions(llvm::raw_ostream&, std::shared_ptr<llvm::SourceMgr> const&, mlir::MLIRContext*, mlir::MlirOptMainConfig const&) MlirOptMain.cpp:0:0
#15 0x0000568cfe39bdfb 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
#16 0x0000568cfe445ae5 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+0x4393ae5)
#17 0x0000568cfe396ff2 mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&) (./mlir-opt+0x42e4ff2)
#18 0x0000568cfe3972a3 mlir::MlirOptMain(int, char**, llvm::StringRef, llvm::StringRef, mlir::DialectRegistry&) (./mlir-opt+0x42e52a3)
#19 0x0000568cfe3974b2 mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&) (./mlir-opt+0x42e54b2)
#20 0x0000568cfb1035d7 main (./mlir-opt+0x10515d7)
#21 0x00007273270dcd90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#22 0x00007273270dce40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#23 0x0000568cfb103145 _start (./mlir-opt+0x1051145)
Aborted (core dumped)
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzcWFtv47oR_jX0C2FDInV98IPXidEFTpAgCfpqUORIZpcmVZLa4_z7gpJjW46drBc9LdrF7loShzPfNzdemHOy0QBzlH5D6d2EdX5j7HwnHdNNNKmMeJu_gvPYaMzNdis9ogu88b51iC4QWSGyaqTfdNWMmy0iK6V-vv9MW2v-AdwjstpPJassTYoqo2kiYlGWEcS8LHKa1SnknAoo8qwCwQtA0R2KFs5D67A32EJrjeg4BKP9EMqi_d_-dauknZrWYw_Oz8Ibnk7D87S1UvupN61RppGcqakz1l9UEuQxZ-66FSM6BRjl34Z3XHeaz8J_GCVRmL628BOsA0QKRFJmmyj4y4N2xiK6jOmOxDu6qylB9B6REk8Rvb82fmIIY4xIGmFE77A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