[Mlir-commits] [mlir] [mlir][test] Fix crash in ReifyBoundOp with invalid 'type' attribute (PR #184004)

Mehdi Amini llvmlistbot at llvm.org
Sun Mar 1 04:53:59 PST 2026


https://github.com/joker-eph created https://github.com/llvm/llvm-project/pull/184004

The `ReifyBoundOp::getBoundType()` called `llvm_unreachable("invalid bound type")` when the `type` attribute was set to a value other than "EQ", "LB", or "UB" (e.g., "scalable"). This caused an abort instead of a user-visible diagnostic.

Add a verification check that rejects invalid `type` values with a proper error message before `getBoundType()` is ever called.

Fixes #128805

>From e11be20bec4ae202f2c8981772ef9ed6cd3c2e19 Mon Sep 17 00:00:00 2001
From: Mehdi Amini <joker.eph at gmail.com>
Date: Sun, 1 Mar 2026 04:50:38 -0800
Subject: [PATCH] [mlir][test] Fix crash in ReifyBoundOp with invalid 'type'
 attribute

The `ReifyBoundOp::getBoundType()` called `llvm_unreachable("invalid bound
type")` when the `type` attribute was set to a value other than "EQ", "LB",
or "UB" (e.g., "scalable"). This caused an abort instead of a user-visible
diagnostic.

Add a verification check that rejects invalid `type` values with a proper
error message before `getBoundType()` is ever called.

Fixes #128805
---
 mlir/test/Dialect/Affine/invalid-reify-bound-dim.mlir | 10 ++++++++++
 mlir/test/lib/Dialect/Test/TestOpDefs.cpp             |  3 +++
 2 files changed, 13 insertions(+)

diff --git a/mlir/test/Dialect/Affine/invalid-reify-bound-dim.mlir b/mlir/test/Dialect/Affine/invalid-reify-bound-dim.mlir
index e923ac19c5177..e72457c776d69 100644
--- a/mlir/test/Dialect/Affine/invalid-reify-bound-dim.mlir
+++ b/mlir/test/Dialect/Affine/invalid-reify-bound-dim.mlir
@@ -44,4 +44,14 @@ func.func @test_invalid_reify_without_dim(%size: index) -> (index) {
     %dim = "test.reify_bound"(%tensor_val) : (tensor<?xf32>) -> index
 
     return %dim: index
+}
+
+// -----
+
+// Verify that an invalid 'type' value produces a proper error rather than
+// crashing with llvm_unreachable. See: https://github.com/llvm/llvm-project/issues/128805
+func.func @test_invalid_bound_type(%val: index) -> index {
+    // expected-error at +1 {{'test.reify_bound' op invalid bound type 'scalable', expected 'EQ', 'LB', or 'UB'}}
+    %bound = "test.reify_bound"(%val) {type = "scalable"} : (index) -> index
+    return %bound : index
 }
\ No newline at end of file
diff --git a/mlir/test/lib/Dialect/Test/TestOpDefs.cpp b/mlir/test/lib/Dialect/Test/TestOpDefs.cpp
index d2826cc42b270..c243bd79a44a8 100644
--- a/mlir/test/lib/Dialect/Test/TestOpDefs.cpp
+++ b/mlir/test/lib/Dialect/Test/TestOpDefs.cpp
@@ -1014,6 +1014,9 @@ mlir::presburger::BoundType ReifyBoundOp::getBoundType() {
 }
 
 LogicalResult ReifyBoundOp::verify() {
+  if (getType() != "EQ" && getType() != "LB" && getType() != "UB")
+    return emitOpError("invalid bound type '")
+           << getType() << "', expected 'EQ', 'LB', or 'UB'";
   if (isa<ShapedType>(getVar().getType())) {
     if (!getDim().has_value())
       return emitOpError("expected 'dim' attribute for shaped type variable");



More information about the Mlir-commits mailing list