[Mlir-commits] [mlir] [mlir][Inliner] Fix crash when inlining callee without terminator (PR #173665)

Suriyaa MM llvmlistbot at llvm.org
Fri Dec 26 06:24:12 PST 2025


https://github.com/SuriyaaMM created https://github.com/llvm/llvm-project/pull/173665

Fix for [#173561](https://github.com/llvm/llvm-project/issues/173561).

`call.erase()` would `segfault` previously if not all uses are replaced. 

>From 63dee23ca0cf334b967c6d7b1002ba535099dea9 Mon Sep 17 00:00:00 2001
From: SuriyaaMM <suriyaamm.2705 at gmail.com>
Date: Fri, 26 Dec 2025 19:41:39 +0530
Subject: [PATCH] [mlir][Inliner] Fix crash when inlining callee without
 terminator

---
 mlir/lib/Transforms/Utils/Inliner.cpp | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/mlir/lib/Transforms/Utils/Inliner.cpp b/mlir/lib/Transforms/Utils/Inliner.cpp
index 40950312d566f..b3a0994f2070a 100644
--- a/mlir/lib/Transforms/Utils/Inliner.cpp
+++ b/mlir/lib/Transforms/Utils/Inliner.cpp
@@ -682,7 +682,14 @@ Inliner::Impl::inlineCallsInSCC(InlinerInterfaceImpl &inlinerIface,
     useList.mergeUsesAfterInlining(it.targetNode, it.sourceNode);
 
     // then erase the call.
-    call.erase();
+    if (call.getOperation()->use_empty()) {
+      call.erase();
+    } else {
+      LDBG() << "CallOpInterface is still in use. call = " << call
+             << " returning failure";
+      call->emitError("not all uses of call were replaced");
+      return failure();
+    }
 
     // If we inlined in place, mark the node for deletion.
     if (inlineInPlace) {



More information about the Mlir-commits mailing list