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

This commit is contained in:
Samarth Narang 2026-02-01 05:57:25 -05:00 committed by GitHub
parent 584bd38627
commit 7f967a9a26
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 24 additions and 2 deletions

View file

@ -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 {};

View file

@ -0,0 +1,22 @@
// RUN: mlir-opt %s -split-input-file -verify-diagnostics
// -----
// Reject index element type in dense array attribute.
// expected-error@+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@+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@+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@+1 {{expected integer or float type, got: 'complex<f32>'}}
module attributes { a = array<complex<f32>: 1, 2> } {}