Skip to content

Commit 4d5c6ca

Browse files
committed
Merge branch 'PHP-8.2'
* PHP-8.2: Fix SSA construction and type inference
2 parents 5fdf95b + 7496a40 commit 4d5c6ca

File tree

3 files changed

+39
-7
lines changed

3 files changed

+39
-7
lines changed

Zend/Optimizer/zend_inference.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2305,7 +2305,13 @@ static zend_always_inline zend_result _zend_update_type_info(
23052305
* unreachable code. Propagate the empty result early, so that that the following
23062306
* code may assume that operands have at least one type. */
23072307
if (!(t1 & (MAY_BE_ANY|MAY_BE_UNDEF|MAY_BE_CLASS))
2308-
|| !(t2 & (MAY_BE_ANY|MAY_BE_UNDEF|MAY_BE_CLASS))) {
2308+
|| !(t2 & (MAY_BE_ANY|MAY_BE_UNDEF|MAY_BE_CLASS))
2309+
|| ((opline->opcode == ZEND_ASSIGN_DIM_OP
2310+
|| opline->opcode == ZEND_ASSIGN_OBJ_OP
2311+
|| opline->opcode == ZEND_ASSIGN_STATIC_PROP_OP
2312+
|| opline->opcode == ZEND_ASSIGN_DIM
2313+
|| opline->opcode == ZEND_ASSIGN_OBJ)
2314+
&& !(OP1_DATA_INFO() & (MAY_BE_ANY|MAY_BE_UNDEF|MAY_BE_CLASS)) /*&& 0*/)) {
23092315
tmp = 0;
23102316
if (ssa_op->result_def >= 0 && !(ssa_var_info[ssa_op->result_def].type & MAY_BE_REF)) {
23112317
UPDATE_SSA_TYPE(tmp, ssa_op->result_def);
@@ -2316,6 +2322,15 @@ static zend_always_inline zend_result _zend_update_type_info(
23162322
if (ssa_op->op2_def >= 0 && !(ssa_var_info[ssa_op->op2_def].type & MAY_BE_REF)) {
23172323
UPDATE_SSA_TYPE(tmp, ssa_op->op2_def);
23182324
}
2325+
if (opline->opcode == ZEND_ASSIGN_OP
2326+
|| opline->opcode == ZEND_ASSIGN_DIM_OP
2327+
|| opline->opcode == ZEND_ASSIGN_OBJ_OP
2328+
|| opline->opcode == ZEND_ASSIGN_DIM
2329+
|| opline->opcode == ZEND_ASSIGN_OBJ) {
2330+
if ((ssa_op+1)->op1_def >= 0 && !(ssa_var_info[(ssa_op+1)->op1_def].type & MAY_BE_REF)) {
2331+
UPDATE_SSA_TYPE(tmp, (ssa_op+1)->op1_def);
2332+
}
2333+
}
23192334
return SUCCESS;
23202335
}
23212336

Zend/Optimizer/zend_ssa.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -588,12 +588,6 @@ static zend_always_inline int _zend_ssa_rename_op(const zend_op_array *op_array,
588588
break;
589589
case ZEND_ASSIGN_DIM:
590590
case ZEND_ASSIGN_OBJ:
591-
if (opline->op1_type == IS_CV) {
592-
ssa_ops[k].op1_def = ssa_vars_count;
593-
var[EX_VAR_TO_NUM(opline->op1.var)] = ssa_vars_count;
594-
ssa_vars_count++;
595-
//NEW_SSA_VAR(opline->op1.var)
596-
}
597591
next = opline + 1;
598592
if (next->op1_type & (IS_CV|IS_VAR|IS_TMP_VAR)) {
599593
ssa_ops[k + 1].op1_use = var[EX_VAR_TO_NUM(next->op1.var)];
@@ -605,6 +599,12 @@ static zend_always_inline int _zend_ssa_rename_op(const zend_op_array *op_array,
605599
//NEW_SSA_VAR(next->op1.var)
606600
}
607601
}
602+
if (opline->op1_type == IS_CV) {
603+
ssa_ops[k].op1_def = ssa_vars_count;
604+
var[EX_VAR_TO_NUM(opline->op1.var)] = ssa_vars_count;
605+
ssa_vars_count++;
606+
//NEW_SSA_VAR(opline->op1.var)
607+
}
608608
break;
609609
case ZEND_ASSIGN_OBJ_REF:
610610
if (opline->op1_type == IS_CV) {
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
--TEST--
2+
Type inference 020;
3+
--INI--
4+
opcache.enable=1
5+
opcache.enable_cli=1
6+
opcache.optimization_level=-1
7+
--FILE--
8+
<?php
9+
function y() {
10+
for(;;) {
11+
$y = $y[] += 3/6 - ~$y;
12+
}
13+
}
14+
?>
15+
DONE
16+
--EXPECT--
17+
DONE

0 commit comments

Comments
 (0)