[Mlir-commits] [mlir] [mlir] Emit an error when dense i1 array values are not `true` or `false` (PR #173533)
Longsheng Mou
llvmlistbot at llvm.org
Thu Dec 25 00:42:22 PST 2025
https://github.com/CoTinker created https://github.com/llvm/llvm-project/pull/173533
Fixes #173373.
>From 3101bf89569e644f49a396b471abb942d1ec97ea Mon Sep 17 00:00:00 2001
From: Longsheng Mou <longshengmou at gmail.com>
Date: Thu, 25 Dec 2025 16:37:49 +0800
Subject: [PATCH 1/2] [mlir] Emit an error when dense i1 array values are not
`true` or `false`
---
mlir/lib/AsmParser/AttributeParser.cpp | 2 ++
1 file changed, 2 insertions(+)
diff --git a/mlir/lib/AsmParser/AttributeParser.cpp b/mlir/lib/AsmParser/AttributeParser.cpp
index dcb21e7d0831d..374471fd3ed41 100644
--- a/mlir/lib/AsmParser/AttributeParser.cpp
+++ b/mlir/lib/AsmParser/AttributeParser.cpp
@@ -883,6 +883,8 @@ ParseResult DenseArrayElementParser::parseIntegerElement(Parser &p) {
!type.isUnsignedInteger());
p.consumeToken();
} else if (p.consumeIf(Token::integer)) {
+ if (type.isInteger(1))
+ return p.emitError("expected 'true' or 'false' values for i1 type");
value = buildAttributeAPInt(type, isNegative, spelling);
if (!value)
return p.emitError("integer constant out of range");
>From 1f1c2c394aec219d7695822a005af01ffaddb747 Mon Sep 17 00:00:00 2001
From: Longsheng Mou <longshengmou at gmail.com>
Date: Thu, 25 Dec 2025 16:40:40 +0800
Subject: [PATCH 2/2] add test
---
mlir/test/IR/invalid-builtin-attributes.mlir | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/mlir/test/IR/invalid-builtin-attributes.mlir b/mlir/test/IR/invalid-builtin-attributes.mlir
index 58d4940eaf874..0d00b3141fbc6 100644
--- a/mlir/test/IR/invalid-builtin-attributes.mlir
+++ b/mlir/test/IR/invalid-builtin-attributes.mlir
@@ -580,6 +580,16 @@ func.func @duplicate_dictionary_attr_key() {
// -----
+// expected-error at below {{expected i1 type for 'true' or 'false' values}}
+#attr = array<i8: true>
+
+// -----
+
+// expected-error at below {{expected 'true' or 'false' values for i1 type}}
+#attr = array<i1: 0>
+
+// -----
+
// expected-error at below {{expected '[' after 'distinct'}}
#attr = distinct<
More information about the Mlir-commits
mailing list