[Mlir-commits] [mlir] [mlir][CFGToSCF] Fix crash when encountering unknown control flow ops (PR #184103)
Markus Böck
llvmlistbot at llvm.org
Tue Mar 3 08:07:47 PST 2026
================
@@ -1156,8 +1156,18 @@ static FailureOr<SmallVector<Block *>> transformToStructuredCFBranches(
FailureOr<Operation *> result = interface.createStructuredBranchRegionOp(
opBuilder, regionEntry->getTerminator(),
continuation->getArgumentTypes(), conditionalRegions);
- if (failed(result))
+ if (failed(result)) {
+ // Blocks were moved from the parent region into conditionalRegions before
+ // calling createStructuredBranchRegionOp. On failure, move them back to
+ // avoid use-after-free crashes: the moved blocks may still be referenced
+ // as successors by blocks remaining in the parent region, so destroying
+ // conditionalRegions with live uses would trigger an assertion.
----------------
zero9178 wrote:
It might be worth mentioning here that this is not meant to make the code correct or undo the change but rather just to allow the pass to fail gracefully and not crash
https://github.com/llvm/llvm-project/pull/184103
More information about the Mlir-commits
mailing list