Repository navigation
A temporary a finally reads is released after the finally - #650
Merged
Merged
Conversation
`const v = mv(); try { if (c) continue; } finally { s += v.get(); }`: a
folded const (a call's result named by a const) is released where its
block ends, and in front of each break, continue or return that leaves
the block early. That release ran before the finally the jump goes
through, and the finally then read a freed block. #600 fixed the same
for locals in slots; a folded const is released by
releaseDiscardedTemporaries instead.
When a finally between the jump and the temporary's block reads it, the
release now goes at the end of the outermost such finally, in a ts.If
tagged with the jump (JUMP_ONLY_ATTR_NAME, RETURN_ONLY_ATTR_NAME), so
TryOpLowering keeps it in that jump's copy of the finally alone - the
scheme MLIRGen uses for the scopes the jump leaves. Jumps with one key
share one copy and get one release. Fuzzer (#646) R6, rc.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`for (..) { const v = mv(); try { try { continue; } finally { break; } }
finally {} }`: the temporary was released in front of the `continue`,
and again in front of the `break` its finally then took. The release
for a jump that passes through a finally now always goes at the end of
the outermost such finally, tagged with the jump, not only when the
finally reads the temporary: a finally that leaves by a jump of its own
never reaches it, and the jump's own release is then the only one.
Fuzzer (#646), found past the first 1000 programs.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ASDAlexander77
added a commit
that referenced
this pull request
Oct 23, 2026
…nt-slot-assigned Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes fuzzer bug R6 (#646): a
break,continueorreturnout of atry, when thefinallyreads a const of the enclosing block.Why
const v = mv(6)is a folded const: the call's result is named directly, with no slot.releaseDiscardedTemporariesreleases it where its block ends, and before eachbreak,continueorreturnthat leaves the block early. That release ran before the finally the jump goes through, so the finally read a freed block. #600 fixed this for locals that live in slots (finallyGuardScope+mlirGenScopeExitAfterFinally), but folded consts are released by this pass instead, which knew nothing about finallys.Fix
When a jump passes through a finally between it and the temporary's block, the release moves to the end of the outermost such finally (the last one the jump runs). It goes inside a
ts.If truetagged for that jump (JUMP_ONLY_ATTR_NAMEwithbreak:/continue:+ label, orRETURN_ONLY_ATTR_NAME). TryOpLowering already keeps such a group only in that jump's copy of the finally, so this reuses MLIRGen's scheme for slot locals. Jumps with the same key share one copy, so each gets one release. A jump that passes through no finally is unchanged.The release moves even when no finally reads the temporary (follow-up commit 4d07298). A finally that leaves by a jump of its own (
try { continue; } finally { break; }) never reaches the end of the finally, and the jump's own release is then the only one. Before, the temporary was released in front of thecontinueand again in front of thebreak. The fuzzer found this past its first 1000 programs, andjumpInFinallyin the test covers it.The pass runs in every memory model, so this also fixes the own forms of R6 (
R6-minimal,R6-own,R6-call-in-finallycrashed under own as well).Tests
tests/00temporary_read_in_finally.tscovers:continueandbreakthrough a finallycontinues through one finallycontinuethrough two nested finallysreturnthrough a finallyIt runs compiled, under JIT, and in the rc/none corpus, and it crashes under rc on Linux without the fix. The ownership verifier (
--verify-ownership) reports no errors on it.Verification
ctest -C Release: Windows 4982/4982, WSL Linux 4964/4964.mm_fuzz.py --jobs 10 run --count 500 --seed 1: only the 3 known own failures (R1, O4).🤖 Generated with Claude Code