Skip to content

Commit 894b27a

Browse files
authored
[mlir][MemRefToLLVM] Fix crash with unconvertable memory space (#132323)
This PR adds handling when the `memref.alloca` with unconvertable memory space to prevent a crash. Fixes #131439.
1 parent cd3798d commit 894b27a

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

mlir/lib/Conversion/MemRefToLLVM/MemRefToLLVM.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,11 @@ struct AllocaOpLowering : public AllocLikeOpLLVMLowering {
105105
auto allocaOp = cast<memref::AllocaOp>(op);
106106
auto elementType =
107107
typeConverter->convertType(allocaOp.getType().getElementType());
108-
unsigned addrSpace =
109-
*getTypeConverter()->getMemRefAddressSpace(allocaOp.getType());
108+
FailureOr<unsigned> maybeAddressSpace =
109+
getTypeConverter()->getMemRefAddressSpace(allocaOp.getType());
110+
if (failed(maybeAddressSpace))
111+
return std::make_tuple(Value(), Value());
112+
unsigned addrSpace = *maybeAddressSpace;
110113
auto elementPtrType =
111114
LLVM::LLVMPointerType::get(rewriter.getContext(), addrSpace);
112115

mlir/test/Conversion/MemRefToLLVM/memref-to-llvm.mlir

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -654,3 +654,14 @@ func.func @store_non_temporal(%input : memref<32xf32, affine_map<(d0) -> (d0)>>,
654654
memref.store %2, %output[%1] {nontemporal = true} : memref<32xf32, affine_map<(d0) -> (d0)>>
655655
func.return
656656
}
657+
658+
// -----
659+
660+
// Ensure unconvertable memory space not cause a crash
661+
662+
// CHECK-LABEL: @alloca_unconvertable_memory_space
663+
func.func @alloca_unconvertable_memory_space() {
664+
// CHECK: memref.alloca
665+
%alloca = memref.alloca() : memref<1x32x33xi32, #spirv.storage_class<StorageBuffer>>
666+
func.return
667+
}

0 commit comments

Comments
 (0)