Fixed GH-12511: Use must be in next opline assertion with patched infection

This commit is contained in:
Dmitry Stogov 2023-10-31 07:51:36 +03:00
parent abe3673d1f
commit b3b46a44c5
2 changed files with 31 additions and 3 deletions

View File

@ -3312,10 +3312,18 @@ static zend_always_inline int _zend_update_type_info(
zend_uchar opcode;
if (!ssa_opcodes) {
ZEND_ASSERT(j == (opline - op_array->opcodes) + 1 && "Use must be in next opline");
if (j != (opline - op_array->opcodes) + 1) {
/* Use must be in next opline */
tmp |= key_type | MAY_BE_ARRAY_OF_ANY | MAY_BE_ARRAY_OF_REF;
break;
}
opcode = op_array->opcodes[j].opcode;
} else {
ZEND_ASSERT(ssa_opcodes[j] == opline + 1 && "Use must be in next opline");
if (ssa_opcodes[j] != opline + 1) {
/* Use must be in next opline */
tmp |= key_type | MAY_BE_ARRAY_OF_ANY | MAY_BE_ARRAY_OF_REF;
break;
}
opcode = ssa_opcodes[j]->opcode;
}
switch (opcode) {
@ -3374,7 +3382,10 @@ static zend_always_inline int _zend_update_type_info(
EMPTY_SWITCH_DEFAULT_CASE()
}
j = zend_ssa_next_use(ssa->ops, ssa_op->result_def, j);
ZEND_ASSERT(j < 0 && "There should only be one use");
if (j >= 0) {
tmp |= key_type | MAY_BE_ARRAY_OF_ANY | MAY_BE_ARRAY_OF_REF;
break;
}
}
}
if (((tmp & MAY_BE_ARRAY) && (tmp & MAY_BE_ARRAY_KEY_ANY))

View File

@ -0,0 +1,17 @@
--TEST--
Type inference 022: FETCH_DIM_W
--INI--
opcache.enable=1
opcache.enable_cli=1
opcache.optimization_level=-1
--FILE--
<?php
function &foo(&$a, $n) {
foreach (array(0) as $_) {
return $a[$n];
}
}
?>
DONE
--EXPECT--
DONE