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

    <tr>
        <th>Summary</th>
        <td>
            [mlir] Crash when using --finalize-memref-to-llvm
        </td>
    </tr>

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

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

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

<pre>
    I have the following MLIR program:
test.mlir:
```
func.func @func1() {
  %alloc_0 = memref.alloc() {alignment = 64 : i64} : memref<10xf32, 1 : ui64>
  return 
}
```
The above MLIR program will cause a crash when using the following command:
```
mlir-opt --finalize-memref-to-llvm test.mlir
```
And the crash backtrace is:
```
mlir-opt: /data/tmp/v1005/llvm-project/mlir/lib/IR/BuiltinAttributes.cpp:360: int64_t mlir::IntegerAttr::getInt() const: Assertion `(getType().isIndex() || getType().isSignlessInteger()) && "must be signless integer"' 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/tmp/v1005/llvm-project/build/bin/mlir-opt --finalize-memref-to-llvm test.mlir
 #0 0x000055ebc9fd543f llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/data/tmp/v1005/llvm-project/build/bin/mlir-opt+0x158443f)
 #1 0x000055ebc9fd24a4 SignalHandler(int) Signals.cpp:0:0
 #2 0x00007f4571282420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
 #3 0x00007f4570d4f00b raise (/lib/x86_64-linux-gnu/libc.so.6+0x4300b)
 #4 0x00007f4570d2e859 abort (/lib/x86_64-linux-gnu/libc.so.6+0x22859)
 #5 0x00007f4570d2e729 (/lib/x86_64-linux-gnu/libc.so.6+0x22729)
 #6 0x00007f4570d3ffd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)
 #7 0x000055ebcd3bd0dd mlir::IntegerAttr::getInt() const (/data/tmp/v1005/llvm-project/build/bin/mlir-opt+0x496c0dd)
 #8 0x000055ebcc8b9237 mlir::LLVMTypeConverter::getMemRefAddressSpace(mlir::BaseMemRefType) const (/data/tmp/v1005/llvm-project/build/bin/mlir-opt+0x3e68237)
 #9 0x000055ebcc8af947 mlir::ConvertToLLVMPattern::getElementPtrType(mlir::MemRefType) const (/data/tmp/v1005/llvm-project/build/bin/mlir-opt+0x3e5e947)
#10 0x000055ebcc97eb70 mlir::AllocationOpLLVMLowering::allocateBufferManuallyAlign(mlir::ConversionPatternRewriter&, mlir::Location, mlir::Value, mlir::Operation*, mlir::Value) const (/data/tmp/v1005/llvm-project/build/bin/mlir-opt+0x3f2db70)
#11 0x000055ebcc963a83 (anonymous namespace)::AllocOpLowering::allocateBuffer(mlir::ConversionPatternRewriter&, mlir::Location, mlir::Value, mlir::Operation*) const MemRefToLLVM.cpp:0:0
#12 0x000055ebcc97fbf7 mlir::AllocLikeOpLLVMLowering::matchAndRewrite(mlir::Operation*, llvm::ArrayRef<mlir::Value>, mlir::ConversionPatternRewriter&) const (/data/tmp/v1005/llvm-project/build/bin/mlir-opt+0x3f2ebf7)
#13 0x000055ebcd2ff7ea mlir::ConversionPattern::matchAndRewrite(mlir::Operation*, mlir::PatternRewriter&) const (/data/tmp/v1005/llvm-project/build/bin/mlir-opt+0x48ae7ea)
#14 0x000055ebd04a0dc0 mlir::PatternApplicator::matchAndRewrite(mlir::Operation*, mlir::PatternRewriter&, llvm::function_ref<bool (mlir::Pattern const&)>, llvm::function_ref<void (mlir::Pattern const&)>, llvm::function_ref<llvm::LogicalResult (mlir::Pattern const&)>) (/data/tmp/v1005/llvm-project/build/bin/mlir-opt+0x7a4fdc0)
#15 0x000055ebcd3078bb (anonymous namespace)::OperationLegalizer::legalize(mlir::Operation*, mlir::ConversionPatternRewriter&) DialectConversion.cpp:0:0
#16 0x000055ebcd308efe mlir::OperationConverter::convert(mlir::ConversionPatternRewriter&, mlir::Operation*) (/data/tmp/v1005/llvm-project/build/bin/mlir-opt+0x48b7efe)
#17 0x000055ebcd30c86b mlir::OperationConverter::convertOperations(llvm::ArrayRef<mlir::Operation*>) (/data/tmp/v1005/llvm-project/build/bin/mlir-opt+0x48bb86b)
#18 0x000055ebcd30ec59 mlir::applyPartialConversion(mlir::Operation*, mlir::ConversionTarget const&, mlir::FrozenRewritePatternSet const&, mlir::ConversionConfig) (/data/tmp/v1005/llvm-project/build/bin/mlir-opt+0x48bdc59)
#19 0x000055ebcc97621f (anonymous namespace)::FinalizeMemRefToLLVMConversionPass::runOnOperation() MemRefToLLVM.cpp:0:0
#20 0x000055ebcd2644f1 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (/data/tmp/v1005/llvm-project/build/bin/mlir-opt+0x48134f1)
#21 0x000055ebcd2649ca mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) (/data/tmp/v1005/llvm-project/build/bin/mlir-opt+0x48139ca)
#22 0x000055ebcd265514 mlir::PassManager::run(mlir::Operation*) (/data/tmp/v1005/llvm-project/build/bin/mlir-opt+0x4814514)
#23 0x000055ebcd256a1b performActions(llvm::raw_ostream&, std::shared_ptr<llvm::SourceMgr> const&, mlir::MLIRContext*, mlir::MlirOptMainConfig const&) MlirOptMain.cpp:0:0
#24 0x000055ebcd2573e4 processBuffer(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::MlirOptMainConfig const&, mlir::DialectRegistry&, llvm::ThreadPoolInterface*) MlirOptMain.cpp:0:0
#25 0x000055ebcd257594 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&)::'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 0x000055ebcd36004e 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/tmp/v1005/llvm-project/build/bin/mlir-opt+0x490f04e)
#27 0x000055ebcd24ee39 mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&) (/data/tmp/v1005/llvm-project/build/bin/mlir-opt+0x47fde39)
#28 0x000055ebcd257701 mlir::MlirOptMain(int, char**, llvm::StringRef, llvm::StringRef, mlir::DialectRegistry&) (/data/tmp/v1005/llvm-project/build/bin/mlir-opt+0x4806701)
#29 0x000055ebcd257bc6 mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&) (/data/tmp/v1005/llvm-project/build/bin/mlir-opt+0x4806bc6)
#30 0x000055ebc9eecacb main (/data/tmp/v1005/llvm-project/build/bin/mlir-opt+0x149bacb)
#31 0x00007f4570d30083 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24083)
#32 0x000055ebc9fa862e _start (/data/tmp/v1005/llvm-project/build/bin/mlir-opt+0x155762e)
Aborted (core dumped)
```
My git version is bf895c714e1f8a51c1e565a75acf60bf7197be51.
</pre>
<img width="1px" height="1px" alt="" src="http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