Skip to content

Commit b8780fb

Browse files
committed
Fix crash when using when using --finalize-memref-to-llvm
Fix crash when attempting to convert uint to int address space during finalize-memref-to-llvm
1 parent a797144 commit b8780fb

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

mlir/lib/Conversion/LLVMCommon/Pattern.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,14 @@ bool ConvertToLLVMPattern::isConvertibleAndHasIdentityMaps(
106106

107107
Type ConvertToLLVMPattern::getElementPtrType(MemRefType type) const {
108108
auto addressSpace = getTypeConverter()->getMemRefAddressSpace(type);
109-
if (failed(addressSpace))
109+
if (failed(addressSpace)) {
110+
emitError(UnknownLoc::get(type.getContext()),
111+
"conversion of memref memory space ")
112+
<< type.getMemorySpace()
113+
<< " to integer address space "
114+
"failed. Consider adding memory space conversions.";
110115
return {};
116+
}
111117
return LLVM::LLVMPointerType::get(type.getContext(), *addressSpace);
112118
}
113119

mlir/lib/Conversion/LLVMCommon/TypeConverter.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -527,8 +527,10 @@ LLVMTypeConverter::getMemRefAddressSpace(BaseMemRefType type) const {
527527
return failure();
528528
if (!(*converted)) // Conversion to default is 0.
529529
return 0;
530-
if (auto explicitSpace = llvm::dyn_cast_if_present<IntegerAttr>(*converted))
531-
return explicitSpace.getInt();
530+
if (auto explicitSpace = llvm::dyn_cast_if_present<IntegerAttr>(*converted)) {
531+
if (explicitSpace.getType().isSignedInteger())
532+
return explicitSpace.getInt();
533+
}
532534
return failure();
533535
}
534536

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// RUN: mlir-opt %s -finalize-memref-to-llvm 2>&1 | FileCheck %s
2+
// Since the error is at an unknown location, we use FileCheck instead of
3+
// -veri-y-diagnostics here
4+
5+
// CHECK: conversion of memref memory space 1 : ui64 to integer address space failed. Consider adding memory space conversions.
6+
// CHECK-LABEL: @invalid_int_conversion
7+
func.func @invalid_int_conversion() {
8+
%alloc_0 = memref.alloc() {alignment = 64 : i64} : memref<10xf32, 1 : ui64>
9+
return
10+
}

0 commit comments

Comments
 (0)