[Mlir-commits] [mlir] [MLIR] Fix crash in int-range-optimizations on type-mismatched IR (PR #183964)

Mehdi Amini llvmlistbot at llvm.org
Sun Mar 1 04:04:17 PST 2026


================
@@ -148,3 +148,41 @@ func.func @analysis_crash(%arg0: i32, %arg1: tensor<128xi1>) -> tensor<128xi64>
   %2 = arith.extsi %1 : tensor<128xi32> to tensor<128xi64>
   return %2 : tensor<128xi64>
 }
+
+// -----
+
+// Regression test for https://github.com/llvm/llvm-project/issues/74234
+// Verifies no crash when interprocedural range propagation encounters a callee
+// whose return operand type differs from the function's declared return type,
+// causing a bit-width mismatch in the inferred ranges.
+
+// CHECK-LABEL: @issue74234_callee
+func.func private @issue74234_callee() -> index {
+  %c30 = arith.constant 30 : index
+  %2 = builtin.unrealized_conversion_cast %c30 : index to i32
+  llvm.return %2 : i32
----------------
joker-eph wrote:

I tried to implement the verifier on func.func, but many tests are failing. For example this one:

```
// BAREPTR-LABEL: func @check_return(
// BAREPTR-SAME: %{{.*}}: memref<?xi8>) -> memref<?xi8>
func.func @check_return(%in : memref<?xi8>) -> memref<?xi8> {
  // BAREPTR: llvm.return {{.*}} : !llvm.struct<(ptr, ptr, i64, array<1 x i64>, array<1 x i64>)>
  return %in : memref<?xi8>
}
```

```
bin/mlir-opt -convert-func-to-llvm='use-bare-ptr-memref-call-conv=1'  ../mlir/test/Conversion/FuncToLLVM/func-memref-return.mlir  --mlir-print-ir-after-all --debug
```

```
...
[pattern-application PatternApplicator.cpp:209 1] Trying to match "(anonymous namespace)::FuncOpConversion"
[dialect-conversion:1]     ** Failure : signature conversion failed
[dialect-conversion:1]     ** Failure : Could not convert funcop
[pattern-application PatternApplicator.cpp:224 1]  -> matchAndRewrite failed
...
mlir/test/Conversion/FuncToLLVM/func-memref-return.mlir:6:3: error: type of return operand 0 ('!llvm.struct<(ptr, ptr, i64, array<1 x i64>, array<1 x i64>)>') doesn't match function result type ('memref<?xi8>') in function @check_return
  return %in : memref<?xi8>
  ^
mlir/test/Conversion/FuncToLLVM/func-memref-return.mlir:6:3: note: see current operation: "llvm.return"(%0) : (!llvm.struct<(ptr, ptr, i64, array<1 x i64>, array<1 x i64>)>) -> ()
// -----// IR Dump After ConvertFuncToLLVMPass Failed (convert-func-to-llvm) //----- //
type of return operand 0 ('!llvm.struct<(ptr, ptr, i64, array<1 x i64>, array<1 x i64>)>') doesn't match function result type ('memref<?xi8>') in function @check_return
[mlir-asm-printer AsmPrinter.cpp:2107 1] builtin.module' failed to verify and will be printed in generic form
"builtin.module"() ({
  "func.func"() <{function_type = (memref<?xi8>) -> memref<?xi8>, sym_name = "check_return"}> ({
  ^bb0(%arg0: memref<?xi8>):
    %0 = "builtin.unrealized_conversion_cast"(%arg0) : (memref<?xi8>) -> !llvm.struct<(ptr, ptr, i64, array<1 x i64>, array<1 x i64>)>
    "llvm.return"(%0) : (!llvm.struct<(ptr, ptr, i64, array<1 x i64>, array<1 x i64>)>) -> ()
  }) : () -> ()
}) : () -> ()

```

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


More information about the Mlir-commits mailing list