Skip to content

Commit 668edf2

Browse files
committed
Improve ASSIGN_OBJ RC inference
ASSIGN_OBJ may only modify RC if it implements __set. Closes GH-13237
1 parent cc5a394 commit 668edf2

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

Zend/Optimizer/zend_inference.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3029,7 +3029,14 @@ static zend_always_inline zend_result _zend_update_type_info(
30293029
break;
30303030
case ZEND_ASSIGN_OBJ:
30313031
if (opline->op1_type == IS_CV) {
3032-
tmp = (t1 & (MAY_BE_REF|MAY_BE_OBJECT))|MAY_BE_RC1|MAY_BE_RCN;
3032+
zend_class_entry *ce = ssa_var_info[ssa_op->op1_use].ce;
3033+
bool add_rc = !ce
3034+
|| ce->__set
3035+
/* Non-default write_property may be set within create_object. */
3036+
|| ce->create_object
3037+
|| ce->default_object_handlers->write_property != zend_std_write_property
3038+
|| ssa_var_info[ssa_op->op1_use].is_instanceof;
3039+
tmp = (t1 & (MAY_BE_REF|MAY_BE_OBJECT|MAY_BE_RC1|MAY_BE_RCN))|(add_rc ? (MAY_BE_RC1|MAY_BE_RCN) : 0);
30333040
UPDATE_SSA_TYPE(tmp, ssa_op->op1_def);
30343041
COPY_SSA_OBJ_TYPE(ssa_op->op1_use, ssa_op->op1_def);
30353042
}

0 commit comments

Comments
 (0)