[Mlir-commits] [mlir] 40740c4 - Fix crash when using when using --finalize-memref-to-llvm (#112433)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Fri Nov 8 10:23:54 PST 2024
Author: Siddhesh Deodhar
Date: 2024-11-08T12:23:50-06:00
New Revision: 40740c4494d971ce410e2051b8d3ea7bbe081c76
URL: https://github.com/llvm/llvm-project/commit/40740c4494d971ce410e2051b8d3ea7bbe081c76
DIFF: https://github.com/llvm/llvm-project/commit/40740c4494d971ce410e2051b8d3ea7bbe081c76.diff
LOG: Fix crash when using when using --finalize-memref-to-llvm (#112433)
This patch fixes crash when attempting to convert uint to int address
space during finalize-memref-to-llvm by doing the following:
1. Add a check to verify that IntegerAttr is signed int before calling
IntegerAttr::getInt()
2. Emit error when getMemRefAddressSpace returns a failure()
Closes #111242
---------
Co-authored-by: Christian Ulmann <christianulmann at gmail.com>
Added:
mlir/test/Conversion/MemRefToLLVM/invalid-uint.mlir
Modified:
mlir/lib/Conversion/LLVMCommon/TypeConverter.cpp
mlir/lib/Conversion/MemRefToLLVM/AllocLikeConversion.cpp
Removed:
################################################################################
diff --git a/mlir/lib/Conversion/LLVMCommon/TypeConverter.cpp b/mlir/lib/Conversion/LLVMCommon/TypeConverter.cpp
index 4e7758bf46d9cf..ce91424e7a577e 100644
--- a/mlir/lib/Conversion/LLVMCommon/TypeConverter.cpp
+++ b/mlir/lib/Conversion/LLVMCommon/TypeConverter.cpp
@@ -524,8 +524,11 @@ LLVMTypeConverter::getMemRefAddressSpace(BaseMemRefType type) const {
return failure();
if (!(*converted)) // Conversion to default is 0.
return 0;
- if (auto explicitSpace = llvm::dyn_cast_if_present<IntegerAttr>(*converted))
- return explicitSpace.getInt();
+ if (auto explicitSpace = dyn_cast_if_present<IntegerAttr>(*converted)) {
+ if (explicitSpace.getType().isIndex() ||
+ explicitSpace.getType().isSignlessInteger())
+ return explicitSpace.getInt();
+ }
return failure();
}
diff --git a/mlir/lib/Conversion/MemRefToLLVM/AllocLikeConversion.cpp b/mlir/lib/Conversion/MemRefToLLVM/AllocLikeConversion.cpp
index e48ca5180b706f..a6408391b1330c 100644
--- a/mlir/lib/Conversion/MemRefToLLVM/AllocLikeConversion.cpp
+++ b/mlir/lib/Conversion/MemRefToLLVM/AllocLikeConversion.cpp
@@ -74,6 +74,12 @@ std::tuple<Value, Value> AllocationOpLLVMLowering::allocateBufferManuallyAlign(
MemRefType memRefType = getMemRefResultType(op);
// Allocate the underlying buffer.
Type elementPtrType = this->getElementPtrType(memRefType);
+ if (!elementPtrType) {
+ emitError(loc, "conversion of memref memory space ")
+ << memRefType.getMemorySpace()
+ << " to integer address space "
+ "failed. Consider adding memory space conversions.";
+ }
LLVM::LLVMFuncOp allocFuncOp = getNotalignedAllocFn(
getTypeConverter(), op->getParentWithTrait<OpTrait::SymbolTable>(),
getIndexType());
diff --git a/mlir/test/Conversion/MemRefToLLVM/invalid-uint.mlir b/mlir/test/Conversion/MemRefToLLVM/invalid-uint.mlir
new file mode 100644
index 00000000000000..7e94677ebbdd7e
--- /dev/null
+++ b/mlir/test/Conversion/MemRefToLLVM/invalid-uint.mlir
@@ -0,0 +1,8 @@
+// RUN: mlir-opt %s -finalize-memref-to-llvm -verify-diagnostics
+
+// CHECK-LABEL: @invalid_int_conversion
+func.func @invalid_int_conversion() {
+ // expected-error at +1 {{conversion of memref memory space 1 : ui64 to integer address space failed. Consider adding memory space conversions.}}
+ %alloc = memref.alloc() {alignment = 64 : i64} : memref<10xf32, 1 : ui64>
+ return
+}
More information about the Mlir-commits
mailing list