Skip to content

Commit fa3d603

Browse files
committed
Mark ASSIGN result as UNUSED in SCCP
We can't drop the ASSIGN entirely, but we should mark the result as UNUSED. Otherwise we'll replace uses of it in operands and will not free the ASSIGN result value. This can happen with non-interned strings, but possibly there's some other cases that can trigger this as well.
1 parent 260d2ac commit fa3d603

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

Zend/Optimizer/sccp.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2188,12 +2188,13 @@ static int try_remove_definition(sccp_ctx *ctx, int var_num, zend_ssa_var *var,
21882188
zend_op *opline = &op_array->opcodes[var->definition];
21892189
zend_ssa_op *ssa_op = &ssa->ops[var->definition];
21902190

2191-
if (opline->opcode == ZEND_ASSIGN) {
2192-
/* Leave assigns to DCE (due to dtor effects) */
2193-
return 0;
2194-
}
2195-
21962191
if (ssa_op->result_def == var_num) {
2192+
if (opline->opcode == ZEND_ASSIGN) {
2193+
/* We can't drop the ASSIGN, but we can remove the result. */
2194+
opline->result_type = IS_UNUSED;
2195+
zend_ssa_remove_result_def(ssa, ssa_op);
2196+
return 0;
2197+
}
21972198
if (ssa_op->op1_def >= 0
21982199
|| ssa_op->op2_def >= 0) {
21992200
/* we cannot remove instruction that defines other variables */
@@ -2257,6 +2258,11 @@ static int try_remove_definition(sccp_ctx *ctx, int var_num, zend_ssa_var *var,
22572258
}
22582259
}
22592260
} else if (ssa_op->op1_def == var_num) {
2261+
if (opline->opcode == ZEND_ASSIGN) {
2262+
/* Leave assigns to DCE (due to dtor effects) */
2263+
return 0;
2264+
}
2265+
22602266
/* Compound assign or incdec -> convert to direct ASSIGN */
22612267

22622268
if (!value) {

0 commit comments

Comments
 (0)