Skip to content

Commit

Permalink
Fixed bug #77058
Browse files Browse the repository at this point in the history
Account for the fact that undef must be interpreted as null for
the purposes of INC/DEC inference.
  • Loading branch information
nikic committed Oct 25, 2018
1 parent e7153e8 commit f1ceec5
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
3 changes: 2 additions & 1 deletion NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ PHP NEWS
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
?? ??? 2018, PHP 7.1.25


- Opcache:
. Fixed bug #77058 (Type inference in opcache causes side effects). (Nikita)

08 Nov 2018, PHP 7.1.24

Expand Down
4 changes: 2 additions & 2 deletions ext/opcache/Optimizer/zend_inference.c
Original file line number Diff line number Diff line change
Expand Up @@ -2434,7 +2434,7 @@ static int zend_update_type_info(const zend_op_array *op_array,
tmp |= MAY_BE_RCN;
}
}
if ((t1 & MAY_BE_ANY) == MAY_BE_LONG) {
if ((t1 & (MAY_BE_ANY|MAY_BE_UNDEF)) == MAY_BE_LONG) {
if (!ssa_var_info[ssa_ops[i].op1_use].has_range ||
(opline->opcode == ZEND_PRE_DEC &&
(ssa_var_info[ssa_ops[i].op1_use].range.underflow ||
Expand Down Expand Up @@ -2496,7 +2496,7 @@ static int zend_update_type_info(const zend_op_array *op_array,
if (t1 & (MAY_BE_RC1|MAY_BE_RCN)) {
tmp |= MAY_BE_RC1;
}
if ((t1 & MAY_BE_ANY) == MAY_BE_LONG) {
if ((t1 & (MAY_BE_ANY|MAY_BE_UNDEF)) == MAY_BE_LONG) {
if (!ssa_var_info[ssa_ops[i].op1_use].has_range ||
(opline->opcode == ZEND_PRE_DEC &&
(ssa_var_info[ssa_ops[i].op1_use].range.underflow ||
Expand Down
20 changes: 20 additions & 0 deletions ext/opcache/tests/bug77058.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
--TEST--
Bug #77058: Type inference in opcache causes side effects
--FILE--
<?php

function myfunc(){
$Nr = 0;
while(1){
$x--;
$x++;
if( ++ $Nr >= 2 ) break;
}
echo "'$Nr' is expected to be 2", PHP_EOL;
}
myfunc();

?>
--EXPECTF--
Notice: Undefined variable: x in %s on line %d
'2' is expected to be 2

0 comments on commit f1ceec5

Please sign in to comment.