Skip to content

Commit 4d4a53b

Browse files
committed
Fix incorrect optimization of ASSIGN_OP may lead to incorrect result (sub assign -> pre dec conversion for null values)
1 parent bcc5d26 commit 4d4a53b

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

Zend/Optimizer/dfa_pass.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1687,7 +1687,7 @@ void zend_dfa_optimize_op_array(zend_op_array *op_array, zend_optimizer_ctx *ctx
16871687
&& Z_TYPE_P(CT_CONSTANT_EX(op_array, opline->op2.constant)) == IS_LONG
16881688
&& Z_LVAL_P(CT_CONSTANT_EX(op_array, opline->op2.constant)) == 1
16891689
&& ssa->ops[op_1].op1_use >= 0
1690-
&& !(ssa->var_info[ssa->ops[op_1].op1_use].type & (MAY_BE_FALSE|MAY_BE_TRUE|MAY_BE_STRING|MAY_BE_ARRAY|MAY_BE_OBJECT|MAY_BE_RESOURCE|MAY_BE_REF))) {
1690+
&& !(ssa->var_info[ssa->ops[op_1].op1_use].type & (MAY_BE_UNDEF|MAY_BE_NULL|MAY_BE_FALSE|MAY_BE_TRUE|MAY_BE_STRING|MAY_BE_ARRAY|MAY_BE_OBJECT|MAY_BE_RESOURCE|MAY_BE_REF))) {
16911691

16921692
// op_1: ASSIGN_SUB #?.CV [undef,null,int,foat] -> #v.CV, int(1) => PRE_DEC #?.CV ->#v.CV
16931693

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
--TEST--
2+
ASSIGN_OP 002: Incorrect optimization of ASSIGN_OP may lead to incorrect result (sub assign -> pre dec conversion for null values)
3+
--INI--
4+
opcache.enable=1
5+
opcache.enable_cli=1
6+
opcache.optimization_level=-1
7+
--FILE--
8+
<?php
9+
function foo(int $a = null) {
10+
$a -= 1;
11+
return $a;
12+
}
13+
var_dump(foo(2));
14+
var_dump(foo(null));
15+
?>
16+
--EXPECT--
17+
int(1)
18+
int(-1)

0 commit comments

Comments
 (0)