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

llvmlistbot at llvm.org llvmlistbot at llvm.org
Thu Jun 18 00:14:18 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-mlir

Author: Prem C (silent-bytesmith)

<details>
<summary>Changes</summary>

Fixes #<!-- -->203860 

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.

---
Full diff: https://github.com/llvm/llvm-project/pull/204521.diff


2 Files Affected:

- (modified) mlir/include/mlir/Interfaces/LoopLikeInterface.td (+2-1) 
- (modified) mlir/test/Conversion/FuncToLLVM/func-to-llvm.mlir (+9) 


``````````diff
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..a0603dcf21dd2 100644
--- a/mlir/test/Conversion/FuncToLLVM/func-to-llvm.mlir
+++ b/mlir/test/Conversion/FuncToLLVM/func-to-llvm.mlir
@@ -583,3 +583,12 @@ module attributes {transform.with_named_sequence} {
     transform.yield
   }
 }
+
+// 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
+}
+

``````````

</details>


https://github.com/llvm/llvm-project/pull/204521


More information about the Mlir-commits mailing list