[llvm-branch-commits] [mlir] [mlir][Transforms] Fix crash in `-remove-dead-values` on private functions (PR #169269)

Mehdi Amini via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Fri Nov 28 01:35:27 PST 2025


================
@@ -786,9 +824,14 @@ static void cleanUpDeadVals(RDVFinalCleanupList &list) {
 
   // 3. Operations
   LDBG() << "Cleaning up " << list.operations.size() << " operations";
-  for (auto &op : list.operations) {
+  for (Operation *op : list.operations) {
     LDBG() << "Erasing operation: "
            << OpWithFlags(op, OpPrintingFlags().skipRegions());
+    if (op->hasTrait<OpTrait::IsTerminator>()) {
+      // When erasing a terminator, insert an unreachable op in its place.
+      OpBuilder b(op);
+      ub::UnreachableOp::create(b, op->getLoc());
+    }
----------------
joker-eph wrote:

```suggestion
    // When erasing a terminator, insert an unreachable op in its place.
    if (op->hasTrait<OpTrait::IsTerminator>())
      ub::UnreachableOp::create(OpBuilder{op}, op->getLoc());
```

Nit: simplifying a bit.

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


More information about the llvm-branch-commits mailing list