Skip to content

Commit 8aac698

Browse files
committed
Merge branch 'PHP-8.4'
* PHP-8.4: Fix RC inference of op1 of FETCH_OBJ and INIT_METHOD_CALL Add tests for GH-17151
2 parents e69317b + 6666cc8 commit 8aac698

File tree

5 files changed

+81
-0
lines changed

5 files changed

+81
-0
lines changed

Zend/Optimizer/zend_inference.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1968,6 +1968,10 @@ static uint32_t get_ssa_alias_types(zend_ssa_alias_kind alias) {
19681968
/* TODO: support for array keys and ($str . "")*/ \
19691969
__type |= MAY_BE_RCN; \
19701970
} \
1971+
if ((__type & MAY_BE_RC1) && (__type & MAY_BE_OBJECT)) {\
1972+
/* TODO: object may be captured by magic handlers */\
1973+
__type |= MAY_BE_RCN; \
1974+
} \
19711975
if (__ssa_var->alias) { \
19721976
__type |= get_ssa_alias_types(__ssa_var->alias); \
19731977
} \

ext/opcache/jit/zend_jit_ir.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14621,6 +14621,7 @@ static int zend_jit_fetch_obj(zend_jit_ctx *jit,
1462114621
ir_MERGE_list(slow_inputs);
1462214622
jit_SET_EX_OPLINE(jit, opline);
1462314623

14624+
op1_info |= MAY_BE_RC1 | MAY_BE_RCN; /* object may be captured/released in magic handler */
1462414625
if (opline->opcode == ZEND_FETCH_OBJ_W) {
1462514626
ir_CALL_1(IR_VOID, ir_CONST_FC_FUNC(zend_jit_fetch_obj_w_slow), obj_ref);
1462614627
ir_END_list(end_inputs);

ext/opcache/tests/jit/gh17151_1.phpt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--TEST--
2+
GH-17151: ZEND_FETCH_OBJ_R may modify RC of op1
3+
--FILE--
4+
<?php
5+
6+
class C {
7+
public function __get($name) {
8+
return $this;
9+
}
10+
}
11+
12+
function test() {
13+
$x = (new C)->bar;
14+
var_dump($x);
15+
}
16+
17+
test();
18+
19+
?>
20+
--EXPECTF--
21+
object(C)#%d (0) {
22+
}

ext/opcache/tests/jit/gh17151_2.phpt

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
--TEST--
2+
GH-17151: ZEND_FETCH_OBJ_R may modify RC of op1
3+
--FILE--
4+
<?php
5+
6+
class C {
7+
public static $prop;
8+
9+
public function __get($name) {
10+
C::$prop = null;
11+
}
12+
13+
public function __destruct() {
14+
echo __METHOD__, "\n";
15+
}
16+
}
17+
18+
function test() {
19+
C::$prop = new C();
20+
C::$prop->bar;
21+
}
22+
23+
test();
24+
echo "Done\n";
25+
26+
?>
27+
--EXPECT--
28+
C::__destruct
29+
Done

ext/opcache/tests/jit/gh17151_3.phpt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
--TEST--
2+
GH-17151: Method calls may modify RC of ZEND_INIT_METHOD_CALL op1
3+
--FILE--
4+
<?php
5+
6+
class C {
7+
public static $prop;
8+
9+
public function storeThis() {
10+
self::$prop = $this;
11+
}
12+
}
13+
14+
function test() {
15+
$c = new C();
16+
$c->storeThis();
17+
$c = null;
18+
}
19+
20+
test();
21+
22+
?>
23+
===DONE===
24+
--EXPECT--
25+
===DONE===

0 commit comments

Comments
 (0)