[Mlir-commits] [mlir] [mlir][test] Fix RegionYieldOp builder adding a null operand (PR #222633)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Thu Sep 10 05:51:22 PDT 2026


https://github.com/AkunCube created https://github.com/llvm/llvm-project/pull/222633

The custom NoOperand build delegate of test::RegionYieldOp forwarded {} to build(), which overload resolution maps to the generated builder taking a single Value parameter, so a null Value was added as an operand. That only explodes once the op is actually created: parsing an op with the `SingleBlockImplicitTerminator` trait whose region lacks a terminator builds the implicit terminator, inserts the null operand and hits a null use-list
access in IROperandBase::insertInto.

Drop the delegate and use an empty builder body like scf.yield, and add a parser error test for the missing-terminator path.

Fixes #221638

>From 5323cc593914aac2aa6d480278adaf12a69cb969 Mon Sep 17 00:00:00 2001
From: cubehan3 <cubehan3 at gmail.com>
Date: Thu, 10 Sep 2026 12:49:32 +0000
Subject: [PATCH] [mlir][test] Fix RegionYieldOp builder adding a null operand

---
 mlir/test/IR/invalid.mlir             | 8 ++++++++
 mlir/test/lib/Dialect/Test/TestOps.td | 4 +---
 2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/mlir/test/IR/invalid.mlir b/mlir/test/IR/invalid.mlir
index 89077ef0f4736..6e8fd96ffba31 100644
--- a/mlir/test/IR/invalid.mlir
+++ b/mlir/test/IR/invalid.mlir
@@ -699,3 +699,11 @@ func.func @drop_references_on_block_parse_error(){
   }) : () -> ()
   return
 }
+
+// -----
+
+// Auto-constructing a missing implicit terminator must not crash.
+func.func @cse_of_single_block_op_no_terminator() {
+  %0 = test.cse_of_single_block_op inputs() {
+  } // expected-error {{expected ':'}}
+}
diff --git a/mlir/test/lib/Dialect/Test/TestOps.td b/mlir/test/lib/Dialect/Test/TestOps.td
index 492cd44833380..3b6a45a58ff94 100644
--- a/mlir/test/lib/Dialect/Test/TestOps.td
+++ b/mlir/test/lib/Dialect/Test/TestOps.td
@@ -2653,9 +2653,7 @@ def RegionYieldOp : TEST_Op<"region_yield",
   let assemblyFormat = [{
     $result `:` type($result) attr-dict
   }];
-  let builders = [OpBuilder<(ins),
-    [{ build($_builder, $_state, {}); }]>
-  ];
+  let builders = [OpBuilder<(ins), [{ /* nothing to do */ }]>];
 }
 
 class BufferBasedOpBase<string mnemonic, list<Trait> traits>



More information about the Mlir-commits mailing list