Skip to content

Commit

Permalink
Merge branch 'PHP-8.3'
Browse files Browse the repository at this point in the history
* PHP-8.3:
  Fixed phpGH-11917: primitives seem to be passed via reference instead of by value under some conditions when JIT is enabled on windows (php#12451)
  • Loading branch information
dstogov committed Oct 16, 2023
2 parents 1e2e2f3 + a831cbc commit 221b4fe
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ext/opcache/jit/zend_jit_x86.dasc
Original file line number Diff line number Diff line change
Expand Up @@ -5188,7 +5188,7 @@ static int zend_jit_long_math_helper(dasm_State **Dst,
result_reg = ZREG_R0;
} else {
/* ASSIGN_DIM_OP */
if (sizeof(void*) == 4
if (ZREG_FCARG1 == ZREG_RCX
&& (opcode == ZEND_SL || opcode == ZEND_SR)
&& Z_MODE(op2_addr) != IS_CONST_ZVAL) {
result_reg = ZREG_R2;
Expand Down
61 changes: 61 additions & 0 deletions ext/opcache/tests/jit/gh11917.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
--TEST--
GH-11917: primitives seem to be passed via reference instead of by value under some conditions when JIT is enabled on windows
--INI--
opcache.enable=1
opcache.enable_cli=1
--FILE--
<?php
$a = [2147483647,2147483647,2147483647,3,0,0,32,2147483584,127];
echo crc32(json_encode(bitwise_small_split($a))) . "\n";
echo crc32(json_encode(bitwise_small_split($a))) . "\n";
echo crc32(json_encode(bitwise_small_split($a))) . "\n";
echo crc32(json_encode(bitwise_small_split($a))) . "\n";

function bitwise_small_split($val)
{
$split = 8;
$vals = [];

$mask = (1 << $split) - 1;

$i = $overflow = 0;
$len = count($val);
$val[] = 0;
$remaining = 31;

while ($i != $len) {
$digit = $val[$i] & $mask;

$val[$i] >>= $split;
if (!$overflow) {
$remaining -= $split;
$overflow = $split <= $remaining ? 0 : $split - $remaining;

if (!$remaining) {
$i++;
$remaining = 31;
$overflow = 0;
}
} elseif (++$i != $len) {
$tempmask = (1 << $overflow) - 1;
$digit |= ($val[$i] & $tempmask) << $remaining;
$val[$i] >>= $overflow;
$remaining = 31 - $overflow;
$overflow = $split <= $remaining ? 0 : $split - $remaining;
}

$vals[] = $digit;
}

while ($vals[count($vals) - 1] == 0) {
unset($vals[count($vals) - 1]);
}

return array_reverse($vals);
}
?>
--EXPECT--
48207660
48207660
48207660
48207660

0 comments on commit 221b4fe

Please sign in to comment.