[Mlir-commits] [mlir] [mlir][IR] Diagnose index element type in DenseArrayAttr (PR #179075)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Sat Jan 31 15:35:37 PST 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir
Author: Samarth Narang (snarang181)
<details>
<summary>Changes</summary>
The dense array attribute parser accepted `index` element types viaisIntOrIndexOrFloat(), but then queried the element bitwidth with getIntOrFloatBitWidth(), which asserts for `index` types.
Reject `index` as a dense array element type and emit a diagnostic instead. Also add corresponding tests.
Fixes https://github.com/llvm/llvm-project/issues/179045
---
Full diff: https://github.com/llvm/llvm-project/pull/179075.diff
2 Files Affected:
- (modified) mlir/lib/AsmParser/AttributeParser.cpp (+2-2)
- (added) mlir/test/IR/invalid-dense-array-attr.mlir (+22)
``````````diff
diff --git a/mlir/lib/AsmParser/AttributeParser.cpp b/mlir/lib/AsmParser/AttributeParser.cpp
index 374471fd3ed41..519609a38be6e 100644
--- a/mlir/lib/AsmParser/AttributeParser.cpp
+++ b/mlir/lib/AsmParser/AttributeParser.cpp
@@ -923,7 +923,7 @@ Attribute Parser::parseDenseArrayAttr(Type attrType) {
// Only bool or integer and floating point elements divisible by bytes are
// supported.
- if (!eltType.isIntOrIndexOrFloat()) {
+ if (!eltType.isIntOrFloat()) {
emitError(typeLoc, "expected integer or float type, got: ") << eltType;
return {};
}
@@ -940,7 +940,7 @@ Attribute Parser::parseDenseArrayAttr(Type attrType) {
return {};
DenseArrayElementParser eltParser(eltType);
- if (eltType.isIntOrIndex()) {
+ if (isa<IntegerType>(eltType)) {
if (parseCommaSeparatedList(
[&] { return eltParser.parseIntegerElement(*this); }))
return {};
diff --git a/mlir/test/IR/invalid-dense-array-attr.mlir b/mlir/test/IR/invalid-dense-array-attr.mlir
new file mode 100644
index 0000000000000..97b9930238543
--- /dev/null
+++ b/mlir/test/IR/invalid-dense-array-attr.mlir
@@ -0,0 +1,22 @@
+// RUN: mlir-opt %s -split-input-file -verify-diagnostics
+
+// -----
+// Reject index element type in dense array attribute.
+// expected-error at +1 {{expected integer or float type, got: 'index'}}
+module attributes { a = array<index: 1, 2> } {}
+
+// -----
+// Reject tensor element type in dense array attribute.
+// expected-error at +1 {{expected integer or float type, got: 'tensor<2xi32>'}}
+module attributes { a = array<tensor<2xi32>: 1, 2> } {}
+
+// -----
+// Reject memref element type in dense array attribute.
+// expected-error at +1 {{expected integer or float type, got: 'memref<2xi32>'}}
+module attributes { a = array<memref<2xi32>: 1, 2> } {}
+
+// -----
+// Reject complex element type in dense array attribute.
+// expected-error at +1 {{expected integer or float type, got: 'complex<f32>'}}
+module attributes { a = array<complex<f32>: 1, 2> } {}
+
``````````
</details>
https://github.com/llvm/llvm-project/pull/179075
More information about the Mlir-commits
mailing list