Skip to content

Commit de1a1d5

Browse files
committed
Merge branch 'PHP-8.0'
* PHP-8.0: Fixed incorrec immediate encoding when using LEA optimization
2 parents 75a678a + c5d93ae commit de1a1d5

File tree

2 files changed

+84
-1
lines changed

2 files changed

+84
-1
lines changed

ext/opcache/jit/zend_jit_x86.dasc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4309,7 +4309,7 @@ static int zend_jit_math_long_long(dasm_State **Dst,
43094309
!may_overflow &&
43104310
Z_MODE(op1_addr) == IS_REG &&
43114311
Z_MODE(op2_addr) == IS_CONST_ZVAL &&
4312-
IS_SIGNED_32BIT(Z_LVAL_P(Z_ZV(op2_addr)))) {
4312+
IS_SIGNED_32BIT(-Z_LVAL_P(Z_ZV(op2_addr)))) {
43134313
| lea Ra(result_reg), [Ra(Z_REG(op1_addr))-Z_LVAL_P(Z_ZV(op2_addr))]
43144314
} else {
43154315
| GET_ZVAL_LVAL result_reg, op1_addr

ext/opcache/tests/jit/bug81225_2.phpt

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
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=function
10+
--SKIPIF--
11+
<?php if (PHP_INT_SIZE != 8) die("skip: 64-bit only"); ?>
12+
--FILE--
13+
<?php
14+
function add_with_positive(int $a) {
15+
$a = $a % 10;
16+
$b = $a + 1;
17+
$c = $a + 100;
18+
$d = $a + 2147483647; // 0x7fff,ffff
19+
$e = $a + 2147483648; // 0x8000,0000 cannot encoded as imm field of lea r1, [r2 + imm]
20+
$f = $a + 78187493394; // 0x12,1234,5678 cannot encoded as imm field of lea r1, [r2 + imm]
21+
var_dump($b, $c, $d, $e, $f);
22+
}
23+
24+
function add_with_negative(int $a) {
25+
$a = $a % 10;
26+
$b = $a + (-1);
27+
$c = $a + (-100);
28+
$d = $a + (-2147483648); // 0xFFFF,FFFF,8000,0000
29+
$e = $a + (-2147483649); // 0xFFFF,FFFF,7FFF,FFFF cannot encoded as imm field of lea r1, [r2 + imm]
30+
$f = $a + (-261458978401740); // 0xFFFF,1234,5678,1234 cannot encoded as imm field of lea r1, [r2 + imm]
31+
var_dump($b, $c, $d, $e, $f);
32+
}
33+
34+
function sub_with_positive(int $a) {
35+
$a = $a % 10;
36+
$b = $a - 1;
37+
$c = $a - 100;
38+
$d = $a - 2147483647; // 0x7fff,ffff
39+
$e = $a - 2147483648; // 0x8000,0000
40+
$f = $a - 2147483649; // 0x8000,0001 cannot encoded as imm field of lea r1, [r2 + imm]
41+
$g = $a - 78187493394; // 0x12,1234,5678 cannot encoded as imm field of lea r1, [r2 + imm]
42+
var_dump($b, $c, $d, $e, $f, $g);
43+
}
44+
45+
function sub_with_negative(int $a) {
46+
$a = $a % 10;
47+
$b = $a - (-1);
48+
$c = $a - (-100);
49+
$d = $a - (-2147483647); // 0xFFFF,FFFF,8000,0001
50+
$e = $a - (-2147483648); // 0xFFFF,FFFF,8000,0000 cannot encoded as imm field of lea r1, [r2 + imm]
51+
$f = $a - (-2147483649); // 0xFFFF,FFFF,7FFF,FFFF cannot encoded as imm field of lea r1, [r2 + imm]
52+
$g = $a - (-261458978401740); // 0xFFFF,1234,5678,1234 cannot encoded as imm field of lea r1, [r2 + imm]
53+
var_dump($b, $c, $d, $e, $f, $g);
54+
}
55+
56+
add_with_positive(2);
57+
add_with_negative(2);
58+
sub_with_positive(2);
59+
sub_with_negative(2);
60+
?>
61+
--EXPECT--
62+
int(3)
63+
int(102)
64+
int(2147483649)
65+
int(2147483650)
66+
int(78187493396)
67+
int(1)
68+
int(-98)
69+
int(-2147483646)
70+
int(-2147483647)
71+
int(-261458978401738)
72+
int(1)
73+
int(-98)
74+
int(-2147483645)
75+
int(-2147483646)
76+
int(-2147483647)
77+
int(-78187493392)
78+
int(3)
79+
int(102)
80+
int(2147483649)
81+
int(2147483650)
82+
int(2147483651)
83+
int(261458978401742)

0 commit comments

Comments
 (0)