Skip to content

Commit bbd3f71

Browse files
committed
Fix COPY_TMP live range construction after optimization
If we optimize the FREE away, we should switch to constructing a normal live range, rather than a split live range. Fixes oss-fuzz #39548.
1 parent cdcdb33 commit bbd3f71

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
--TEST--
2+
Live range construction should not break if colesce assign branch is optimized away
3+
--FILE--
4+
<?php
5+
function test() {
6+
$a[X] ??= Y;
7+
var_dump($a);
8+
}
9+
define('X', 1);
10+
define('Y', 2);
11+
test();
12+
?>
13+
--EXPECT--
14+
array(1) {
15+
[1]=>
16+
int(2)
17+
}

Zend/zend_opcode.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -721,17 +721,22 @@ static void emit_live_range(
721721
* "null" branch, and another from the start of the "non-null" branch to the
722722
* FREE opcode. */
723723
uint32_t rt_var_num = EX_NUM_TO_VAR(op_array->last_var + var_num);
724-
zend_op *block_start_op = use_opline;
725-
726724
if (needs_live_range && !needs_live_range(op_array, orig_def_opline)) {
727725
return;
728726
}
729727

728+
kind = ZEND_LIVE_TMPVAR;
729+
if (use_opline->opcode != ZEND_FREE) {
730+
/* This can happen if one branch of the coalesce has been optimized away.
731+
* In this case we should emit a normal live-range instead. */
732+
break;
733+
}
734+
735+
zend_op *block_start_op = use_opline;
730736
while ((block_start_op-1)->opcode == ZEND_FREE) {
731737
block_start_op--;
732738
}
733739

734-
kind = ZEND_LIVE_TMPVAR;
735740
start = block_start_op - op_array->opcodes;
736741
if (start != end) {
737742
emit_live_range_raw(op_array, var_num, kind, start, end);

0 commit comments

Comments
 (0)