[Mlir-commits] [mlir] [MLIR][Bufferization]: Handle invalid memref element types (PR #173692)
Stefan Weigl-Bosker
llvmlistbot at llvm.org
Sun Dec 28 18:16:13 PST 2025
https://github.com/sweiglbosker updated https://github.com/llvm/llvm-project/pull/173692
>From 387173ce617bfd03fcc6ef79da5d74ae5d1ff728 Mon Sep 17 00:00:00 2001
From: Stefan Weigl-Bosker <stefan at s00.xyz>
Date: Fri, 26 Dec 2025 20:06:30 -0500
Subject: [PATCH] [Bufferization]: Handle invalid memref element types
---
.../Dialect/Bufferization/IR/BufferizableOpInterface.cpp | 8 ++++++++
.../Transforms/one-shot-module-bufferize-invalid.mlir | 9 +++++++++
2 files changed, 17 insertions(+)
diff --git a/mlir/lib/Dialect/Bufferization/IR/BufferizableOpInterface.cpp b/mlir/lib/Dialect/Bufferization/IR/BufferizableOpInterface.cpp
index 9b11270e7bbe2..4fa580a8c78b5 100644
--- a/mlir/lib/Dialect/Bufferization/IR/BufferizableOpInterface.cpp
+++ b/mlir/lib/Dialect/Bufferization/IR/BufferizableOpInterface.cpp
@@ -961,6 +961,14 @@ FailureOr<BufferLikeType> bufferization::detail::defaultGetBufferType(
assert(llvm::isa<TensorType>(value.getType()) && "expected tensor type");
auto tensorType = cast<TensorType>(value.getType());
+ auto elementType = tensorType.getElementType();
+
+ if (!BaseMemRefType::isValidElementType(elementType))
+ return getOwnerOfValue(value)->emitError()
+ << "cannot bufferize value of type " << tensorType
+ << ": element type " << elementType
+ << " is not a valid memref element type";
+
// No further analysis is possible for a block argument.
if (llvm::isa<BlockArgument>(value)) {
return cast<BufferLikeType>(
diff --git a/mlir/test/Dialect/Bufferization/Transforms/one-shot-module-bufferize-invalid.mlir b/mlir/test/Dialect/Bufferization/Transforms/one-shot-module-bufferize-invalid.mlir
index 29714e61d336a..948739eface6a 100644
--- a/mlir/test/Dialect/Bufferization/Transforms/one-shot-module-bufferize-invalid.mlir
+++ b/mlir/test/Dialect/Bufferization/Transforms/one-shot-module-bufferize-invalid.mlir
@@ -134,3 +134,12 @@ func.func @func_multiple_yields(%t: tensor<5xf32>) -> tensor<5xf32> {
^bb1(%arg1 : tensor<5xf32>):
func.return %arg1 : tensor<5xf32>
}
+
+// -----
+
+func.func @non_memref_elem_type() -> tensor<1x!quant.uniform<i8:f32, 1.0>> {
+ // expected-error @below{{cannot bufferize value of type 'tensor<1x!quant.uniform<i8:f32, 1.000000e+00>>': element type '!quant.uniform<i8:f32, 1.000000e+00>' is not a valid memref element type}}
+ // expected-error @below{{failed to bufferize op}}
+ %t = tensor.empty() : tensor<1x!quant.uniform<i8:f32, 1.0>>
+ return %t : tensor<1x!quant.uniform<i8:f32, 1.0>>
+}
More information about the Mlir-commits
mailing list