Skip to content

Commit 14b36c8

Browse files
committed
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1: Fixed GH-12511: Use must be in next opline assertion with patched infection
2 parents d906d8b + b3b46a4 commit 14b36c8

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

Zend/Optimizer/zend_inference.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3344,10 +3344,18 @@ static zend_always_inline zend_result _zend_update_type_info(
33443344
zend_uchar opcode;
33453345

33463346
if (!ssa_opcodes) {
3347-
ZEND_ASSERT(j == (opline - op_array->opcodes) + 1 && "Use must be in next opline");
3347+
if (j != (opline - op_array->opcodes) + 1) {
3348+
/* Use must be in next opline */
3349+
tmp |= key_type | MAY_BE_ARRAY_OF_ANY | MAY_BE_ARRAY_OF_REF;
3350+
break;
3351+
}
33483352
opcode = op_array->opcodes[j].opcode;
33493353
} else {
3350-
ZEND_ASSERT(ssa_opcodes[j] == opline + 1 && "Use must be in next opline");
3354+
if (ssa_opcodes[j] != opline + 1) {
3355+
/* Use must be in next opline */
3356+
tmp |= key_type | MAY_BE_ARRAY_OF_ANY | MAY_BE_ARRAY_OF_REF;
3357+
break;
3358+
}
33513359
opcode = ssa_opcodes[j]->opcode;
33523360
}
33533361
switch (opcode) {
@@ -3409,7 +3417,10 @@ static zend_always_inline zend_result _zend_update_type_info(
34093417
EMPTY_SWITCH_DEFAULT_CASE()
34103418
}
34113419
j = zend_ssa_next_use(ssa->ops, ssa_op->result_def, j);
3412-
ZEND_ASSERT(j < 0 && "There should only be one use");
3420+
if (j >= 0) {
3421+
tmp |= key_type | MAY_BE_ARRAY_OF_ANY | MAY_BE_ARRAY_OF_REF;
3422+
break;
3423+
}
34133424
}
34143425
}
34153426
if (((tmp & MAY_BE_ARRAY) && (tmp & MAY_BE_ARRAY_KEY_ANY))
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
--TEST--
2+
Type inference 022: FETCH_DIM_W
3+
--INI--
4+
opcache.enable=1
5+
opcache.enable_cli=1
6+
opcache.optimization_level=-1
7+
--FILE--
8+
<?php
9+
function &foo(&$a, $n) {
10+
foreach (array(0) as $_) {
11+
return $a[$n];
12+
}
13+
}
14+
?>
15+
DONE
16+
--EXPECT--
17+
DONE

0 commit comments

Comments
 (0)