Skip to content

Commit bb5047a

Browse files
committed
Merge branch 'PHP-8.1'
* PHP-8.1: JIT: Fix incorrect FETCH_THIS elimination
2 parents d6b4039 + 56430ef commit bb5047a

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

ext/opcache/jit/zend_jit_trace.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3417,8 +3417,9 @@ static void zend_jit_trace_setup_ret_counter(const zend_op *opline, size_t offse
34173417
}
34183418
}
34193419

3420-
static bool zend_jit_may_delay_fetch_this(zend_ssa *ssa, const zend_op **ssa_opcodes, int var)
3420+
static bool zend_jit_may_delay_fetch_this(const zend_op_array *op_array, zend_ssa *ssa, const zend_op **ssa_opcodes, const zend_ssa_op *ssa_op)
34213421
{
3422+
int var = ssa_op->result_def;
34223423
int i;
34233424
int use = ssa->vars[var].use_chain;
34243425
const zend_op *opline;
@@ -3459,6 +3460,19 @@ static bool zend_jit_may_delay_fetch_this(zend_ssa *ssa, const zend_op **ssa_opc
34593460
return 0;
34603461
}
34613462

3463+
if (opline->opcode == ZEND_ASSIGN_OBJ_OP) {
3464+
if (opline->op1_type == IS_CV
3465+
&& (opline+1)->op1_type == IS_CV
3466+
&& (opline+1)->op1.var == opline->op1.var) {
3467+
/* skip $a->prop += $a; */
3468+
return 0;
3469+
}
3470+
if (!zend_jit_supported_binary_op(
3471+
opline->extended_value, MAY_BE_ANY, OP1_DATA_INFO())) {
3472+
return 0;
3473+
}
3474+
}
3475+
34623476
for (i = ssa->vars[var].definition; i < use; i++) {
34633477
if (ssa_opcodes[i]->opcode == ZEND_DO_UCALL
34643478
|| ssa_opcodes[i]->opcode == ZEND_DO_FCALL_BY_NAME
@@ -5884,7 +5898,7 @@ static const void *zend_jit_trace(zend_jit_trace_rec *trace_buffer, uint32_t par
58845898
case ZEND_FETCH_THIS:
58855899
delayed_fetch_this = 0;
58865900
if (ssa_op->result_def >= 0 && opline->result_type != IS_CV) {
5887-
if (zend_jit_may_delay_fetch_this(ssa, ssa_opcodes, ssa_op->result_def)) {
5901+
if (zend_jit_may_delay_fetch_this(op_array, ssa, ssa_opcodes, ssa_op)) {
58885902
ssa->var_info[ssa_op->result_def].delayed_fetch_this = 1;
58895903
delayed_fetch_this = 1;
58905904
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
--TEST--
2+
JIT ASSIGN_OBJ_OP: Unsupported types
3+
--INI--
4+
opcache.enable=1
5+
opcache.enable_cli=1
6+
opcache.file_update_protection=0
7+
opcache.jit_buffer_size=1M
8+
--FILE--
9+
<?php
10+
class Test{
11+
}
12+
13+
$test = new Test;
14+
(function(){$this->y.=[];})->call($test);
15+
?>
16+
--EXPECTF--
17+
Warning: Undefined property: Test::$y in %sassign_obj_op_001.php on line 6
18+
19+
Warning: Array to string conversion in %sassign_obj_op_001.php on line 6

0 commit comments

Comments
 (0)