Skip to content

std.build audit:all reports use-after-kill in seven move-self builder fns (reset-on-move blank ordering) #927

Closed

Description

@ehartford

Found during #921 while hunting the (now fixed, 1c50ae4) accessor borrow-return miscompile. with analyze lib/std/build.w audit:all fails with 11 violations — 7 use-after-kill plus 4 effect-fixpoint edges:

violation: use-after-kill: ProcessEnv.set: local _1 is read at bb0 after its reset-on-move blank zeroed it
violation: use-after-kill: ToolFs.read_binary: local _7 is read at bb5 ...
violation: use-after-kill: tool_process_apply_env: local _7 is read at bb5 ...
violation: use-after-kill: Target.with_env: local _1 is read at bb0 ...
violation: use-after-kill: Build.generated_source: local _1 is read at bb0 ...
violation: use-after-kill: Build.download: local _7 is read at bb7 ...
violation: use-after-kill: Target.compiler: local _1 is read at bb0 ...
violation: effect edge sig 389:1 -> 376:6 is not at fixpoint; missing=4  (+3 more)

All seven share the D32 rebind idiom: move self → var owned = self → owned.vecfield.push(<literal/concat>) → owned. The minimal same-shape repro (Env.set clone with a 2-field struct) reproduces the violation under analyze but behaves CORRECTLY at runtime — so this is either (a) an audit false-positive on the _4 = move _1; _1 = zst + later StorageDead(_1) pattern (StorageDead counted as a read), or (b) a real latent mis-scheduling that current codegen happens to tolerate (StorageDead is a codegen no-op today). Note the related real oddity seen in the same MIR: StorageDead(_4) is emitted BEFORE _0 = move _4 in the return block — harmless today only because codegen ignores StorageDead; any future lowering of Storage markers to llvm.lifetime intrinsics would turn it into a genuine use-after-end.

Wanted: rule which of (a)/(b) holds, fix the audit or the ordering accordingly, and get analyze lib/std/build.w audit:all green — it's the natural proof gate for the #921 runner's std.build surface. The effect-fixpoint edges need their own look.

Repro: ./out/stage/bin/with-stage2 analyze lib/std/build.w audit:all
Minimal: 10-line Env.set clone (violation fires, runtime correct).

Activity

  1. ehartford commented on Sep 2, 2026

    @ehartford
    ContributorAuthor

    Fixed across be015f4 and 1f8c… (the two commits after it): analyze lib/std/build.w audit:all now reports 0 violations (was 11 when filed, 12 by the time of the fix).

    • The seven (then eight) use-after-kill findings were a validator bug, not the builders: validate_use_after_kill_body read rval_d0 as an operand for every rvalue kind, but for an aggregate that slot is the aggregate kind, so operand 0 of the body — the moved self in every D32 rebind builder — was reported read after its blank whenever an aggregate/binop/ref followed the blank. It now enumerates each rvalue's value operands per kind (mir_rvalue_read_locals). Same bug behind all 128 of audit:all fails on src/main.w: 129 violations (127 use-after-kill + 2 frozen-phase re-entries) — grown from 48; needs a dedicated drain #742's use-after-kill findings. A minimal aggregate-after-blank rebind is now a deep-debug fixture expected to audit clean.
    • The four effect-edge fixpoint findings were the audit disagreeing with the fixpoint's own D17 rule: the solver demotes consume/escape to write across a non-Copy field-projection edge (spec.env into a consuming parameter), and audit:effects recomputed the transfer without that rule. effect_edge_transfer is now the one rule both read.

    The blank-ordering observation in the title (StorageDead(_4) emitted before _0 = move _4 in the return tail) is real but cosmetic — StorageDead is a codegen no-op and the validator treats it as a marker — and is not part of this fix.

    Batteries green; reseeded.

  2. ehartford commented on Sep 2, 2026

    @ehartford
    ContributorAuthor

    Correction to the close note: the two commits are be015f4 (use-after-kill validator) and 75cfc03 (shared effect-edge transfer rule). The "1f8c…" placeholder above was a typo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions