[Mlir-commits] [mlir] [mlir][irdl] Fix crash in TypeOp/AttributeOp verify on empty sym_name (PR #184598)

Mehdi Amini llvmlistbot at llvm.org
Wed Mar 4 03:59:15 PST 2026


https://github.com/joker-eph created https://github.com/llvm/llvm-project/pull/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

>From 48772c489cdf4cbd59ce352039aa92094ae9191e Mon Sep 17 00:00:00 2001
From: Mehdi Amini <joker.eph at gmail.com>
Date: Wed, 4 Mar 2026 01:59:18 -0800
Subject: [PATCH] [mlir][irdl] Fix crash in TypeOp/AttributeOp verify on empty
 sym_name

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
---
 mlir/lib/Dialect/IRDL/IR/IRDL.cpp              |  4 ++--
 mlir/test/Dialect/IRDL/invalid_names.irdl.mlir | 16 ++++++++++++++++
 2 files changed, 18 insertions(+), 2 deletions(-)

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