Skip to content

Commit e7f4860

Browse files
committed
Improve ZEND_NEW RC inference
ZEND_NEW returns RC1 if the instanciated class has no constructor.
1 parent 52dba99 commit e7f4860

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

Zend/Optimizer/zend_inference.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3371,9 +3371,19 @@ static zend_always_inline zend_result _zend_update_type_info(
33713371
UPDATE_SSA_OBJ_TYPE(ce, 0, ssa_op->result_def);
33723372
} else if ((t1 & MAY_BE_CLASS) && ssa_op->op1_use >= 0 && ssa_var_info[ssa_op->op1_use].ce) {
33733373
UPDATE_SSA_OBJ_TYPE(ssa_var_info[ssa_op->op1_use].ce, ssa_var_info[ssa_op->op1_use].is_instanceof, ssa_op->result_def);
3374+
if (!ssa_var_info[ssa_op->result_def].is_instanceof) {
3375+
ce = ssa_var_info[ssa_op->op1_use].ce;
3376+
}
33743377
} else {
33753378
UPDATE_SSA_OBJ_TYPE(NULL, 0, ssa_op->result_def);
33763379
}
3380+
/* New objects without constructors cannot escape. */
3381+
if (ce
3382+
&& !ce->constructor
3383+
&& !ce->create_object
3384+
&& ce->default_object_handlers->get_constructor == zend_std_get_constructor) {
3385+
tmp &= ~MAY_BE_RCN;
3386+
}
33773387
UPDATE_SSA_TYPE(tmp, ssa_op->result_def);
33783388
break;
33793389
case ZEND_CLONE:

0 commit comments

Comments
 (0)