-
Notifications
You must be signed in to change notification settings - Fork 15.2k
Fix crash when using when using --finalize-memref-to-llvm #112433
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Fix crash when attempting to convert uint to int address space during finalize-memref-to-llvm
|
Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be notified. If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers. If you have further questions, they may be answered by the LLVM GitHub User Guide. You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums. |
|
@llvm/pr-subscribers-mlir-llvm Author: Siddhesh Deodhar (siddhesh195) ChangesThis patch fixes crash when attempting to convert uint to int address space during finalize-memref-to-llvm by doing the following:
Closes #111242 Full diff: https://github.com/llvm/llvm-project/pull/112433.diff 3 Files Affected:
diff --git a/mlir/lib/Conversion/LLVMCommon/Pattern.cpp b/mlir/lib/Conversion/LLVMCommon/Pattern.cpp
index d551506485a454..d502b4f49b00b9 100644
--- a/mlir/lib/Conversion/LLVMCommon/Pattern.cpp
+++ b/mlir/lib/Conversion/LLVMCommon/Pattern.cpp
@@ -106,8 +106,14 @@ bool ConvertToLLVMPattern::isConvertibleAndHasIdentityMaps(
Type ConvertToLLVMPattern::getElementPtrType(MemRefType type) const {
auto addressSpace = getTypeConverter()->getMemRefAddressSpace(type);
- if (failed(addressSpace))
+ if (failed(addressSpace)) {
+ emitError(UnknownLoc::get(type.getContext()),
+ "conversion of memref memory space ")
+ << type.getMemorySpace()
+ << " to integer address space "
+ "failed. Consider adding memory space conversions.";
return {};
+ }
return LLVM::LLVMPointerType::get(type.getContext(), *addressSpace);
}
diff --git a/mlir/lib/Conversion/LLVMCommon/TypeConverter.cpp b/mlir/lib/Conversion/LLVMCommon/TypeConverter.cpp
index 5a92fa839e9847..8693a60ad6e1b0 100644
--- a/mlir/lib/Conversion/LLVMCommon/TypeConverter.cpp
+++ b/mlir/lib/Conversion/LLVMCommon/TypeConverter.cpp
@@ -527,8 +527,10 @@ 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 = llvm::dyn_cast_if_present<IntegerAttr>(*converted)) {
+ if (explicitSpace.getType().isSignedInteger())
+ return explicitSpace.getInt();
+ }
return failure();
}
diff --git a/mlir/test/Conversion/MemRefToLLVM/invalid-uint.mlir b/mlir/test/Conversion/MemRefToLLVM/invalid-uint.mlir
new file mode 100644
index 00000000000000..adad1cb0922337
--- /dev/null
+++ b/mlir/test/Conversion/MemRefToLLVM/invalid-uint.mlir
@@ -0,0 +1,10 @@
+// RUN: mlir-opt %s -finalize-memref-to-llvm 2>&1 | FileCheck %s
+// Since the error is at an unknown location, we use FileCheck instead of
+// -veri-y-diagnostics here
+
+// CHECK: conversion of memref memory space 1 : ui64 to integer address space failed. Consider adding memory space conversions.
+// CHECK-LABEL: @invalid_int_conversion
+func.func @invalid_int_conversion() {
+ %alloc_0 = memref.alloc() {alignment = 64 : i64} : memref<10xf32, 1 : ui64>
+ return
+}
|
|
@llvm/pr-subscribers-mlir Author: Siddhesh Deodhar (siddhesh195) ChangesThis patch fixes crash when attempting to convert uint to int address space during finalize-memref-to-llvm by doing the following:
Closes #111242 Full diff: https://github.com/llvm/llvm-project/pull/112433.diff 3 Files Affected:
diff --git a/mlir/lib/Conversion/LLVMCommon/Pattern.cpp b/mlir/lib/Conversion/LLVMCommon/Pattern.cpp
index d551506485a454..d502b4f49b00b9 100644
--- a/mlir/lib/Conversion/LLVMCommon/Pattern.cpp
+++ b/mlir/lib/Conversion/LLVMCommon/Pattern.cpp
@@ -106,8 +106,14 @@ bool ConvertToLLVMPattern::isConvertibleAndHasIdentityMaps(
Type ConvertToLLVMPattern::getElementPtrType(MemRefType type) const {
auto addressSpace = getTypeConverter()->getMemRefAddressSpace(type);
- if (failed(addressSpace))
+ if (failed(addressSpace)) {
+ emitError(UnknownLoc::get(type.getContext()),
+ "conversion of memref memory space ")
+ << type.getMemorySpace()
+ << " to integer address space "
+ "failed. Consider adding memory space conversions.";
return {};
+ }
return LLVM::LLVMPointerType::get(type.getContext(), *addressSpace);
}
diff --git a/mlir/lib/Conversion/LLVMCommon/TypeConverter.cpp b/mlir/lib/Conversion/LLVMCommon/TypeConverter.cpp
index 5a92fa839e9847..8693a60ad6e1b0 100644
--- a/mlir/lib/Conversion/LLVMCommon/TypeConverter.cpp
+++ b/mlir/lib/Conversion/LLVMCommon/TypeConverter.cpp
@@ -527,8 +527,10 @@ 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 = llvm::dyn_cast_if_present<IntegerAttr>(*converted)) {
+ if (explicitSpace.getType().isSignedInteger())
+ return explicitSpace.getInt();
+ }
return failure();
}
diff --git a/mlir/test/Conversion/MemRefToLLVM/invalid-uint.mlir b/mlir/test/Conversion/MemRefToLLVM/invalid-uint.mlir
new file mode 100644
index 00000000000000..adad1cb0922337
--- /dev/null
+++ b/mlir/test/Conversion/MemRefToLLVM/invalid-uint.mlir
@@ -0,0 +1,10 @@
+// RUN: mlir-opt %s -finalize-memref-to-llvm 2>&1 | FileCheck %s
+// Since the error is at an unknown location, we use FileCheck instead of
+// -veri-y-diagnostics here
+
+// CHECK: conversion of memref memory space 1 : ui64 to integer address space failed. Consider adding memory space conversions.
+// CHECK-LABEL: @invalid_int_conversion
+func.func @invalid_int_conversion() {
+ %alloc_0 = memref.alloc() {alignment = 64 : i64} : memref<10xf32, 1 : ui64>
+ return
+}
|
Resolve test failure by checking if an IntegerAttr is int
Dinistro
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some drive-by comments, but this should be reviewed by people who rely on this conversion as they have more context.
Co-authored-by: Christian Ulmann <[email protected]>
Emit type conversion error message on the operation
| 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() || |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we instead change this to get the integer out of uiN attributes instead?
If not, this is reasonably approved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, there currently is no separate attributes defined for signless and signed integer in BuiltinAttributes and IntegerAttr represents both signless and signed. BuiltinAttributes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the reviews. If the PR looks good, can someone help merge because I don't have write access
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll run CI and land this, thanks for helping!
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
|
@siddhesh195 Congratulations on having your first Pull Request (PR) merged into the LLVM Project! Your changes will be combined with recent changes from other authors, then tested by our build bots. If there is a problem with a build, you may receive a report in an email or a comment on this PR. Please check whether problems have been caused by your change specifically, as the builds can include changes from many authors. It is not uncommon for your change to be included in a build that fails due to someone else's changes, or infrastructure issues. How to do this, and the rest of the post-merge process, is covered in detail here. If your change does cause a problem, it may be reverted, or you can revert it yourself. This is a normal part of LLVM development. You can fix your changes and open a new PR to merge them again. If you don't get any reports, no action is required from you. Your changes are working as expected, well done! |
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 llvm#111242 --------- Co-authored-by: Christian Ulmann <[email protected]>
This patch fixes crash when attempting to convert uint to int address space during finalize-memref-to-llvm by doing the following:
Closes #111242