[Mlir-commits] [mlir] 1b35451 - [mlir][irdl] Fix crash in TypeOp/AttributeOp verify on empty sym_name (#184598)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Wed Mar 4 05:26:55 PST 2026
Author: Mehdi Amini
Date: 2026-03-04T14:26:50+01:00
New Revision: 1b3545117df0dfcea164d33a2432c66aa3b7f559
URL: https://github.com/llvm/llvm-project/commit/1b3545117df0dfcea164d33a2432c66aa3b7f559
DIFF: https://github.com/llvm/llvm-project/commit/1b3545117df0dfcea164d33a2432c66aa3b7f559.diff
LOG: [mlir][irdl] Fix crash in TypeOp/AttributeOp verify on empty sym_name (#184598)
TypeOp::verify() and AttributeOp::verify() called StringRef::front() to
check for leading '\!' or '#' sigils before passing the name to
isValidName(). When sym_name is empty, front() triggers an assertion
failure:
Assertion `\!empty()' failed.
Fix: guard the front() calls with an emptiness check. An empty sym_name
then falls through to isValidName(), which already emits a proper
diagnostic:
error: name of type is empty
Fixes #159949
Added:
Modified:
mlir/lib/Dialect/IRDL/IR/IRDL.cpp
mlir/test/Dialect/IRDL/invalid_names.irdl.mlir
Removed:
################################################################################
diff --git a/mlir/lib/Dialect/IRDL/IR/IRDL.cpp b/mlir/lib/Dialect/IRDL/IR/IRDL.cpp
index d5d2ca33d8a5f..278113fc6e966 100644
--- a/mlir/lib/Dialect/IRDL/IR/IRDL.cpp
+++ b/mlir/lib/Dialect/IRDL/IR/IRDL.cpp
@@ -116,14 +116,14 @@ LogicalResult OperationOp::verify() {
LogicalResult TypeOp::verify() {
auto symName = getSymName();
- if (symName.front() == '!')
+ if (!symName.empty() && symName.front() == '!')
symName = symName.substr(1);
return isValidName(symName, getOperation(), "type");
}
LogicalResult AttributeOp::verify() {
auto symName = getSymName();
- if (symName.front() == '#')
+ if (!symName.empty() && symName.front() == '#')
symName = symName.substr(1);
return isValidName(symName, getOperation(), "attribute");
}
diff --git a/mlir/test/Dialect/IRDL/invalid_names.irdl.mlir b/mlir/test/Dialect/IRDL/invalid_names.irdl.mlir
index e2d2be52fc3db..20729e836866b 100644
--- a/mlir/test/Dialect/IRDL/invalid_names.irdl.mlir
+++ b/mlir/test/Dialect/IRDL/invalid_names.irdl.mlir
@@ -92,3 +92,19 @@ irdl.dialect @test_dialect {
}
// -----
+
+irdl.dialect @test_dialect {
+ // expected-error at +1 {{name of type is empty}}
+ irdl.type @"" {
+ %0 = irdl.any
+ }
+}
+
+// -----
+
+irdl.dialect @test_dialect {
+ // expected-error at +1 {{name of attribute is empty}}
+ irdl.attribute @"" {
+ %0 = irdl.any
+ }
+}
More information about the Mlir-commits
mailing list