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

    <tr>
        <th>Summary</th>
        <td>
            [mlir] -transform-dialect-check-uses crashes
        </td>
    </tr>

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

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

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

<pre>
    git version: bc29fc937c6cb4a210f80c93c79fc6ed97c801f8

system: `Ubuntu 18.04.6 LTS`

reproduce with: `mlir-opt  -transform-dialect-check-uses a.mlir`


a.mlir:  
``` 
func.func @foo(%arg0: index, %arg1:index, %arg2 : index) {
  scf.for %i = %arg0 to %arg1 step %arg2 {
    %0 = arith.constant 0 : i32
  }
  return
}

module attributes {transform.with_named_sequence} {
  transform.named_sequence @__transform_main(%root:!transform.any_op) {
    transform.with_pdl_patterns %root :!transform.any_op {
    ^bb0(%arg0:!transform.any_op):
 pdl.pattern @match_const : benefit(1) {
        %0 = pdl.operands
 %1 = pdl.types
        %2 = pdl.operation "arith.constant"(%0 :!pdl.range<value>) -> (%1 :!pdl.range<type>)
        pdl.rewrite %2 with "transform.dialect"
      }


      sequence %arg0 :!transform.any_op failures(propagate) {
      ^bb1(%arg1:!transform.any_op):
        %0 = transform.pdl_match @match_const in %arg1 : (!transform.any_op) ->!transform.any_op
        %1 = transform.get_parent_op %0 {op_name = "scf.for"} : (!transform.any_op) ->!transform.any_op
        alternatives %1 :!transform.any_op {
        ^bb2(%arg2:!transform.any_op):
        }
 }
    }
    transform.yield
  }
}

``` 
stack trace:

