Skip to content

Commit 586b2f8

Browse files
committed
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2: Fixed GH-12511: Use must be in next opline assertion with patched infection
2 parents 004d895 + 14b36c8 commit 586b2f8

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
@@ -3348,10 +3348,18 @@ static zend_always_inline zend_result _zend_update_type_info(
33483348
uint8_t opcode;
33493349

33503350
if (!ssa_opcodes) {
3351-
ZEND_ASSERT(j == (opline - op_array->opcodes) + 1 && "Use must be in next opline");
3351+
if (j != (opline - op_array->opcodes) + 1) {
3352+
/* Use must be in next opline */
3353+
tmp |= key_type | MAY_BE_ARRAY_OF_ANY | MAY_BE_ARRAY_OF_REF;
3354+
break;
3355+
}
33523356
opcode = op_array->opcodes[j].opcode;
33533357
} else {
3354-
ZEND_ASSERT(ssa_opcodes[j] == opline + 1 && "Use must be in next opline");
3358+
if (ssa_opcodes[j] != opline + 1) {
3359+
/* Use must be in next opline */
3360+
tmp |= key_type | MAY_BE_ARRAY_OF_ANY | MAY_BE_ARRAY_OF_REF;
3361+
break;
3362+
}
33553363
opcode = ssa_opcodes[j]->opcode;
33563364
}
33573365
switch (opcode) {
@@ -3413,7 +3421,10 @@ static zend_always_inline zend_result _zend_update_type_info(
34133421
EMPTY_SWITCH_DEFAULT_CASE()
34143422
}
34153423
j = zend_ssa_next_use(ssa->ops, ssa_op->result_def, j);
3416-
ZEND_ASSERT(j < 0 && "There should only be one use");
3424+
if (j >= 0) {
3425+
tmp |= key_type | MAY_BE_ARRAY_OF_ANY | MAY_BE_ARRAY_OF_REF;
3426+
break;
3427+
}
34173428
}
34183429
}
34193430
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)