Skip to content

Commit 8360e9d

Browse files
committed
Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0: Fix COPY_TMP live range construction after optimization
2 parents e8e4852 + bbd3f71 commit 8360e9d

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
@@ -783,17 +783,22 @@ static void emit_live_range(
783783
* "null" branch, and another from the start of the "non-null" branch to the
784784
* FREE opcode. */
785785
uint32_t rt_var_num = EX_NUM_TO_VAR(op_array->last_var + var_num);
786-
zend_op *block_start_op = use_opline;
787-
788786
if (needs_live_range && !needs_live_range(op_array, orig_def_opline)) {
789787
return;
790788
}
791789

790+
kind = ZEND_LIVE_TMPVAR;
791+
if (use_opline->opcode != ZEND_FREE) {
792+
/* This can happen if one branch of the coalesce has been optimized away.
793+
* In this case we should emit a normal live-range instead. */
794+
break;
795+
}
796+
797+
zend_op *block_start_op = use_opline;
792798
while ((block_start_op-1)->opcode == ZEND_FREE) {
793799
block_start_op--;
794800
}
795801

796-
kind = ZEND_LIVE_TMPVAR;
797802
start = block_start_op - op_array->opcodes;
798803
if (start != end) {
799804
emit_live_range_raw(op_array, var_num, kind, start, end);

0 commit comments

Comments
 (0)