Skip to content

Commit 2af3323

Browse files
committed
Merge branch 'PHP-8.1'
* PHP-8.1: Fix too aggressive DCE that leads to memory leak
2 parents e7c2e11 + 34c2324 commit 2af3323

File tree

2 files changed

+32
-9
lines changed

2 files changed

+32
-9
lines changed

Zend/Optimizer/sccp.c

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2108,21 +2108,31 @@ static int try_remove_definition(sccp_ctx *ctx, int var_num, zend_ssa_var *var,
21082108
zend_optimizer_update_op1_const(ctx->scdf.op_array, opline, value);
21092109
}
21102110
return 0;
2111-
} else {
2112-
zend_ssa_remove_result_def(ssa, ssa_op);
2113-
if (opline->opcode == ZEND_DO_ICALL) {
2114-
removed_ops = remove_call(ctx, opline, ssa_op);
2115-
} else if (opline->opcode == ZEND_TYPE_CHECK
2116-
&& (opline->op1_type & (IS_VAR|IS_TMP_VAR))
2117-
&& (!value_known(&ctx->values[ssa_op->op1_use])
2118-
|| IS_PARTIAL_ARRAY(&ctx->values[ssa_op->op1_use])
2119-
|| IS_PARTIAL_OBJECT(&ctx->values[ssa_op->op1_use]))) {
2111+
} else if ((opline->op2_type & (IS_VAR|IS_TMP_VAR))
2112+
&& (!value_known(&ctx->values[ssa_op->op2_use])
2113+
|| IS_PARTIAL_ARRAY(&ctx->values[ssa_op->op2_use])
2114+
|| IS_PARTIAL_OBJECT(&ctx->values[ssa_op->op2_use]))) {
2115+
return 0;
2116+
} else if ((opline->op1_type & (IS_VAR|IS_TMP_VAR))
2117+
&& (!value_known(&ctx->values[ssa_op->op1_use])
2118+
|| IS_PARTIAL_ARRAY(&ctx->values[ssa_op->op1_use])
2119+
|| IS_PARTIAL_OBJECT(&ctx->values[ssa_op->op1_use]))) {
2120+
if (opline->opcode == ZEND_TYPE_CHECK
2121+
|| opline->opcode == ZEND_BOOL) {
2122+
zend_ssa_remove_result_def(ssa, ssa_op);
21202123
/* For TYPE_CHECK we may compute the result value without knowing the
21212124
* operand, based on type inference information. Make sure the operand is
21222125
* freed and leave further cleanup to DCE. */
21232126
opline->opcode = ZEND_FREE;
21242127
opline->result_type = IS_UNUSED;
21252128
removed_ops++;
2129+
} else {
2130+
return 0;
2131+
}
2132+
} else {
2133+
zend_ssa_remove_result_def(ssa, ssa_op);
2134+
if (opline->opcode == ZEND_DO_ICALL) {
2135+
removed_ops = remove_call(ctx, opline, ssa_op);
21262136
} else {
21272137
zend_ssa_remove_instr(ssa, opline, ssa_op);
21282138
removed_ops++;

ext/opcache/tests/opt/sccp_037.phpt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
--TEST--
2+
SCCP 037: Memory leak
3+
--INI--
4+
opcache.enable=1
5+
opcache.enable_cli=1
6+
opcache.optimization_level=-1
7+
--FILE--
8+
<?php
9+
[!![[new ERROR]]];
10+
?>
11+
DONE
12+
--EXPECT--
13+
DONE

0 commit comments

Comments
 (0)