You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
MIR: statement temps materialized inside a zero-iteration loop body drop at the join — uninitialized stack slot freed as a str (#729 residue; release-lane c_import SEGV root cause) #771
In Zcu.c_import_cache_key_frontend, codegen emits a str-temp drop (glue 'drop#struct __drop_struct_16') at the exit/join of the owns/borrows concat loops. The temp is materialized INSIDE the loop body; on a ZERO-ITERATION run the drop still executes, freeing whatever the never-initialized stack slot (sp+0x210 in the release binary) holds. At -O1 that slot contains the dead frame of the immediately-preceding record_frontend_tracked_input call — insert_unique's sret Vec header — so the 'str free' lands on the TRACKED-INPUT VEC'S LIVE BUFFER.
This is behav_branch_temp_drop_not_taken_path's class (#729) in its loop/zero-iteration shape, alive in the compiler itself.
Crash: str_byte_at_ref dereferencing quoted-path text as a header; caller tracked_input_str_compare (x30; bt unwind broken).
Crash memory: vec element slots hold '"/Users/…' path TEXT spanning two slots; later slots hold intact stale headers — buffer freed + partially recycled by a string alloc.
Time bisection: address zeroed at expand_c_imports_frontend entry; crash before Sema.
Hardware watchpoint on the block header (payload-16):
alloc: vec_grow ← with_vec_push ← tracked_input_insert_unique ← record_frontend_tracked_input (the block IS the tracked vec buffer)
reuse: alloc_str ← c_import_trim (the recycler that plants the text)
WITH_ALLOC_NO_REUSE=1: compile prints 'ok' then 'invalid free … origin=drop#struct __drop_struct_470' from Compilation's exit glue — the SECOND free of the same block, proving the vec still owned it when free Type resolution corruption when single source file exceeds ~14K lines #1 fired.
Disassembly at the free site: add x0, sp, #0x210 → bl with_str_free_drop_origin, origin constant 'drop#struct __drop_struct_16' (str's own glue); the site sits between the owns-loop back-edge (b.vc +1228) and the borrows loop — the loop-exit drop of a body-materialized temp.
Why each lane behaves as it does
Release binary (flip codegen): drops are real → frees live heap through stack garbage → UAF/SEGV on every c_import (tracked-input recording is c_import's hot path).
Seed-compiled stage1: pre-flip Copy world emits NO temp drops — the path is structurally absent → lane green.
Why the drop-audit matrix missed it: cells cover branch taken/untaken and loops that RUN; the zero-iteration × -O1-slot-overlay cell isn't in the matrix, and the misfree usually hits the rt_payload_start_can_be_owned guard silently.
Fix direction
MirLower: a stmt temp materialized inside a conditional region (loop body, arm) must drop INSIDE that region or carry a drop-flag guard — extend the #729 fix's scope to loop bodies (register_stmt_temp/schedule placement). Ownership-class change → its own :move-audit/:drop-audit-bracketed batch, plus a drop-audit cell for the zero-iteration loop shape.
Blocks the reseed (this defect is why the release lane is red — #761's remaining class). Prior suspects (unspelled field captures, fixed in ee33341 and the Sema/CodegenTraits siblings) were real hygiene bugs but NOT this root; Compilation's var-zcu pattern is exonerated.
Fixed in c1f4985 (+ dd66426 for the formatter-temp residue it unmasked). All 12 loop-body lowerings now frame their statement temps (drop inside the body, per iteration); the four fmt helpers register their owned results. Bracket battery: fixpoint ✓ move-audit ✓ drop-audit ✓ debug-alloc 65 PASS (da_loop_body_stmt_temp_zero_and_n pins both shapes: zero-iteration misdrop + per-iteration leak — pre-fix leak count=7, post-fix 0). Release lane: behav_c_import_offsetof and the single_tiny/single_stdint repros healed. Remaining release-lane crashes are SEPARATE instances (first: UAF read at cimport_deps_sorted_unique_paths+176, fault on a freed-header data pointer; also issue114's interior-NUL panic) — tracked on #761 with the established watchpoint protocol.
Activity
sema/codegen-traits: spell move on the remaining tracked-input captur…
ehartford commentedon Aug 13, 2026
Fixed in c1f4985 (+ dd66426 for the formatter-temp residue it unmasked). All 12 loop-body lowerings now frame their statement temps (drop inside the body, per iteration); the four fmt helpers register their owned results. Bracket battery: fixpoint ✓ move-audit ✓ drop-audit ✓ debug-alloc 65 PASS (da_loop_body_stmt_temp_zero_and_n pins both shapes: zero-iteration misdrop + per-iteration leak — pre-fix leak count=7, post-fix 0). Release lane: behav_c_import_offsetof and the single_tiny/single_stdint repros healed. Remaining release-lane crashes are SEPARATE instances (first: UAF read at cimport_deps_sorted_unique_paths+176, fault on a freed-header data pointer; also issue114's interior-NUL panic) — tracked on #761 with the established watchpoint protocol.
mir: loop-body statement temps drop inside the body (#771 — release-l…
mir: register formatter result temps — interpolated non-str values le…
docs: handoff — #771 fixed and blessed; instance-2 (argument-temp gar…
select await takes each task once per arm path; arm temporaries drop …
select await takes each task once per arm path; arm temporaries drop …
select await takes each task once per arm path; arm temporaries drop …
select await takes each task once per arm path; arm temporaries drop …
Cancellation: indirect callees that may suspend get the cancelled-ret…