Skip to content

Commit 36ce177

Browse files
committed
Merge branch 'PHP-8.1'
* PHP-8.1: Fixed incorrect DCE for FREE
2 parents 5ca5f06 + 56d7672 commit 36ce177

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
@@ -397,7 +397,8 @@ static inline bool is_free_of_live_var(context *ctx, zend_op *opline, zend_ssa_o
397397
switch (opline->opcode) {
398398
case ZEND_FREE:
399399
/* It is always safe to remove FREEs of non-refcounted values, even if they are live. */
400-
if (!may_be_refcounted(ctx->ssa->var_info[ssa_op->op1_use].type)) {
400+
if ((ctx->ssa->var_info[ssa_op->op1_use].type & (MAY_BE_REF|MAY_BE_ANY|MAY_BE_UNDEF)) != 0
401+
&& !may_be_refcounted(ctx->ssa->var_info[ssa_op->op1_use].type)) {
401402
return 0;
402403
}
403404
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)