Skip to content

Commit 38e2762

Browse files
committed
Merge branch 'PHP-7.4'
* PHP-7.4: Fix live range calculation for FE_FETCH
2 parents a66e226 + be7eab3 commit 38e2762

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
--TEST--
2+
FE_FETCH op2 is a def and needs special live range handling
3+
--FILE--
4+
<?php
5+
try {
6+
foreach (["test"] as $k => func()[]) {}
7+
} catch (Error $e) {
8+
echo $e->getMessage(), "\n";
9+
}
10+
?>
11+
--EXPECT--
12+
Call to undefined function func()

Zend/zend_opcode.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -827,7 +827,17 @@ static void zend_calc_live_ranges(
827827
}
828828
if (opline->op2_type & (IS_TMP_VAR|IS_VAR)) {
829829
uint32_t var_num = EX_VAR_TO_NUM(opline->op2.var) - var_offset;
830-
if (EXPECTED(last_use[var_num] == (uint32_t) -1)) {
830+
if (UNEXPECTED(opline->opcode == ZEND_FE_FETCH_R
831+
|| opline->opcode == ZEND_FE_FETCH_RW)) {
832+
/* OP2 of FE_FETCH is actually a def, not a use. */
833+
if (last_use[var_num] != (uint32_t) -1) {
834+
if (opnum + 1 != last_use[var_num]) {
835+
emit_live_range(
836+
op_array, var_num, opnum, last_use[var_num], needs_live_range);
837+
}
838+
last_use[var_num] = (uint32_t) -1;
839+
}
840+
} else if (EXPECTED(last_use[var_num] == (uint32_t) -1)) {
831841
#if 1
832842
/* OP_DATA uses only op1 operand */
833843
ZEND_ASSERT(opline->opcode != ZEND_OP_DATA);

0 commit comments

Comments
 (0)