Skip to content

validate-ownership is silent on a move out of an already-moved place (guarded match arm double free passed) #1414

Closed

Description

@ehartford

Found during #1394. On origin/main (dd786a4):

fn get() -> Option[Vec[i32]]: ...   // 100 elements
match get():
    Some(v) if v.len() > 500 => print("long")
    Some(v) => print(v.len())
    None => ...

The guarded arm binds _5 = move _3<as v0>.f0, the guard fails and drops _5, and the next arm binds _12 = move _3<as v0>.f0 again: run --debug-alloc reports DOUBLE FREE (size=512 origin=Vec). --validate-all said ok. The #1394 PR fixes the lowering (a failed guard moves its bindings back into the subject), but the validator still has no rule for it.

The natural rule — reject an OK_MOVE of a drop-bearing place whose drop state is Moved or Maybe — was tried in the #1394 branch and reverted: the drop-state lattice's Maybe is the join of any two different states, so it conflates "moved on some path" with "uninitialized on some path". It fired on every match result temp (_16 = move _18 in one arm, the unreachable no-arm path leaves _16 Uninit, then _14 = move _16 at the join) and on prelude bodies. The rule needs a lattice that keeps maybe-moved distinct from maybe-uninit (or a separate may-moved bit), then the check. Coordinate with #1353 (drop-state storage).

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