Skip to content

Commit 8f0da22

Browse files
nikicdstogov
authored andcommitted
Fixes
1 parent 432d25a commit 8f0da22

File tree

1 file changed

+23
-12
lines changed

1 file changed

+23
-12
lines changed

Zend/Optimizer/zend_inference.c

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1877,6 +1877,9 @@ static uint32_t get_ssa_alias_types(zend_ssa_alias_kind alias) {
18771877
} \
18781878
} \
18791879
if (ssa_var_info[__var].type != __type) { \
1880+
ZEND_ASSERT(__ssa_var->var >= op_array->last_var || \
1881+
(ssa_var_info[__var].type & MAY_BE_REF) \
1882+
== (__type & MAY_BE_REF)); \
18801883
if (ssa_var_info[__var].type & ~__type) { \
18811884
emit_type_narrowing_warning(op_array, ssa, __var); \
18821885
return FAILURE; \
@@ -4252,7 +4255,6 @@ void zend_func_return_info(const zend_op_array *op_array,
42524255

42534256
static int zend_infer_types(const zend_op_array *op_array, const zend_script *script, zend_ssa *ssa, zend_long optimization_level)
42544257
{
4255-
zend_ssa_var_info *ssa_var_info = ssa->var_info;
42564258
int ssa_vars_count = ssa->vars_count;
42574259
int j;
42584260
zend_bitset worklist;
@@ -4264,7 +4266,6 @@ static int zend_infer_types(const zend_op_array *op_array, const zend_script *sc
42644266
/* Type Inference */
42654267
for (j = op_array->last_var; j < ssa_vars_count; j++) {
42664268
zend_bitset_incl(worklist, j);
4267-
ssa_var_info[j].type = 0;
42684269
}
42694270

42704271
if (zend_infer_types_ex(op_array, script, ssa, worklist, optimization_level) != SUCCESS) {
@@ -4322,12 +4323,12 @@ static int zend_mark_cv_references(const zend_op_array *op_array, const zend_scr
43224323
case ZEND_SEND_VAR_EX:
43234324
case ZEND_SEND_FUNC_ARG:
43244325
break;
4326+
case ZEND_INIT_ARRAY:
43254327
case ZEND_ADD_ARRAY_ELEMENT:
43264328
if (!(opline->extended_value & ZEND_ARRAY_ELEMENT_REF)) {
43274329
continue;
43284330
}
43294331
break;
4330-
case ZEND_BIND_LEXICAL:
43314332
case ZEND_BIND_STATIC:
43324333
if (!(opline->extended_value & ZEND_BIND_REF)) {
43334334
continue;
@@ -4351,8 +4352,17 @@ static int zend_mark_cv_references(const zend_op_array *op_array, const zend_scr
43514352
continue;
43524353
}
43534354
} else if (ssa->ops[def].op2_def == var) {
4354-
if (opline->opcode != ZEND_ASSIGN_REF) {
4355-
continue;
4355+
switch (opline->opcode) {
4356+
case ZEND_ASSIGN_REF:
4357+
case ZEND_FE_FETCH_RW:
4358+
break;
4359+
case ZEND_BIND_LEXICAL:
4360+
if (!(opline->extended_value & ZEND_BIND_REF)) {
4361+
continue;
4362+
}
4363+
break;
4364+
default:
4365+
continue;
43564366
}
43574367
} else {
43584368
ZEND_UNREACHABLE();
@@ -4382,12 +4392,15 @@ static int zend_mark_cv_references(const zend_op_array *op_array, const zend_scr
43824392

43834393
if (ssa->vars[var].use_chain >= 0) {
43844394
int use = ssa->vars[var].use_chain;
4385-
zend_ssa_op *op;
4386-
4387-
do {
4388-
op = ssa->ops + use;
4395+
FOREACH_USE(&ssa->vars[var], use) {
4396+
zend_ssa_op *op = ssa->ops + use;
43894397
if (op->op1_use == var && op->op1_def >= 0) {
43904398
if (!(ssa->var_info[op->op1_def].type & MAY_BE_REF)) {
4399+
/* Unset breaks references (outside global scope). */
4400+
if (op_array->opcodes[use].opcode == ZEND_UNSET_CV
4401+
&& op_array->function_name) {
4402+
continue;
4403+
}
43914404
zend_bitset_incl(worklist, op->op1_def);
43924405
}
43934406
}
@@ -4401,9 +4414,7 @@ static int zend_mark_cv_references(const zend_op_array *op_array, const zend_scr
44014414
zend_bitset_incl(worklist, op->result_def);
44024415
}
44034416
}
4404-
4405-
use = zend_ssa_next_use(ssa->ops, var, use);
4406-
} while (use >= 0);
4417+
} FOREACH_USE_END();
44074418
}
44084419
} WHILE_WORKLIST_END();
44094420

0 commit comments

Comments
 (0)