Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 62 additions & 5 deletions lib/Compiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -27185,11 +27185,27 @@ protected function compileCallArgSends(
}
}
if (null !== $cfgCallOp && null !== $block->orig) {
$trailingProducers = $this->precedingInlineCallArgProducersBeforeCfgOp(
$block->orig->children,
$cfgCallOp
);
$trailingComparisonProducer = $trailingProducers[\count($trailingProducers) - 1] ?? null;
$trailingComparisonProducer = null;
$cfgCallIndex = null;
foreach ($block->orig->children as $ci => $cfgChild) {
if ($cfgChild === $cfgCallOp) {
$cfgCallIndex = $ci;
break;
}
}
if (null !== $cfgCallIndex && $cfgCallIndex > 0) {
$immediatePrelude = $block->orig->children[$cfgCallIndex - 1] ?? null;
if ($this->isComparisonInlineCallArgProducer($immediatePrelude)) {
$trailingComparisonProducer = $immediatePrelude;
}
}
if (null === $trailingComparisonProducer) {
$trailingProducers = $this->precedingInlineCallArgProducersBeforeCfgOp(
$block->orig->children,
$cfgCallOp
);
$trailingComparisonProducer = $trailingProducers[\count($trailingProducers) - 1] ?? null;
}
$comparisonFeedsCallArg = $this->isComparisonInlineCallArgProducer($trailingComparisonProducer);
if (
$comparisonFeedsCallArg
Expand All @@ -27198,6 +27214,12 @@ protected function compileCallArgSends(
&& null !== $trailingComparisonProducer->result
) {
$comparisonSlot = $block->slotForOperand($trailingComparisonProducer->result);
if (null === $comparisonSlot) {
foreach ($this->compileExpr($trailingComparisonProducer, $block) as $op) {
$sends[] = $op;
}
$comparisonSlot = $block->slotForOperand($trailingComparisonProducer->result);
}
if (null !== $comparisonSlot) {
$valueSlot = (string) $comparisonSlot;
}
Expand All @@ -27224,6 +27246,10 @@ protected function compileCallArgSends(
$valueSlot = (string) $chainedConcatSlot;
} else {
$callArgProbe = $cfgCallOp->args[(int) $argIndex] ?? $arg;
$trailingProducers = $this->precedingInlineCallArgProducersBeforeCfgOp(
$block->orig->children,
$cfgCallOp
);
foreach ($trailingProducers as $producer) {
if (!$producer instanceof Op\Expr\FuncCall && !$producer instanceof Op\Expr\NsFuncCall) {
continue;
Expand Down Expand Up @@ -27977,6 +28003,37 @@ protected function compileCallArgSends(
$valueSlot = $procOpenSlot;
}
}
// var_dump(E::A <=> E::B) — immediate spaceship prelude wins over hoisted enum temps (#10203).
if (null !== $cfgCallOp && null !== $block->orig) {
$callArgProbe = $cfgCallOp->args[(int) $argIndex] ?? $arg;
if ($this->callArgIsDeadInlineTemporary($callArgProbe)) {
$cfgCallIndex = null;
foreach ($block->orig->children as $ci => $cfgChild) {
if ($cfgChild === $cfgCallOp) {
$cfgCallIndex = $ci;
break;
}
}
if (null !== $cfgCallIndex && $cfgCallIndex > 0) {
$immediatePrelude = $block->orig->children[$cfgCallIndex - 1] ?? null;
if (
$this->isComparisonInlineCallArgProducer($immediatePrelude)
&& $immediatePrelude instanceof Op\Expr
&& null !== $immediatePrelude->result
) {
if (null === $block->slotForOperand($immediatePrelude->result)) {
foreach ($this->compileExpr($immediatePrelude, $block) as $op) {
$sends[] = $op;
}
}
$comparisonSlot = $block->slotForOperand($immediatePrelude->result);
if (null !== $comparisonSlot) {
$valueSlot = (string) $comparisonSlot;
}
}
}
}
}
$sends[] = new OpCode(OpCode::TYPE_ARG_SEND, $valueSlot, $nameSlot, $unpackFlag);
}

Expand Down
29 changes: 29 additions & 0 deletions test/unit/InlineCallArgProducerSlotTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1861,6 +1861,35 @@ enum E: int { case A = 1; }
self::assertSame($spaceshipSlot, $varDumpSend, 'var_dump arg send='.$varDumpSend);
}

/** Issue #10203 — var_dump(E::A <=> E::B) must send spaceship int, not hoisted enum case (#9575). */
public function testVarDumpEnumSpaceshipSendsSpaceshipResultSlot(): void
{
$code = <<<'PHP'
<?php
declare(strict_types=1);
enum E: int { case A = 1; case B = 2; }
var_dump(E::A <=> E::B);
PHP;
$runtime = new Runtime();
$block = $runtime->parseAndCompile($code, 'enum_spaceship_var_dump.php');

$spaceshipSlot = null;
$varDumpSend = null;
$seenSpaceship = false;
foreach ($block->opCodes as $op) {
if (OpCode::TYPE_SPACESHIP === $op->type) {
$spaceshipSlot = $op->arg1;
$seenSpaceship = true;
}
if ($seenSpaceship && OpCode::TYPE_ARG_SEND === $op->type && null === $varDumpSend) {
$varDumpSend = $op->arg1;
}
}

self::assertNotNull($spaceshipSlot, 'spaceship result slot must be lowered');
self::assertSame($spaceshipSlot, $varDumpSend, 'var_dump arg send='.$varDumpSend);
}

/** Issue #13945 — hoisted null operand before spaceship must not bind ConstFetch slot to var_dump arg. */
public function testVarDumpNullSpaceshipSendsSpaceshipResultSlot(): void
{
Expand Down