[Mlir-commits] [mlir] [mlir][CSE] fix use-after-free (PR #203849)
Mehdi Amini
llvmlistbot at llvm.org
Mon Jun 15 03:57:16 PDT 2026
================
@@ -162,6 +162,11 @@ void CSEDriver::replaceUsesAndDelete(ScopedMapTy &knownValues, Operation *op,
if (isa<UnknownLoc>(existing->getLoc()) && !isa<UnknownLoc>(op->getLoc()))
existing->setLoc(op->getLoc());
+ // Deletion of the dead current op can only be done here, and not before,
+ // because the its location is still read above.
+ if (opIsDead)
+ eraseDeadOp(op);
+
----------------
joker-eph wrote:
Instead of delaying the erasure, seem to me we can move the location assignment earlier instead? (and the `++numCSE;` as well.
Also adding early returns immediately after the erasure would make the control flow more clear.
I think we can just remove the `else` (no else after return) then.
https://github.com/llvm/llvm-project/pull/203849
More information about the Mlir-commits
mailing list