SCCP optimization marks the wrong target feasible when the constant is of the incorrect type.

Closes GH-6861.
This commit is contained in:
twosee 2021-04-13 18:15:39 +08:00
parent 976e71a2fa
commit 7c6cf09463
No known key found for this signature in database
GPG Key ID: 0450D9046197760D
3 changed files with 61 additions and 2 deletions

3
NEWS
View File

@ -6,6 +6,9 @@ PHP NEWS
. Fixed bug #80933 (SplFileObject::DROP_NEW_LINE is broken for NUL and CR).
(cmb, Nikita)
- Opcache:
. Fixed bug #80900 (switch statement behavior inside function). (twosee)
29 Apr 2021, PHP 7.4.18
- Core:

View File

@ -2006,7 +2006,7 @@ static void sccp_mark_feasible_successors(
scdf_mark_edge_feasible(scdf, block_num, target);
return;
}
s = 0;
s = block->successors_count - 1;
break;
case ZEND_SWITCH_STRING:
if (Z_TYPE_P(op1) == IS_STRING) {
@ -2024,7 +2024,7 @@ static void sccp_mark_feasible_successors(
scdf_mark_edge_feasible(scdf, block_num, target);
return;
}
s = 0;
s = block->successors_count - 1;
break;
default:
for (s = 0; s < block->successors_count; s++) {

View File

@ -0,0 +1,56 @@
--TEST--
Bug 80900: Switch constant with incorrect type
--INI--
opcache.enable=1
opcache.enable_cli=1
opcache.optimization_level=-1
--SKIPIF--
<?php require_once('skipif.inc'); ?>
--FILE--
<?php
function switchLong() {
$var = 'foo';
/* The number of case clauses needs to be greater than 5,
* otherwise it will not be compiled into SWITCH_LONG. */
switch ($var) {
case 1:
echo 'no1';
break;
case 2:
echo 'no2';
break;
case 3:
echo 'no3';
break;
case 4:
echo 'no4';
break;
case 5:
echo 'no5';
break;
default:
echo 'yes';
break;
}
echo PHP_EOL;
}
function switchString() {
$var = false;
switch ($var) {
case 'string':
echo 'no';
break;
default:
echo 'yes';
break;
}
echo PHP_EOL;
}
switchLong();
switchString();
?>
--EXPECT--
yes
yes