[Mlir-commits] [mlir] [mlir] Fix crash on test.with_bounds op (PR #218489)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Mon Aug 24 11:47:35 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir
Author: tht2005
<details>
<summary>Changes</summary>
The old verify function implementation only check
if umin and result have the same bit width, add
the check for umax, smin and smax too.
Fix https://github.com/llvm/llvm-project/issues/203855
---
Full diff: https://github.com/llvm/llvm-project/pull/218489.diff
2 Files Affected:
- (modified) mlir/test/Interfaces/InferIntRangeInterface/infer-int-range-test-ops-invalid.mlir (+37-1)
- (modified) mlir/test/lib/Dialect/Test/TestOpDefs.cpp (+15-4)
``````````diff
diff --git a/mlir/test/Interfaces/InferIntRangeInterface/infer-int-range-test-ops-invalid.mlir b/mlir/test/Interfaces/InferIntRangeInterface/infer-int-range-test-ops-invalid.mlir
index 7392b9d2ec712..8e358a8b7cec6 100644
--- a/mlir/test/Interfaces/InferIntRangeInterface/infer-int-range-test-ops-invalid.mlir
+++ b/mlir/test/Interfaces/InferIntRangeInterface/infer-int-range-test-ops-invalid.mlir
@@ -4,9 +4,45 @@
// bounds for an i8 result) is rejected as invalid IR.
// See: https://github.com/llvm/llvm-project/issues/120882
func.func @with_bounds_mismatched_width() -> i8 {
- // expected-error at +1 {{'test.with_bounds' op bound attribute width (64) does not match result type width (8)}}
+ // expected-error at +1 {{'test.with_bounds' op 'umin' bound attribute width (64) does not match result type width (8)}}
%0 = test.with_bounds { umin = 10 : i64, umax = 15 : i64,
smin = 10 : i64, smax = 15 : i64 } : i8
%1 = test.reflect_bounds %0 : i8
return %1 : i8
}
+
+// Verify that test.with_bounds with mismatched attribute width (e.g., i64
+// bounds for an i8 result) is rejected as invalid IR. The old implementation
+// only compare bid width of umin and result, need to check umax, smin and
+// smax too.
+// See: https://github.com/llvm/llvm-project/issues/203855
+func.func @mismatched_umax_bound_bitwidth() -> i32 {
+ // expected-error at +1 {{'test.with_bounds' op 'umax' bound attribute width (8) does not match result type width (32)}}
+ %0 = test.with_bounds {
+ umin = 0 : i32,
+ umax = 127 : i8,
+ smin = 0 : i8,
+ smax = 127 : i8
+ } : i32
+ return %0 : i32
+}
+func.func @mismatched_smin_bound_bitwidth() -> i32 {
+ // expected-error at +1 {{'test.with_bounds' op 'smin' bound attribute width (8) does not match result type width (32)}}
+ %0 = test.with_bounds {
+ umin = 0 : i32,
+ umax = 127 : i32,
+ smin = 0 : i8,
+ smax = 127 : i8
+ } : i32
+ return %0 : i32
+}
+func.func @mismatched_smax_bound_bitwidth() -> i32 {
+ // expected-error at +1 {{'test.with_bounds' op 'smax' bound attribute width (8) does not match result type width (32)}}
+ %0 = test.with_bounds {
+ umin = 0 : i32,
+ umax = 127 : i32,
+ smin = 0 : i32,
+ smax = 127 : i8
+ } : i32
+ return %0 : i32
+}
diff --git a/mlir/test/lib/Dialect/Test/TestOpDefs.cpp b/mlir/test/lib/Dialect/Test/TestOpDefs.cpp
index 2e8bce9199fd2..560c2f6bc751b 100644
--- a/mlir/test/lib/Dialect/Test/TestOpDefs.cpp
+++ b/mlir/test/lib/Dialect/Test/TestOpDefs.cpp
@@ -911,10 +911,21 @@ LogicalResult TestWithBoundsOp::verify() {
expectedWidth = IndexType::kInternalStorageBitWidth;
else if (auto intTy = llvm::dyn_cast<IntegerType>(type))
expectedWidth = intTy.getWidth();
- if (expectedWidth != 0 && getUmin().getBitWidth() != expectedWidth)
- return emitOpError("bound attribute width (")
- << getUmin().getBitWidth() << ") does not match result type width ("
- << expectedWidth << ")";
+ // wrapper to check bound width and return error message if needed
+ auto verifyBoundWidth = [&](StringRef name,
+ const APInt& bound) -> LogicalResult {
+ if (expectedWidth != 0 && bound.getBitWidth() != expectedWidth)
+ return emitOpError()
+ << "'" << name << "' bound attribute width ("
+ << bound.getBitWidth()
+ << ") does not match result type width (" << expectedWidth << ")";
+ return success();
+ };
+ if (failed(verifyBoundWidth("umin", getUmin())) ||
+ failed(verifyBoundWidth("umax", getUmax())) ||
+ failed(verifyBoundWidth("smin", getSmin())) ||
+ failed(verifyBoundWidth("smax", getSmax())))
+ return failure();
return success();
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/218489
More information about the Mlir-commits
mailing list