[Mlir-commits] [mlir] [mlir] Handle null region in LoopLikeOpInterface::isDefinedOutsideOfLoop (PR #204521)

Prem C llvmlistbot at llvm.org
Sat Jun 20 00:49:38 PDT 2026


https://github.com/silent-bytesmith updated https://github.com/llvm/llvm-project/pull/204521

>From bb3d6a00994cffb3112b7ea81a2d2676e7dde52a Mon Sep 17 00:00:00 2001
From: silent-bytesmith <cpgh at google.com>
Date: Wed, 17 Jun 2026 23:35:28 -0700
Subject: [PATCH] [mlir] Handle null region in
 LoopLikeOpInterface::isDefinedOutsideOfLoop

In LoopLikeOpInterface::isDefinedOutsideOfLoop default implementation,
value.getParentRegion() can return null during signature conversion
rollbacks when blocks/ops are unlinked. Check for null region to avoid
a segmentation fault.

Also, add a regression test for convert-func-to-llvm with index-bitwidth=32
on functions with affine.for loops.

Assisted-by: Antigravity
---
 mlir/include/mlir/Interfaces/LoopLikeInterface.td |  3 ++-
 mlir/test/Conversion/FuncToLLVM/func-to-llvm.mlir | 15 +++++++++++++++
 2 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/mlir/include/mlir/Interfaces/LoopLikeInterface.td b/mlir/include/mlir/Interfaces/LoopLikeInterface.td
index 5fb897339ffde..2dc17c8950e62 100644
--- a/mlir/include/mlir/Interfaces/LoopLikeInterface.td
+++ b/mlir/include/mlir/Interfaces/LoopLikeInterface.td
@@ -62,7 +62,8 @@ def LoopLikeOpInterface : OpInterface<"LoopLikeOpInterface"> {
       /*args=*/(ins "::mlir::Value ":$value),
       /*methodBody=*/"",
       /*defaultImplementation=*/[{
-        return !$_op->isAncestor(value.getParentRegion()->getParentOp());
+        ::mlir::Region *region = value.getParentRegion();
+        return !region || !$_op->isAncestor(region->getParentOp());
       }]
     >,
     InterfaceMethod<[{
diff --git a/mlir/test/Conversion/FuncToLLVM/func-to-llvm.mlir b/mlir/test/Conversion/FuncToLLVM/func-to-llvm.mlir
index 94dfceadbc449..6a04960e3513a 100644
--- a/mlir/test/Conversion/FuncToLLVM/func-to-llvm.mlir
+++ b/mlir/test/Conversion/FuncToLLVM/func-to-llvm.mlir
@@ -583,3 +583,18 @@ module attributes {transform.with_named_sequence} {
     transform.yield
   }
 }
+
+// During signature conversion with index-bitwidth=32, pattern rollback can
+// unlink blocks/ops from their regions. If loop-like operations are folded
+// in this state, querying `isDefinedOutsideOfLoop` on block arguments
+// of unlinked blocks would previously dereference a null parent region pointer
+// and crash.
+// See: https://github.com/llvm/llvm-project/issues/203860
+// CHECK32-LABEL: llvm.func @affine_for_index_bitwidth_32
+func.func @affine_for_index_bitwidth_32(%arg0: index, %arg1: index, %arg2: index, %arg3: index) {
+  %0 = affine.for %arg4 = 0 to 101 iter_args(%arg5 = %arg1) -> (index) {
+    affine.yield %arg3 : index
+  }
+  return
+}
+



More information about the Mlir-commits mailing list