[Mlir-commits] [mlir] 7f967a9 - [mlir][IR] Diagnose index element type in DenseArrayAttr (#179075)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Sun Feb 1 02:57:30 PST 2026


Author: Samarth Narang
Date: 2026-02-01T05:57:25-05:00
New Revision: 7f967a9a26a5717eac6eeeabef9288e0e6a5d730

URL: https://github.com/llvm/llvm-project/commit/7f967a9a26a5717eac6eeeabef9288e0e6a5d730
DIFF: https://github.com/llvm/llvm-project/commit/7f967a9a26a5717eac6eeeabef9288e0e6a5d730.diff

LOG: [mlir][IR] Diagnose index element type in DenseArrayAttr (#179075)

Added: 
    mlir/test/IR/invalid-dense-array-attr.mlir

Modified: 
    mlir/lib/AsmParser/AttributeParser.cpp

Removed: 
    


################################################################################
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