Skip to content

Commit 3621ce6

Browse files
committed
Merge branch 'PHP-8.0'
* PHP-8.0: Fixed bug #81225 (Wrong result with pow operator with JIT enabled)
2 parents 453a516 + 9cd4371 commit 3621ce6

File tree

3 files changed

+42
-3
lines changed

3 files changed

+42
-3
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ PHP NEWS
66
. Fixed bug #81238 (Fiber support missing for Solaris Sparc). (trowski)
77
. Fixed bug #81237 (Comparison of fake closures doesn't work). (krakjoe)
88

9+
- Opcache:
10+
. Fixed bug #81225 (Wrong result with pow operator with JIT enabled).
11+
(Dmitry)
12+
913
- Reflection:
1014
. Fixed bug #80097 (ReflectionAttribute is not a Reflector). (beberlei)
1115

ext/opcache/jit/zend_jit_x86.dasc

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4296,17 +4296,20 @@ static int zend_jit_math_long_long(dasm_State **Dst,
42964296
} else if (opcode == ZEND_ADD &&
42974297
!may_overflow &&
42984298
Z_MODE(op1_addr) == IS_REG &&
4299-
Z_MODE(op2_addr) == IS_CONST_ZVAL) {
4299+
Z_MODE(op2_addr) == IS_CONST_ZVAL &&
4300+
IS_SIGNED_32BIT(Z_LVAL_P(Z_ZV(op2_addr)))) {
43004301
| lea Ra(result_reg), [Ra(Z_REG(op1_addr))+Z_LVAL_P(Z_ZV(op2_addr))]
43014302
} else if (opcode == ZEND_ADD &&
43024303
!may_overflow &&
43034304
Z_MODE(op2_addr) == IS_REG &&
4304-
Z_MODE(op1_addr) == IS_CONST_ZVAL) {
4305+
Z_MODE(op1_addr) == IS_CONST_ZVAL &&
4306+
IS_SIGNED_32BIT(Z_LVAL_P(Z_ZV(op1_addr)))) {
43054307
| lea Ra(result_reg), [Ra(Z_REG(op2_addr))+Z_LVAL_P(Z_ZV(op1_addr))]
43064308
} else if (opcode == ZEND_SUB &&
43074309
!may_overflow &&
43084310
Z_MODE(op1_addr) == IS_REG &&
4309-
Z_MODE(op2_addr) == IS_CONST_ZVAL) {
4311+
Z_MODE(op2_addr) == IS_CONST_ZVAL &&
4312+
IS_SIGNED_32BIT(Z_LVAL_P(Z_ZV(op2_addr)))) {
43104313
| lea Ra(result_reg), [Ra(Z_REG(op1_addr))-Z_LVAL_P(Z_ZV(op2_addr))]
43114314
} else {
43124315
| GET_ZVAL_LVAL result_reg, op1_addr

ext/opcache/tests/jit/bug81225.phpt

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
--TEST--
2+
Bug #81225: Wrong result with pow operator with JIT enabled
3+
--EXTENSIONS--
4+
opcache
5+
--INI--
6+
opcache.enable=1
7+
opcache.enable_cli=1
8+
opcache.jit_buffer_size=1M
9+
opcache.jit=tracing
10+
--FILE--
11+
<?php
12+
13+
function unsignedLong(int $offset): int
14+
{
15+
$normalizedOffset = $offset % (2 ** 32);
16+
17+
if ($normalizedOffset < 0) {
18+
$normalizedOffset += 2 ** 32;
19+
}
20+
21+
return $normalizedOffset;
22+
}
23+
24+
$offset = -0x100000000 + 2;
25+
26+
for ($i = 0; $i < 200; ++$i) {
27+
assert(unsignedLong($offset) === 2);
28+
}
29+
?>
30+
OK
31+
--EXPECT--
32+
OK

0 commit comments

Comments
 (0)