[Mlir-commits] [mlir] [mlir][IR] Diagnose index element type in DenseArrayAttr (PR #179075)
Samarth Narang
llvmlistbot at llvm.org
Sat Jan 31 15:35:05 PST 2026
https://github.com/snarang181 created https://github.com/llvm/llvm-project/pull/179075
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
>From 51a5fd675d3b694f7c6a16a1ee0b4c4d4bbae395 Mon Sep 17 00:00:00 2001
From: Samarth Narang <snarang at utexas.edu>
Date: Sat, 31 Jan 2026 18:33:43 -0500
Subject: [PATCH] [mlir][IR] Diagnose index elTy in dense array attr
---
mlir/lib/AsmParser/AttributeParser.cpp | 4 ++--
mlir/test/IR/invalid-dense-array-attr.mlir | 22 ++++++++++++++++++++++
2 files changed, 24 insertions(+), 2 deletions(-)
create mode 100644 mlir/test/IR/invalid-dense-array-attr.mlir
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> } {}
+
More information about the Mlir-commits
mailing list