Skip to content

Commit 56430ef

Browse files
committed
Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0: JIT: Fix incorrect FETCH_THIS elimination
2 parents be22018 + 4170d41 commit 56430ef

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
@@ -3404,8 +3404,9 @@ static void zend_jit_trace_setup_ret_counter(const zend_op *opline, size_t offse
34043404
}
34053405
}
34063406

3407-
static bool zend_jit_may_delay_fetch_this(zend_ssa *ssa, const zend_op **ssa_opcodes, int var)
3407+
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)
34083408
{
3409+
int var = ssa_op->result_def;
34093410
int i;
34103411
int use = ssa->vars[var].use_chain;
34113412
const zend_op *opline;
@@ -3446,6 +3447,19 @@ static bool zend_jit_may_delay_fetch_this(zend_ssa *ssa, const zend_op **ssa_opc
34463447
return 0;
34473448
}
34483449

3450+
if (opline->opcode == ZEND_ASSIGN_OBJ_OP) {
3451+
if (opline->op1_type == IS_CV
3452+
&& (opline+1)->op1_type == IS_CV
3453+
&& (opline+1)->op1.var == opline->op1.var) {
3454+
/* skip $a->prop += $a; */
3455+
return 0;
3456+
}
3457+
if (!zend_jit_supported_binary_op(
3458+
opline->extended_value, MAY_BE_ANY, OP1_DATA_INFO())) {
3459+
return 0;
3460+
}
3461+
}
3462+
34493463
for (i = ssa->vars[var].definition; i < use; i++) {
34503464
if (ssa_opcodes[i]->opcode == ZEND_DO_UCALL
34513465
|| ssa_opcodes[i]->opcode == ZEND_DO_FCALL_BY_NAME
@@ -5871,7 +5885,7 @@ static const void *zend_jit_trace(zend_jit_trace_rec *trace_buffer, uint32_t par
58715885
case ZEND_FETCH_THIS:
58725886
delayed_fetch_this = 0;
58735887
if (ssa_op->result_def >= 0 && opline->result_type != IS_CV) {
5874-
if (zend_jit_may_delay_fetch_this(ssa, ssa_opcodes, ssa_op->result_def)) {
5888+
if (zend_jit_may_delay_fetch_this(op_array, ssa, ssa_opcodes, ssa_op)) {
58755889
ssa->var_info[ssa_op->result_def].delayed_fetch_this = 1;
58765890
delayed_fetch_this = 1;
58775891
}
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)