Skip to content

Commit f903c03

Browse files
committed
Improve ASSIGN_OBJ[_REF] RC inference
* ASSIGN_OBJ may only modify RC if it implements __set. * ASSIGN_OBJ_REF does not call __set, and thus may not modify RC.
1 parent 52dba99 commit f903c03

File tree

2 files changed

+8
-16
lines changed

2 files changed

+8
-16
lines changed

Zend/Optimizer/zend_inference.c

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3024,7 +3024,14 @@ static zend_always_inline zend_result _zend_update_type_info(
30243024
break;
30253025
case ZEND_ASSIGN_OBJ:
30263026
if (opline->op1_type == IS_CV) {
3027-
tmp = (t1 & (MAY_BE_REF|MAY_BE_OBJECT))|MAY_BE_RC1|MAY_BE_RCN;
3027+
zend_class_entry *ce = ssa_var_info[ssa_op->op1_use].ce;
3028+
bool add_rc = !ce
3029+
|| ce->__set
3030+
/* Non-default write_property may be set within create_object. */
3031+
|| ce->create_object
3032+
|| ce->default_object_handlers->write_property != zend_std_write_property
3033+
|| ssa_var_info[ssa_op->op1_use].is_instanceof;
3034+
tmp = (t1 & (MAY_BE_REF|MAY_BE_OBJECT|MAY_BE_RC1|MAY_BE_RCN))|(add_rc ? (MAY_BE_RC1|MAY_BE_RCN) : 0);
30283035
UPDATE_SSA_TYPE(tmp, ssa_op->op1_def);
30293036
COPY_SSA_OBJ_TYPE(ssa_op->op1_use, ssa_op->op1_def);
30303037
}
@@ -3157,15 +3164,6 @@ static zend_always_inline zend_result _zend_update_type_info(
31573164
}
31583165
break;
31593166
case ZEND_ASSIGN_OBJ_REF:
3160-
if (opline->op1_type == IS_CV && ssa_op->op1_def >= 0) {
3161-
tmp = t1;
3162-
if (tmp & MAY_BE_OBJECT) {
3163-
tmp |= MAY_BE_RC1 | MAY_BE_RCN;
3164-
}
3165-
UPDATE_SSA_TYPE(tmp, ssa_op->op1_def);
3166-
COPY_SSA_OBJ_TYPE(ssa_op->op1_use, ssa_op->op1_def);
3167-
}
3168-
31693167
t2 = OP1_DATA_INFO();
31703168
if ((opline+1)->op1_type == IS_VAR && (opline->extended_value & ZEND_RETURNS_FUNCTION)) {
31713169
tmp = (MAY_BE_REF | MAY_BE_RCN | MAY_BE_RC1 | t2) & ~MAY_BE_UNDEF;

Zend/Optimizer/zend_ssa.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -607,12 +607,6 @@ static zend_always_inline int _zend_ssa_rename_op(const zend_op_array *op_array,
607607
}
608608
break;
609609
case ZEND_ASSIGN_OBJ_REF:
610-
if ((build_flags & ZEND_SSA_RC_INFERENCE) && opline->op1_type == IS_CV) {
611-
ssa_ops[k].op1_def = ssa_vars_count;
612-
var[EX_VAR_TO_NUM(opline->op1.var)] = ssa_vars_count;
613-
ssa_vars_count++;
614-
//NEW_SSA_VAR(opline->op1.var)
615-
}
616610
next = opline + 1;
617611
if (next->op1_type & (IS_CV|IS_VAR|IS_TMP_VAR)) {
618612
ssa_ops[k + 1].op1_use = var[EX_VAR_TO_NUM(next->op1.var)];

0 commit comments

Comments
 (0)