Skip to content

Commit 59b2a89

Browse files
committed
Merge branch 'PHP-7.4' into PHP-8.0
* PHP-7.4: Fix DCE of FREE of COALESCE
2 parents f421ebc + 0826a54 commit 59b2a89

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

ext/opcache/Optimizer/dce.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,16 @@ int dce_optimize_op_array(zend_op_array *op_array, zend_ssa *ssa, zend_bool reor
509509
ctx.phi_dead = alloca(sizeof(zend_ulong) * ctx.phi_worklist_len);
510510
memset(ctx.phi_dead, 0xff, sizeof(zend_ulong) * ctx.phi_worklist_len);
511511

512+
/* Mark non-CV phis as live. Even if the result is unused, we generally cannot remove one
513+
* of the producing instructions, as it combines producing the result with control flow.
514+
* This can be made more precise if there are any cases where this is not the case. */
515+
FOREACH_PHI(phi) {
516+
if (phi->var >= op_array->last_var) {
517+
zend_bitset_excl(ctx.phi_dead, phi->ssa_var);
518+
add_phi_sources_to_worklists(&ctx, phi, 0);
519+
}
520+
} FOREACH_PHI_END();
521+
512522
/* Mark reacable instruction without side effects as dead */
513523
int b = ssa->cfg.blocks_count;
514524
while (b > 0) {

ext/opcache/tests/opt/dce_009.phpt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
--TEST--
2+
Incorrect DCE of FREE of COALESCE
3+
--FILE--
4+
<?php
5+
6+
function test(?string $str) {
7+
$str ?? $str = '';
8+
return strlen($str);
9+
}
10+
11+
$foo = 'foo';
12+
$foo .= 'bar';
13+
var_dump(test($foo));
14+
15+
?>
16+
--EXPECT--
17+
int(6)

0 commit comments

Comments
 (0)