Skip to content

$a[$k] ??= $c ? $n->prop : f($n) SIGSEGVs once a later inference run erases $n to a cell. #502

Closed

Description

@blacktrs

Summary

$a[$k] ??= $c ? $n->prop : f($n) SIGSEGVs once a later inference run erases $n to a cell.

Repro

<?php
// The `??=` value block kept the type it adopted on the first InferTypes run (obj) while its
// last node became a cell, so the arm boxed the cell word as an object pointer.
final class Span { public function __construct(public int $a) {} }
final class Lit { public function __construct(public Span $span) {} }
final class Call {
    /** @param Lit[] $args */
    public function __construct(public array $args) {}
}
final class Idx {
    /** @var array<string, Span> */
    private array $m = [];
    private static function fresh(Lit $n): Span { return new Span($n->span->a + 100); }
    public function add(string $k, Call $c, bool $low): void {
        $lit = $c->args[0];
        $this->m[$k] ??= $low ? $lit->span : self::fresh($lit);
        $x = ($this->m[$k . '!'] ??= match ($low) { true => $lit->span, false => self::fresh($lit) });
        echo $k, ' ', $x->a, "\n";
    }
    public function dump(): void { foreach ($this->m as $k => $s) { echo $k, ' ', $s->a, "\n"; } }
}
$ix = new Idx();
for ($i = 0; $i < 6; $i++) {
    // The second element is not a Lit: the property's element type is erased only once the
    // call sites are re-inferred.
    $ix->add('k' . ($i % 4), new Call([new Lit(new Span($i)), $i > 100 ? "x" : $i]), $i % 2 === 0);
}
$ix->dump();

Expected (php)

k0 0
k1 101
k2 2
k3 103
k0 0
k1 101
k0 0
k0! 0
k1 101
k1! 101
k2 2
k2! 2
k3 103
k3! 103

Actual (manticore babf5bee, Darwin arm64)


[exit code 139 — SIGSEGV]

Tracking

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

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