Skip to content

Fix RC tracking of op1 of FETCH_OBJ and INIT_METHOD_CALL #17152

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Zend/Optimizer/zend_inference.c
Original file line number Diff line number Diff line change
Expand Up @@ -1968,6 +1968,10 @@ static uint32_t get_ssa_alias_types(zend_ssa_alias_kind alias) {
/* TODO: support for array keys and ($str . "")*/ \
__type |= MAY_BE_RCN; \
} \
if ((__type & MAY_BE_RC1) && (__type & MAY_BE_OBJECT)) {\
/* TODO: object may be captured by magic handlers */\
__type |= MAY_BE_RCN; \
} \
if (__ssa_var->alias) { \
__type |= get_ssa_alias_types(__ssa_var->alias); \
} \
Expand Down
1 change: 1 addition & 0 deletions ext/opcache/jit/zend_jit_ir.c
Original file line number Diff line number Diff line change
Expand Up @@ -14426,6 +14426,7 @@ static int zend_jit_fetch_obj(zend_jit_ctx *jit,
ir_MERGE_list(slow_inputs);
jit_SET_EX_OPLINE(jit, opline);

op1_info |= MAY_BE_RC1 | MAY_BE_RCN; /* object may be captured/released in magic handler */
if (opline->opcode == ZEND_FETCH_OBJ_W) {
ir_CALL_1(IR_VOID, ir_CONST_FC_FUNC(zend_jit_fetch_obj_w_slow), obj_ref);
ir_END_list(end_inputs);
Expand Down
22 changes: 22 additions & 0 deletions ext/opcache/tests/jit/gh17151_1.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
--TEST--
GH-17151: ZEND_FETCH_OBJ_R may modify RC of op1
--FILE--
<?php

class C {
public function __get($name) {
return $this;
}
}

function test() {
$x = (new C)->bar;
var_dump($x);
}

test();

?>
--EXPECTF--
object(C)#%d (0) {
}
29 changes: 29 additions & 0 deletions ext/opcache/tests/jit/gh17151_2.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
--TEST--
GH-17151: ZEND_FETCH_OBJ_R may modify RC of op1
--FILE--
<?php

class C {
public static $prop;

public function __get($name) {
C::$prop = null;
}

public function __destruct() {
echo __METHOD__, "\n";
}
}

function test() {
C::$prop = new C();
C::$prop->bar;
}

test();
echo "Done\n";

?>
--EXPECT--
C::__destruct
Done
25 changes: 25 additions & 0 deletions ext/opcache/tests/jit/gh17151_3.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
--TEST--
GH-17151: Method calls may modify RC of ZEND_INIT_METHOD_CALL op1
--FILE--
<?php

class C {
public static $prop;

public function storeThis() {
self::$prop = $this;
}
}

function test() {
$c = new C();
$c->storeThis();
$c = null;
}

test();

?>
===DONE===
--EXPECT--
===DONE===
Loading