Repository navigation
Conversation
added 2 commits
October 3, 2026 10:22
… a use after drop (#1991) #1991's stage1-only "index out of bounds" in math_fn_arity was the pre-#1968 lowering in the old pinned seed (nightly-20260929, 8f84428): `let t = math_fn_table(); t[id].arity` lowered to `drop(_2); _0 = copy _2[_4].f`. The seed-built stage1's machine code frees the Vec and then panics on every path (the optimizer folded the cleared length into the bounds check), and the seed's own `check --validate-all` said ok: the drop-state lattice marks a dropped place Uninit, like StorageDead, and judges only whole-local reads of Maybe places, never a projection. validate_read_after_drop: a forward must-analysis of the locals every path has whole-dropped (Drop, drop-and-goto) and nothing rewrote (whole Assign, StorageLive, call destination). A value read of such a local, whole or through a projection, in a statement or a terminator operand is refused. Swept with stage1 `check --validate-all` over test/behavior, test/phase and test/spec (2049 files): one hit, a real one (behav_c_facade_resource_drop_once: `drop(_1); _0 = copy _1.repr`), fixed in the next commit. test/internals/mir_read_after_drop_test.w builds the MIR directly (fails with the call removed): read after drop, after a drop-and-goto, as a call argument; clean for read-before-drop, drop-rewrite-read, and a drop on one arm only.
…ck drops reads before the drop (#1991) The read-after-drop validator named `fn scope() -> *mut db: let d = Database.new(1).unwrap(); d.repr` in behav_c_facade_resource_drop_once: `drop(_1); _0 = copy _1.repr`. materialize_tail_read_of_dropped_local (#1968) left a TY_PTR tail lazy beside a TY_REF one, but a raw pointer is a value the place stores, not a view of the place: `let t = rows(); t[0].p` read the freed Vec and panicked "index out of bounds" with the release compiler. Only a view-typed tail stays lazy now. test/behavior/behav_1991_tail_pointer_field_read_before_drop.w panics on the installed release compiler and passes under the stage1 built from this tree; the facade fixture now passes validate-all.
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.
Closes #1991.
Root cause (#1991). The stage1-only panic was the pre-#1968 lowering in the old pinned seed (nightly-20260929,
v0.15.3.0-g8f84428e5, digest 8c5a151d…). 9a73f74 changedmath_fn_aritytolet t = math_fn_table(); t[id].arityand fixed the lowering in the same commit, but the seed that built stage1 still had the bug. Under that seed the MIR isdrop(_2); _0 = copy _2[_4].f. In the stage1 it built (impl-1930's stage1, 04:46),math_fn_arity's machine code frees the Vec and then callswith_panic_refon every path:+164 bl with_vec_free_buffer_drop_origin, then+196 bl with_panic_ref/brk. There is no path that returns. Stage2 and the release are built by stage1's fixed lowering, so they are correct. With the current seed (nightly-20261003, c884c1c, which has 9a73f74), stage1'smath_fn_aritychecks the bounds, reads, drops and returns. All four fixtures named in the issue pass under it. No source change was needed for #1991 itself.Why no tool caught it. The old seed's
check --validate-allreportedokon exactly that MIR. The drop-state lattice marks a dropped place Uninit, the same as StorageDead. Its only read rule judges whole-local reads of Maybe places and never looks at a projection. Separately, no lane runs a stage1, the seed-built compiler, over a corpus. Stage1 only has to compile stage2, and fixpoint compares stage2 with stage3.This PR
validate_read_after_drop(MirCore, part of validate-ownership/validate-all/audit). It runs a forward must-analysis over locals that every path has whole-dropped and that nothing rewrote. A value read of such a local, whole or through a projection, is refused.test/internals/mir_read_after_drop_test.wbuilds the MIR directly and fails when the validator is removed. Sweeping stage1check --validate-allover test/behavior + test/phase + test/spec (2049 files) found one hit, and it is a real bug (2).materialize_tail_read_of_dropped_localleft aTY_PTRtail lazy, the same as a&Tview. A raw pointer is a value the place stores, not a view of the place, solet t = rows(); t[0].pread the freed Vec. This panics with the release compiler. Inbehav_c_facade_resource_drop_once,scope()/early()lowered todrop(_1); _0 = copy _1.repr. New fixture:test/behavior/behav_1991_tail_pointer_field_read_before_drop.w(panics on the installed release, passes on this tree's stage1).Evidence:
src/main build :gategreen;:deep-debug-tool-tests --no-depsgreen;:drop-audit254 cells, 0 regressions; the 215 behavior fixtures that use raw pointers pass under stage1.