``` 
mlir-opt: /data/szy/MLIR/llvm-release/llvm-project/llvm/include/llvm/Support/Casting.h:578: decltype(auto) llvm::cast(From *) [To = mlir::MemoryEffectOpInterface, 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: /data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt -transform-dialect-check-uses /data/szy/MLIR/seed/seed14/tmp.kuOGtmbIp2.mlir
 #0 0x000055be46e7d508 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x11ef508)
 #1 0x000055be46e7b01e llvm::sys::RunSignalHandlers() (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x11ed01e)
 #2 0x000055be46e7de9d SignalHandler(int) Signals.cpp:0:0
 #3 0x00007f7908752420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
 #4 0x00007f7907d8f00b raise /build/glibc-LcI20x/glibc-2.31/signal/../sysdeps/unix/sysv/linux/raise.c:51:1
 #5 0x00007f7907d6e859 abort /build/glibc-LcI20x/glibc-2.31/stdlib/abort.c:81:7
 #6 0x00007f7907d6e729 get_sysdep_segment_value /build/glibc-LcI20x/glibc-2.31/intl/loadmsgcat.c:509:8
 #7 0x00007f7907d6e729 _nl_load_domain /build/glibc-LcI20x/glibc-2.31/intl/loadmsgcat.c:970:34
 #8 0x00007f7907d7ffd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)
 #9 0x000055be4961acae void llvm::function_ref<void (mlir::Operation*)>::callback_fn<(anonymous namespace)::TransformOpMemFreeAnalysis::collectFreedValues(mlir::Operation*)::'lambda'(mlir::Operation*)>(long, mlir::Operation*) CheckUses.cpp:0:0
#10 0x000055be46f954ce void mlir::detail::walk<mlir::ForwardIterator>(mlir::Operation*, llvm::function_ref<void (mlir::Operation*)>, mlir::WalkOrder) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x13074ce)
#11 0x000055be46f954ce void mlir::detail::walk<mlir::ForwardIterator>(mlir::Operation*, llvm::function_ref<void (mlir::Operation*)>, mlir::WalkOrder) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x13074ce)
#12 0x000055be4961a20c mlir::WalkResult llvm::function_ref<mlir::WalkResult (mlir::Operation*)>::callback_fn<(anonymous namespace)::TransformOpMemFreeAnalysis::TransformOpMemFreeAnalysis(mlir::Operation*)::'lambda'(mlir::Operation*)>(long, mlir::Operation*) CheckUses.cpp:0:0
#13 0x000055be46faafa7 mlir::WalkResult mlir::detail::walk<mlir::ForwardIterator>(mlir::Operation*, llvm::function_ref<mlir::WalkResult (mlir::Operation*)>, mlir::WalkOrder) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x131cfa7)
#14 0x000055be46faafa7 mlir::WalkResult mlir::detail::walk<mlir::ForwardIterator>(mlir::Operation*, llvm::function_ref<mlir::WalkResult (mlir::Operation*)>, mlir::WalkOrder) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x131cfa7)
#15 0x000055be46faafa7 mlir::WalkResult mlir::detail::walk<mlir::ForwardIterator>(mlir::Operation*, llvm::function_ref<mlir::WalkResult (mlir::Operation*)>, mlir::WalkOrder) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x131cfa7)
#16 0x000055be49619b1d (anonymous namespace)::CheckUsesPass::runOnOperation() CheckUses.cpp:0:0
#17 0x000055be49ddeec6 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x4150ec6)
#18 0x000055be49ddf7f0 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+0x41517f0)
#19 0x000055be49de1dc2 mlir::PassManager::run(mlir::Operation*) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x4153dc2)
#20 0x000055be49dda53a performActions(llvm::raw_ostream&, std::shared_ptr<llvm::SourceMgr> const&, mlir::MLIRContext*, mlir::MlirOptMainConfig const&) MlirOptMain.cpp:0:0
#21 0x000055be49dda18d 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
#22 0x000055be49e85c65 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+0x41f7c65)
#23 0x000055be49dd4175 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+0x4146175)
#24 0x000055be49dd441f mlir::MlirOptMain(int, char**, llvm::StringRef, llvm::StringRef, mlir::DialectRegistry&) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x414641f)
#25 0x000055be49dd474e mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x414674e)
#26 0x000055be46e5dff7 main (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x11cfff7)
#27 0x00007f7907d70083 __libc_start_main /build/glibc-LcI20x/glibc-2.31/csu/../csu/libc-start.c:342:3
#28 0x000055be46e5db6e _start (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x11cfb6e)
``` 
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzsWl9v2zgS_zTMCxGDov4_5MF16rsCDRI02b1HgSJHDq8yqSWpJL5PfyAlW7aaP93dZnfvsEAbW-KQM_Ob38xQlJm1cqMALlD6AaWXZ6x399pcPD7usqiMzmotdhcb6fADGCu1QvES15yWDS_jnGe8ThiNSFMQXsY8LxuegShzXpCoKRBZIrK0O-tg6-ehjPxU98r1OCoWJFlk-PPdLcrIIGegM1r0HPCjdPej_LaV5lx3DuNzZ5iyjTbbcyFZC9yd83vgX897CxazhZc8rIXIcrwTLzH2NzIy_PMXTa_4wv_BKCGN1ogWiKbMbIgXl0rAE6IrPNyLULyc3aL4SK7EKP-AyBJjy5tFo40XkhjFl6M0wU7v18LWQTetMk7E_g4JU5iR7n7BtbKOKYfJoCmmQQ7ll-HTgOuN8l6FG4gst1r0LWDmnJF178D6tQ-ALTyglWJbEJWFX3pQHFB-edA_CZ7KeHiq6jBabZlUA1ZGa4fiJaLRNJepXaW7Y0COVw4mdKKtOuYcGGXxuAx-fp1jcNKPdU1OgvS8Yj9AlrgT7WLU4j3YMsfvqwBpQLMGBY10iBbRqbEngfCL6A4MU8L6cUTT6DDgdh3Y01n0dJaTWmFE6Wk8EaWDG2T02ssbpjaA4tUDa3tA8Udv1DmKP-JBNHpG1OsfJI-MCALwaKSDwSAPubdhQmpMHG_Gft6BQoc7U_RH-r4QoIbJtjdgES06ozu2YQ7mgIbQRYfQRW-Fbh6FSdJTJ0RyHlKpDskVaobX9SwrzwNi3w6dqI1majfgqo4ZUC5wMtiVf9BdyKYxyemY-B5Wn1W_0wrWeuYyJx_A4iMCvJIhB6jpAWr6vVAPNWVfWvDRt2nuTkIrjkrQRJrjsmod41_9LA6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