Skip to content

A foreach value over an untyped element, narrowed by instanceof then rebound to an object in else, fails MIR.verify ownflow (obj vs mixdead) #160

Closed

Description

@blacktrs

Summary

A foreach value over an untyped element, narrowed by instanceof then rebound to an object in else, fails MIR.verify ownflow (obj vs mixdead).

Repro

<?php
class D { public function __construct(public $p = null) {} public function g(): string { return 'D'; } }
class CD extends D {}
function f(array $items): string {
    $out = '';
    foreach ($items as $providers) {
        $adapter = new D();
        foreach ($providers[0] as $adapter) {
            if ($adapter instanceof CD) {
                $c = 1;
            } else {
                $adapter = new CD($adapter);
            }
        }
        $out .= $adapter->g();
    }
    return $out;
}
echo f([[new D, new CD]]), "\n";

Expected (php)

D

Actual (manticore d3fbe1c2, Darwin arm64)

compile failed (rc=65):
compile failed: MIR.verify: ownflow: $adapter read at line 16 in f past a representation mismatch (obj vs mixdead): the name is live there
compile: front-end (parse/typeck/IR) returned null (rc=65)

Tracking

Known-bug repro: tests/aot/repro/crash/foreach_erased_value_narrowed_then_rebound_ownflow.php — bash tests/aot/xfail.sh -k foreach_erased_value_narrowed_then_rebound_ownflow reports XFAIL while this is open and XPASS once it is fixed; then move the repro into tests/aot/cases/ and close this issue.

Activity

  1. added
    bug
    crash
    on Oct 9, 2026
  2. blacktrs commented on Oct 9, 2026

    @blacktrs
    ContributorAuthor

    Diagnosis (from MANTICORE_OWN_TRACE on symfony CachePoolPass::process, where this blocks building a symfony app):

    • the foreach value var over an erased element is bound Scalar (OwnershipFlow::bindBorrow, no flavor key for unknown);
    • instanceof CD narrows it to obj<CD> in the then-arm, so InferTypes::planMergeShadow sees obj vs obj and plants no box-back;
    • the else-arm stores a fresh Own(obj); OwnLattice::meet(Own, Scalar) -> MixDead, and the read after the loop is a deadRead.

    Binding the element as Borrow(<name's obj key>) would let the existing Borrow/Own join (own_retain on the borrowed edge) settle it, but retains an erased word as an object, which is only safe where the word passed the instanceof. Needs a decision, not a blind patch.

  3. blacktrs commented on Oct 9, 2026

    @blacktrs
    ContributorAuthor

    Tried binding the erased element as Borrow(obj) when every other store of the name is an object. Unsound: the repro then compiles but dies at run time (SIGUSR1) — the join's own_retain runs on a non-object word (null from an object's property). The fix has to be at the type level instead: the instanceof narrowing hides the unknown-vs-obj disagreement from InferTypes::planMergeShadow, so no box-back is planted.

  4. blacktrs commented on Oct 9, 2026

    @blacktrs
    ContributorAuthor

    Type-level attempt: planting the box-back against the pre-narrowing slot type (so the instanceof-narrowed then-arm no longer hides unknown/cell vs obj) is not enough — the plant is dropped again on a later InferTypes run and the final MIR has no box-back. The real value at the foreach (symfony: elements of an erased array) is a decoded cell, the else-arm stores a raw obj pointer: two representations in one slot, which is a miscompile risk beyond the verifier message. Needs a look at loopMerge / unplantAgreedBoxBacks together with the instanceof narrowing.

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

    bugcrash

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions