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

    <tr>
        <th>Summary</th>
        <td>
            [mlir][spirv] --convert-func-to-spirv crashed with assertion failure "invalid index for shaped type"
        </td>
    </tr>

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

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

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

<pre>
    git version: 0359a78f77fbee15a3c3ca9e6a44301336cc0f6e

system: ```Ubuntu 20.04.6 LTS (Focal Fossa)```

reproduced with: ```mlir-opt --convert-func-to-spirv a.mlir```

a.mlir:
```
func.func private @func1() {
  %c15 = arith.constant 15 : index
  %c28 = arith.constant 28 : index
  %alloc_18 = memref.alloc() {alignment = 64 : i64} : memref<9xi64>
  // This lines is invalid.
  // Crash would disappear, if %c28 is 0.
  %dim = memref.dim %alloc_18, %c28 : memref<9xi64>
 %alloca_29 = memref.alloca() : memref<9x9xi64>
  %70 = affine.vector_load %alloca_29[%c15, %dim] : memref<9x9xi64>, vector<31xi64>
 return
}
```

trace:
```
mlir-opt: /data/bin/llvm-project/build/tools/mlir/include/mlir/IR/BuiltinTypeInterfaces.h.inc:240: bool mlir::detail::ShapedTypeTrait<ConcreteType>::isDynamicDim(unsigned int) const [with ConcreteType = mlir::MemRefType]: Assertion `idx < getRank() && "invalid index for shaped 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/bin/llvm-project/build/bin/mlir-opt --convert-func-to-spirv reduced.mlir
 #0 0x0000558d54f95a9f llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/data/bin/llvm-project/build/bin/mlir-opt+0x15d2a9f)
 #1 0x0000558d54f92b34 SignalHandler(int) Signals.cpp:0:0
 #2 0x00007f7d1e0bb420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
 #3 0x00007f7d1dba600b raise (/lib/x86_64-linux-gnu/libc.so.6+0x4300b)
 #4 0x00007f7d1db85859 abort (/lib/x86_64-linux-gnu/libc.so.6+0x22859)
 #5 0x00007f7d1db85729 (/lib/x86_64-linux-gnu/libc.so.6+0x22729)
 #6 0x00007f7d1db96fd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)
 #7 0x0000558d55082017 isDimOpValidSymbol(mlir::ShapedDimOpInterface, mlir::Region*) AffineOps.cpp:0:0
 #8 0x0000558d55081767 mlir::affine::isValidSymbol(mlir::Value, mlir::Region*) (/data/bin/llvm-project/build/bin/mlir-opt+0x16be767)
 #9 0x0000558d550822bd mlir::affine::isValidDim(mlir::Value, mlir::Region*) (/data/bin/llvm-project/build/bin/mlir-opt+0x16bf2bd)
#10 0x0000558d55082412 isValidAffineIndexOperand(mlir::Value, mlir::Region*) AffineOps.cpp:0:0
#11 0x0000558d55082a94 verifyMemoryOpIndexing(mlir::Operation*, mlir::AffineMapAttr, mlir::OperandRange, mlir::MemRefType, unsigned int) AffineOps.cpp:0:0
#12 0x0000558d5508306a mlir::affine::AffineVectorLoadOp::verify() (/data/bin/llvm-project/build/bin/mlir-opt+0x16c006a)
#13 0x0000558d550958a0 mlir::Op<mlir::affine::AffineVectorLoadOp, mlir::OpTrait::ZeroRegions, mlir::OpTrait::OneResult, mlir::OpTrait::OneTypedResult<mlir::VectorType>::Impl, mlir::OpTrait::ZeroSuccessors, mlir::OpTrait::AtLeastNOperands<1u>::Impl, mlir::OpTrait::OpInvariants, mlir::BytecodeOpInterface::Trait, mlir::affine::AffineReadOpInterface::Trait, mlir::affine::AffineMapAccessInterface::Trait, mlir::OpTrait::MemRefsNormalizable, mlir::MemoryEffectOpInterface::Trait>::verifyInvariants(mlir::Operation*) (/data/bin/llvm-project/build/bin/mlir-opt+0x16d28a0)
#14 0x0000558d5509ae38 mlir::RegisteredOperationName::Model<mlir::affine::AffineVectorLoadOp>::verifyInvariants(mlir::Operation*) (/data/bin/llvm-project/build/bin/mlir-opt+0x16d7e38)
#15 0x0000558d57d2b8b3 (anonymous namespace)::OperationVerifier::verifyOnEntrance(mlir::Operation&) (.isra.0) Verifier.cpp:0:0
#16 0x0000558d57d2cbdf (anonymous namespace)::OperationVerifier::verifyOperation(mlir::Operation&) Verifier.cpp:0:0
#17 0x0000558d57d2d9a8 (anonymous namespace)::OperationVerifier::verifyOnExit(mlir::Operation&) Verifier.cpp:0:0
#18 0x0000558d57d2c671 (anonymous namespace)::OperationVerifier::verifyOperation(mlir::Operation&) Verifier.cpp:0:0
#19 0x0000558d57d2e63a mlir::verify(mlir::Operation*, bool) (/data/bin/llvm-project/build/bin/mlir-opt+0x436b63a)
#20 0x0000558d57af39be mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (/data/bin/llvm-project/build/bin/mlir-opt+0x41309be)
#21 0x0000558d57af3d4a 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+0x4130d4a)
#22 0x0000558d57af4574 mlir::PassManager::run(mlir::Operation*) (/data/bin/llvm-project/build/bin/mlir-opt+0x4131574)
#23 0x0000558d57ae4e3b performActions(llvm::raw_ostream&, std::shared_ptr<llvm::SourceMgr> const&, mlir::MLIRContext*, mlir::MlirOptMainConfig const&) MlirOptMain.cpp:0:0
#24 0x0000558d57ae62f4 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
#25 0x0000558d57ae64a4 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
#26 0x0000558d57be2eb4 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+0x421feb4)
#27 0x0000558d57adf777 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+0x411c777)
#28 0x0000558d57ae67cb mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&) (/data/bin/llvm-project/build/bin/mlir-opt+0x41237cb)
#29 0x0000558d54ecdb8b main (/data/bin/llvm-project/build/bin/mlir-opt+0x150ab8b)
#30 0x00007f7d1db87083 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24083)
#31 0x0000558d54f6633e _start (/data/bin/llvm-project/build/bin/mlir-opt+0x15a333e)
Aborted (core dumped)
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzcWk1v4zjS_jXKhYghkfo85ODYCd4AnUmQ5O3DXoySSNncpkgtSWXi_fULUv6QlDid7jSmZ3cwHdhSsep56osl0WAMX0vGLoLkMkiWZ9DZjdIXIJX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