Skip to content
Open
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
4 changes: 3 additions & 1 deletion ext/opcache/jit/zend_jit_ir.c
Original file line number Diff line number Diff line change
Expand Up @@ -859,12 +859,14 @@ void *zend_jit_snapshot_handler(ir_ctx *ctx, ir_ref snapshot_ref, ir_insn *snaps
t->stack_map[t->exit_info[exit_point].stack_offset + var].flags = ZREG_TYPE_ONLY;
} else {
if ((exit_flags & ZEND_JIT_EXIT_FIXED)
&& t->stack_map[t->exit_info[exit_point].stack_offset + var].reg != IR_REG_NUM(reg)) {
&& (t->stack_map[t->exit_info[exit_point].stack_offset + var].reg != IR_REG_NUM(reg)
|| (t->stack_map[t->exit_info[exit_point].stack_offset + var].flags & ~(ZREG_LOAD|ZREG_STORE|ZREG_LAST_USE)))) {
exit_point = zend_jit_duplicate_exit_point(ctx, t, exit_point, snapshot_ref);
addr = (void*)zend_jit_trace_get_exit_addr(exit_point);
exit_flags &= ~ZEND_JIT_EXIT_FIXED;
}
t->stack_map[t->exit_info[exit_point].stack_offset + var].reg = IR_REG_NUM(reg);
t->stack_map[t->exit_info[exit_point].stack_offset + var].flags &= (ZREG_LOAD|ZREG_STORE|ZREG_LAST_USE);
}
} else {
if ((exit_flags & ZEND_JIT_EXIT_FIXED)
Expand Down
2 changes: 2 additions & 0 deletions ext/opcache/jit/zend_jit_trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -3558,6 +3558,8 @@ static int zend_jit_trace_deoptimization(
}
}
} else if (STACK_FLAGS(parent_stack, i) == ZREG_TYPE_ONLY) {
ZEND_ASSERT(reg == ZREG_NONE);

uint8_t type = STACK_TYPE(parent_stack, i);

if (!zend_jit_store_type(jit, i, type)) {
Expand Down
58 changes: 58 additions & 0 deletions ext/opcache/tests/jit/gh22763.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
--TEST--
GH-22763: JIT fails to clear ZREG_TYPE_ONLY after setting reg
--FILE--

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: with no --INI-- this runs at the default opcache.jit_hot_loop=61, so no trace compiles for findMiddleSnake (3-iteration loop, called once) and the assert never fires. It passes unpatched here. --EXTENSIONS-- opcache + --INI-- with jit_hot_loop=1 (like the other jit/ tests) makes it actually reproduce.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

run-tests.php sets a number of JIT settings including opcache.jit_hot_loop=1: https://github.com/arnaud-lb/php-src/blob/d341eb74fbc3fbc48fafae47b6d9b0f1158b551c/run-tests.php#L295

It reproduces with make test TESTS="ext/opcache/tests/jit/gh22763.phpt -d opcache.jit=tracing".

CI runs tests with an without -d opcache.jit=tracing

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm interesting, locally I had to make tweaks to trigger initial error.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually that's a user error, I ran test manually via php -d all good then.

<?php

function findMiddleSnake(array $a, int $aLo, int $aHi, array $b, int $bLo, int $bHi): array
{
$n = $aHi - $aLo;
$m = $bHi - $bLo;
$delta = $n - $m;
$deltaIsOdd = ($delta & 1) !== 0;
$offset = 4;
$size = 2 * 3 + 2;
$vf = array_fill(0, $size, 0);
$vb = array_fill(0, $size, 0);

$d = 2;
$x = 0;

for ($k = -$d; $k <= $d; $k += 2) {
if ($k === -$d || ($k !== $d && $vb[$offset + $k - 1] < $vb[$offset + $k + 1])) {
$x = $vb[$offset + $k + 1];
var_dump($x);
} else {
$x = $vb[$offset + $k - 1] + 1;
}

$y = $x - $k;
$xs = $x;
$ys = $y;

while ($x < $n && $y < $m && $a[$aLo + $n - 1 - $x] === $b[$bLo + $m - 1 - $y]) {
$x++;
$y++;
}

$vb[$offset + $k] = $x;

if (!$deltaIsOdd) {
$kf = $delta - $k;

if ($kf >= -$d && $kf <= $d && $vf[$offset + $kf] + $vb[$offset + $k] >= $n) {
return [$n - $x, $m - $y, $n - $xs, $m - $ys];
}
}
}

return [];
}

$from = [3,2,1];
$to = [1,99,3];
findMiddleSnake($from, 0, count($from), $to, 0, count($to));
?>
--EXPECTF--
int(0)

Warning: Undefined array key 3 in %s on line %d
Loading