Skip to content

Commit fe4beb3

Browse files
committed
Merge branch 'PHP-8.1'
* PHP-8.1: Tracing JIT: Fix reference counting
2 parents d9926a1 + 0314f40 commit fe4beb3

File tree

4 files changed

+38
-6
lines changed

4 files changed

+38
-6
lines changed

ext/opcache/jit/zend_jit.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ static uint32_t zend_ssa_cv_info(const zend_op_array *op_array, zend_ssa *ssa, u
540540
return info;
541541
}
542542

543-
static bool zend_jit_may_avoid_refcounting(const zend_op *opline)
543+
static bool zend_jit_may_avoid_refcounting(const zend_op *opline, uint32_t op1_info)
544544
{
545545
switch (opline->opcode) {
546546
case ZEND_FETCH_OBJ_FUNC_ARG:
@@ -552,7 +552,8 @@ static bool zend_jit_may_avoid_refcounting(const zend_op *opline)
552552
/* break missing intentionally */
553553
case ZEND_FETCH_OBJ_R:
554554
case ZEND_FETCH_OBJ_IS:
555-
if (opline->op2_type == IS_CONST
555+
if ((op1_info & MAY_BE_OBJECT)
556+
&& opline->op2_type == IS_CONST
556557
&& Z_TYPE_P(RT_CONSTANT(opline, opline->op2)) == IS_STRING
557558
&& Z_STRVAL_P(RT_CONSTANT(opline, opline->op2))[0] != '\0') {
558559
return 1;

ext/opcache/jit/zend_jit_arm64.dasc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11118,7 +11118,7 @@ static int zend_jit_fetch_dim_read(dasm_State **Dst,
1111811118
&& (res_info & (MAY_BE_STRING|MAY_BE_ARRAY|MAY_BE_OBJECT|MAY_BE_RESOURCE))
1111911119
&& (ssa_op+1)->op1_use == ssa_op->result_def
1112011120
&& !(op2_info & ((MAY_BE_ANY|MAY_BE_UNDEF|MAY_BE_REF) - (MAY_BE_STRING|MAY_BE_LONG)))
11121-
&& zend_jit_may_avoid_refcounting(opline+1)) {
11121+
&& zend_jit_may_avoid_refcounting(opline+1, res_info)) {
1112211122
result_avoid_refcounting = 1;
1112311123
ssa->var_info[ssa_op->result_def].avoid_refcounting = 1;
1112411124
}
@@ -12398,7 +12398,7 @@ static int zend_jit_fetch_obj(dasm_State **Dst,
1239812398
&& !(flags & ZEND_JIT_EXIT_FREE_OP1)
1239912399
&& (res_info & (MAY_BE_STRING|MAY_BE_ARRAY|MAY_BE_OBJECT|MAY_BE_RESOURCE))
1240012400
&& (ssa_op+1)->op1_use == ssa_op->result_def
12401-
&& zend_jit_may_avoid_refcounting(opline+1)) {
12401+
&& zend_jit_may_avoid_refcounting(opline+1, res_info)) {
1240212402
result_avoid_refcounting = 1;
1240312403
ssa->var_info[ssa_op->result_def].avoid_refcounting = 1;
1240412404
}

ext/opcache/jit/zend_jit_x86.dasc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11775,7 +11775,7 @@ static int zend_jit_fetch_dim_read(dasm_State **Dst,
1177511775
&& (res_info & (MAY_BE_STRING|MAY_BE_ARRAY|MAY_BE_OBJECT|MAY_BE_RESOURCE))
1177611776
&& (ssa_op+1)->op1_use == ssa_op->result_def
1177711777
&& !(op2_info & ((MAY_BE_ANY|MAY_BE_UNDEF|MAY_BE_REF) - (MAY_BE_STRING|MAY_BE_LONG)))
11778-
&& zend_jit_may_avoid_refcounting(opline+1)) {
11778+
&& zend_jit_may_avoid_refcounting(opline+1, res_info)) {
1177911779
result_avoid_refcounting = 1;
1178011780
ssa->var_info[ssa_op->result_def].avoid_refcounting = 1;
1178111781
}
@@ -13107,7 +13107,7 @@ static int zend_jit_fetch_obj(dasm_State **Dst,
1310713107
&& !(flags & ZEND_JIT_EXIT_FREE_OP1)
1310813108
&& (res_info & (MAY_BE_STRING|MAY_BE_ARRAY|MAY_BE_OBJECT|MAY_BE_RESOURCE))
1310913109
&& (ssa_op+1)->op1_use == ssa_op->result_def
13110-
&& zend_jit_may_avoid_refcounting(opline+1)) {
13110+
&& zend_jit_may_avoid_refcounting(opline+1, res_info)) {
1311113111
result_avoid_refcounting = 1;
1311213112
ssa->var_info[ssa_op->result_def].avoid_refcounting = 1;
1311313113
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
--TEST--
2+
JIT: FETCH_OBJ 008
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 A {
11+
public string $prop = "";
12+
}
13+
14+
class B {
15+
public function __toString() {
16+
global $a;
17+
$a->prop = "A $e B";
18+
$a->prop->prop . $a->prop = "C";
19+
return "test";
20+
}
21+
}
22+
23+
$a = new A;
24+
$a->prop = new B;
25+
?>
26+
DONE
27+
--EXPECTF--
28+
Warning: Undefined variable $e in %sfetch_obj_008.php on line 9
29+
30+
Warning: Attempt to read property "prop" on string in %sfetch_obj_008.php on line 10
31+
DONE

0 commit comments

Comments
 (0)