Skip to content

Commit

Permalink
Merge branch 'PHP-7.4'
Browse files Browse the repository at this point in the history
* PHP-7.4:
  Fixed bug #79412 (Opcache chokes and uses 100% CPU on specific script).
dstogov committed Mar 25, 2020
2 parents 782f7e2 + 91ee85c commit 5a05fef
Showing 2 changed files with 41 additions and 3 deletions.
19 changes: 16 additions & 3 deletions ext/opcache/Optimizer/zend_inference.c
Original file line number Diff line number Diff line change
@@ -1787,12 +1787,25 @@ static int zend_infer_ranges(const zend_op_array *op_array, zend_ssa *ssa) /* {{
}
} WHILE_WORKLIST_END();

/* Add all SCC entry variables into worklist for narrowing */
/* initialize missing ranges */
for (j = scc_var[scc]; j >= 0; j = next_scc_var[j]) {
if (!ssa->var_info[j].has_range) {
zend_inference_init_range(op_array, ssa, j, 1, ZEND_LONG_MIN, ZEND_LONG_MAX, 1);
} else if (ssa->vars[j].definition_phi &&
ssa->vars[j].definition_phi->pi < 0) {
FOR_EACH_VAR_USAGE(j, ADD_SCC_VAR);
}
}

/* widening (second round) */
WHILE_WORKLIST(worklist, worklist_len, j) {
if (zend_ssa_range_widening(op_array, ssa, j, scc)) {
FOR_EACH_VAR_USAGE(j, ADD_SCC_VAR);
}
} WHILE_WORKLIST_END();

/* Add all SCC entry variables into worklist for narrowing */
for (j = scc_var[scc]; j >= 0; j = next_scc_var[j]) {
if (ssa->vars[j].definition_phi
&& ssa->vars[j].definition_phi->pi < 0) {
/* narrowing Phi functions first */
zend_ssa_range_narrowing(op_array, ssa, j, scc);
}
25 changes: 25 additions & 0 deletions ext/opcache/tests/bug79412.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
--TEST--
Bug #79412 (Opcache chokes and uses 100% CPU on specific script)
--INI--
opcache.enable=1
opcache.optimization_level=-1
--SKIPIF--
<?php require_once('skipif.inc'); ?>
--FILE--
<?php
$limitPerRun = 10;
foreach ($foo as $bar) {
$count = 0;
foreach ($runs as $run) {
++$count;
if ($count >= $limitPerRun) {
break;
}
}
foo($limitPerRun);
}
?>
--EXPECTF--
Warning: Undefined variable: foo in %s on line %d

Warning: foreach() argument must be of type array|object, null given in %s on line %d

0 comments on commit 5a05fef

Please sign in to comment.