Skip to content

Commit 6c6d36b

Browse files
committed
Fix SSA construction for ADD_ARRAY_ELEMENT in RC_INFERENCE mode
This was broken in cc29cbe.
1 parent 32fbd24 commit 6c6d36b

File tree

2 files changed

+34
-4
lines changed

2 files changed

+34
-4
lines changed

ext/opcache/Optimizer/zend_ssa.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -569,10 +569,6 @@ static int zend_ssa_rename(const zend_op_array *op_array, uint32_t build_flags,
569569
}
570570

571571
switch (opline->opcode) {
572-
case ZEND_ADD_ARRAY_UNPACK:
573-
case ZEND_ADD_ARRAY_ELEMENT:
574-
ssa_ops[k].result_use = var[EX_VAR_TO_NUM(opline->result.var)];
575-
break;
576572
case ZEND_ASSIGN:
577573
if ((build_flags & ZEND_SSA_RC_INFERENCE) && opline->op2_type == IS_CV) {
578574
ssa_ops[k].op2_def = ssa_vars_count;
@@ -718,6 +714,12 @@ static int zend_ssa_rename(const zend_op_array *op_array, uint32_t build_flags,
718714
goto add_op1_def;
719715
}
720716
break;
717+
case ZEND_ADD_ARRAY_UNPACK:
718+
ssa_ops[k].result_use = var[EX_VAR_TO_NUM(opline->result.var)];
719+
break;
720+
case ZEND_ADD_ARRAY_ELEMENT:
721+
ssa_ops[k].result_use = var[EX_VAR_TO_NUM(opline->result.var)];
722+
/* break missing intentionally */
721723
case ZEND_INIT_ARRAY:
722724
if (((build_flags & ZEND_SSA_RC_INFERENCE)
723725
|| (opline->extended_value & ZEND_ARRAY_ELEMENT_REF))

ext/opcache/tests/jit/array_elem.phpt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
--TEST--
2+
Refcount inference when adding array elements
3+
--FILE--
4+
<?php
5+
6+
function test($a) {
7+
$ary = [$a];
8+
$ary2 = [0, $ary, $ary];
9+
return $ary2;
10+
}
11+
var_dump(test(1));
12+
13+
?>
14+
--EXPECT--
15+
array(3) {
16+
[0]=>
17+
int(0)
18+
[1]=>
19+
array(1) {
20+
[0]=>
21+
int(1)
22+
}
23+
[2]=>
24+
array(1) {
25+
[0]=>
26+
int(1)
27+
}
28+
}

0 commit comments

Comments
 (0)