Skip to content

Commit 89eb1c6

Browse files
authored
Fixed GH-11917: primitives seem to be passed via reference instead of by value under some conditions when JIT is enabled on windows (#12451)
1 parent dabced0 commit 89eb1c6

File tree

2 files changed

+62
-1
lines changed

2 files changed

+62
-1
lines changed

ext/opcache/jit/zend_jit_x86.dasc

+1-1
Original file line numberDiff line numberDiff line change
@@ -5157,7 +5157,7 @@ static int zend_jit_long_math_helper(dasm_State **Dst,
51575157
result_reg = ZREG_R0;
51585158
} else {
51595159
/* ASSIGN_DIM_OP */
5160-
if (sizeof(void*) == 4
5160+
if (ZREG_FCARG1 == ZREG_RCX
51615161
&& (opcode == ZEND_SL || opcode == ZEND_SR)
51625162
&& Z_MODE(op2_addr) != IS_CONST_ZVAL) {
51635163
result_reg = ZREG_R2;

ext/opcache/tests/jit/gh11917.phpt

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
--TEST--
2+
GH-11917: primitives seem to be passed via reference instead of by value under some conditions when JIT is enabled on windows
3+
--INI--
4+
opcache.enable=1
5+
opcache.enable_cli=1
6+
--FILE--
7+
<?php
8+
$a = [2147483647,2147483647,2147483647,3,0,0,32,2147483584,127];
9+
echo crc32(json_encode(bitwise_small_split($a))) . "\n";
10+
echo crc32(json_encode(bitwise_small_split($a))) . "\n";
11+
echo crc32(json_encode(bitwise_small_split($a))) . "\n";
12+
echo crc32(json_encode(bitwise_small_split($a))) . "\n";
13+
14+
function bitwise_small_split($val)
15+
{
16+
$split = 8;
17+
$vals = [];
18+
19+
$mask = (1 << $split) - 1;
20+
21+
$i = $overflow = 0;
22+
$len = count($val);
23+
$val[] = 0;
24+
$remaining = 31;
25+
26+
while ($i != $len) {
27+
$digit = $val[$i] & $mask;
28+
29+
$val[$i] >>= $split;
30+
if (!$overflow) {
31+
$remaining -= $split;
32+
$overflow = $split <= $remaining ? 0 : $split - $remaining;
33+
34+
if (!$remaining) {
35+
$i++;
36+
$remaining = 31;
37+
$overflow = 0;
38+
}
39+
} elseif (++$i != $len) {
40+
$tempmask = (1 << $overflow) - 1;
41+
$digit |= ($val[$i] & $tempmask) << $remaining;
42+
$val[$i] >>= $overflow;
43+
$remaining = 31 - $overflow;
44+
$overflow = $split <= $remaining ? 0 : $split - $remaining;
45+
}
46+
47+
$vals[] = $digit;
48+
}
49+
50+
while ($vals[count($vals) - 1] == 0) {
51+
unset($vals[count($vals) - 1]);
52+
}
53+
54+
return array_reverse($vals);
55+
}
56+
?>
57+
--EXPECT--
58+
48207660
59+
48207660
60+
48207660
61+
48207660

0 commit comments

Comments
 (0)