Skip to content

Commit cbc925e

Browse files
committed
Fixed bug #81409 (Incorrect JIT code for ADD with a reference to array)
1 parent d6d6491 commit cbc925e

File tree

6 files changed

+34
-10
lines changed

6 files changed

+34
-10
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ PHP NEWS
22
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
33
?? ??? ????, PHP 8.1.0RC2
44

5+
- Opcache:
6+
. Fixed bug #81409 (Incorrect JIT code for ADD with a reference to array).
7+
(Dmitry)
8+
59
- Zip:
610
. Fixed bug #80833 (ZipArchive::getStream doesn't use setPassword). (Remi)
711

ext/opcache/jit/zend_jit.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2989,7 +2989,7 @@ static int zend_jit(const zend_op_array *op_array, zend_ssa *ssa, const zend_op
29892989
if (opline->opcode == ZEND_ADD &&
29902990
(op1_info & (MAY_BE_ANY|MAY_BE_UNDEF)) == MAY_BE_ARRAY &&
29912991
(op2_info & (MAY_BE_ANY|MAY_BE_UNDEF)) == MAY_BE_ARRAY) {
2992-
if (!zend_jit_add_arrays(&dasm_state, opline, op1_info, op2_info, res_addr)) {
2992+
if (!zend_jit_add_arrays(&dasm_state, opline, op1_info, OP1_REG_ADDR(), op2_info, OP2_REG_ADDR(), res_addr)) {
29932993
goto jit_failure;
29942994
}
29952995
} else {

ext/opcache/jit/zend_jit_arm64.dasc

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4454,11 +4454,8 @@ static int zend_jit_math(dasm_State **Dst, const zend_op *opline, uint32_t op1_i
44544454
return 1;
44554455
}
44564456

4457-
static int zend_jit_add_arrays(dasm_State **Dst, const zend_op *opline, uint32_t op1_info, uint32_t op2_info, zend_jit_addr res_addr)
4457+
static int zend_jit_add_arrays(dasm_State **Dst, const zend_op *opline, uint32_t op1_info, zend_jit_addr op1_addr, uint32_t op2_info, zend_jit_addr op2_addr, zend_jit_addr res_addr)
44584458
{
4459-
zend_jit_addr op1_addr = OP1_ADDR();
4460-
zend_jit_addr op2_addr = OP2_ADDR();
4461-
44624459
| GET_ZVAL_LVAL ZREG_FCARG1, op1_addr, TMP1
44634460
| GET_ZVAL_LVAL ZREG_FCARG2, op2_addr, TMP1
44644461
| EXT_CALL zend_jit_add_arrays_helper, REG0

ext/opcache/jit/zend_jit_trace.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4270,7 +4270,7 @@ static const void *zend_jit_trace(zend_jit_trace_rec *trace_buffer, uint32_t par
42704270
if (opline->opcode == ZEND_ADD &&
42714271
(op1_info & (MAY_BE_ANY|MAY_BE_UNDEF)) == MAY_BE_ARRAY &&
42724272
(op2_info & (MAY_BE_ANY|MAY_BE_UNDEF)) == MAY_BE_ARRAY) {
4273-
if (!zend_jit_add_arrays(&dasm_state, opline, op1_info, op2_info, res_addr)) {
4273+
if (!zend_jit_add_arrays(&dasm_state, opline, op1_info, op1_addr, op2_info, op2_addr, res_addr)) {
42744274
goto jit_failure;
42754275
}
42764276
} else {

ext/opcache/jit/zend_jit_x86.dasc

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4877,11 +4877,8 @@ static int zend_jit_math(dasm_State **Dst, const zend_op *opline, uint32_t op1_i
48774877
return 1;
48784878
}
48794879

4880-
static int zend_jit_add_arrays(dasm_State **Dst, const zend_op *opline, uint32_t op1_info, uint32_t op2_info, zend_jit_addr res_addr)
4880+
static int zend_jit_add_arrays(dasm_State **Dst, const zend_op *opline, uint32_t op1_info, zend_jit_addr op1_addr, uint32_t op2_info, zend_jit_addr op2_addr, zend_jit_addr res_addr)
48814881
{
4882-
zend_jit_addr op1_addr = OP1_ADDR();
4883-
zend_jit_addr op2_addr = OP2_ADDR();
4884-
48854882
| GET_ZVAL_LVAL ZREG_FCARG1, op1_addr
48864883
| GET_ZVAL_LVAL ZREG_FCARG2, op2_addr
48874884
| EXT_CALL zend_jit_add_arrays_helper, r0

ext/opcache/tests/jit/bug81409.phpt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
--TEST--
2+
Bug #81409: Incorrect JIT code for ADD with a reference to array
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+
function foo(&$a) {
13+
$n = count($a);
14+
$a = $a + [$n=>1];
15+
}
16+
function bar() {
17+
$x = [];
18+
for ($i = 0; $i < 200; $i++) {
19+
foo($x);
20+
}
21+
var_dump(count($x));
22+
}
23+
bar();
24+
?>
25+
--EXPECT--
26+
int(200)

0 commit comments

Comments
 (0)