Skip to content

Commit b06311c

Browse files
committed
Improve ZEND_NEW RC inference
ZEND_NEW returns RC1 if the instanciated class has no constructor. Closes GH-13239
1 parent 8d08295 commit b06311c

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
@@ -3376,9 +3376,19 @@ static zend_always_inline zend_result _zend_update_type_info(
33763376
UPDATE_SSA_OBJ_TYPE(ce, 0, ssa_op->result_def);
33773377
} else if ((t1 & MAY_BE_CLASS) && ssa_op->op1_use >= 0 && ssa_var_info[ssa_op->op1_use].ce) {
33783378
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);
3379+
if (!ssa_var_info[ssa_op->result_def].is_instanceof) {
3380+
ce = ssa_var_info[ssa_op->op1_use].ce;
3381+
}
33793382
} else {
33803383
UPDATE_SSA_OBJ_TYPE(NULL, 0, ssa_op->result_def);
33813384
}
3385+
/* New objects without constructors cannot escape. */
3386+
if (ce
3387+
&& !ce->constructor
3388+
&& !ce->create_object
3389+
&& ce->default_object_handlers->get_constructor == zend_std_get_constructor) {
3390+
tmp &= ~MAY_BE_RCN;
3391+
}
33823392
UPDATE_SSA_TYPE(tmp, ssa_op->result_def);
33833393
break;
33843394
case ZEND_CLONE:

0 commit comments

Comments
 (0)