Skip to content

Commit 34c2324

Browse files
committed
Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0: Fix too aggressive DCE that leads to memory leak
2 parents e700864 + 965dafe commit 34c2324

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
@@ -2254,21 +2254,31 @@ static int try_remove_definition(sccp_ctx *ctx, int var_num, zend_ssa_var *var,
22542254
zend_optimizer_update_op1_const(ctx->scdf.op_array, opline, value);
22552255
}
22562256
return 0;
2257-
} else {
2258-
zend_ssa_remove_result_def(ssa, ssa_op);
2259-
if (opline->opcode == ZEND_DO_ICALL) {
2260-
removed_ops = remove_call(ctx, opline, ssa_op);
2261-
} else if (opline->opcode == ZEND_TYPE_CHECK
2262-
&& (opline->op1_type & (IS_VAR|IS_TMP_VAR))
2263-
&& (!value_known(&ctx->values[ssa_op->op1_use])
2264-
|| IS_PARTIAL_ARRAY(&ctx->values[ssa_op->op1_use])
2265-
|| IS_PARTIAL_OBJECT(&ctx->values[ssa_op->op1_use]))) {
2257+
} else if ((opline->op2_type & (IS_VAR|IS_TMP_VAR))
2258+
&& (!value_known(&ctx->values[ssa_op->op2_use])
2259+
|| IS_PARTIAL_ARRAY(&ctx->values[ssa_op->op2_use])
2260+
|| IS_PARTIAL_OBJECT(&ctx->values[ssa_op->op2_use]))) {
2261+
return 0;
2262+
} else if ((opline->op1_type & (IS_VAR|IS_TMP_VAR))
2263+
&& (!value_known(&ctx->values[ssa_op->op1_use])
2264+
|| IS_PARTIAL_ARRAY(&ctx->values[ssa_op->op1_use])
2265+
|| IS_PARTIAL_OBJECT(&ctx->values[ssa_op->op1_use]))) {
2266+
if (opline->opcode == ZEND_TYPE_CHECK
2267+
|| opline->opcode == ZEND_BOOL) {
2268+
zend_ssa_remove_result_def(ssa, ssa_op);
22662269
/* For TYPE_CHECK we may compute the result value without knowing the
22672270
* operand, based on type inference information. Make sure the operand is
22682271
* freed and leave further cleanup to DCE. */
22692272
opline->opcode = ZEND_FREE;
22702273
opline->result_type = IS_UNUSED;
22712274
removed_ops++;
2275+
} else {
2276+
return 0;
2277+
}
2278+
} else {
2279+
zend_ssa_remove_result_def(ssa, ssa_op);
2280+
if (opline->opcode == ZEND_DO_ICALL) {
2281+
removed_ops = remove_call(ctx, opline, ssa_op);
22722282
} else {
22732283
zend_ssa_remove_instr(ssa, opline, ssa_op);
22742284
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)