Skip to content

Commit 56d7672

Browse files
committed
Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0: Fixed incorrect DCE for FREE
2 parents 8b8cf8f + 78c7289 commit 56d7672

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

Zend/Optimizer/dce.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,8 @@ static inline bool is_free_of_live_var(context *ctx, zend_op *opline, zend_ssa_o
398398
switch (opline->opcode) {
399399
case ZEND_FREE:
400400
/* It is always safe to remove FREEs of non-refcounted values, even if they are live. */
401-
if (!may_be_refcounted(ctx->ssa->var_info[ssa_op->op1_use].type)) {
401+
if ((ctx->ssa->var_info[ssa_op->op1_use].type & (MAY_BE_REF|MAY_BE_ANY|MAY_BE_UNDEF)) != 0
402+
&& !may_be_refcounted(ctx->ssa->var_info[ssa_op->op1_use].type)) {
402403
return 0;
403404
}
404405
ZEND_FALLTHROUGH;

ext/opcache/tests/opt/dce_013.phpt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
--TEST--
2+
Incorrect DCE of FREE
3+
--FILE--
4+
<?php
5+
function foo() {
6+
$a = $r[] = $r = []&$y;
7+
list(&$y)=$a;
8+
}
9+
?>
10+
DONE
11+
--EXPECT--
12+
DONE

0 commit comments

Comments
 (0)