Skip to content

Commit fdf8fff

Browse files
committed
SCCP optimization marks the wrong target feasible when the constant is of the incorrect type
1 parent a1fdfa7 commit fdf8fff

File tree

2 files changed

+58
-2
lines changed

2 files changed

+58
-2
lines changed

ext/opcache/Optimizer/sccp.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2006,7 +2006,7 @@ static void sccp_mark_feasible_successors(
20062006
scdf_mark_edge_feasible(scdf, block_num, target);
20072007
return;
20082008
}
2009-
s = 0;
2009+
s = block->successors_count - 1;
20102010
break;
20112011
case ZEND_SWITCH_STRING:
20122012
if (Z_TYPE_P(op1) == IS_STRING) {
@@ -2024,7 +2024,7 @@ static void sccp_mark_feasible_successors(
20242024
scdf_mark_edge_feasible(scdf, block_num, target);
20252025
return;
20262026
}
2027-
s = 0;
2027+
s = block->successors_count - 1;
20282028
break;
20292029
default:
20302030
for (s = 0; s < block->successors_count; s++) {

ext/opcache/tests/bug80900.phpt

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
--TEST--
2+
Bug 80900: Switch constant with incorrect type
3+
--INI--
4+
opcache.enable=1
5+
opcache.enable_cli=1
6+
opcache.optimization_level=-1
7+
--SKIPIF--
8+
<?php require_once('skipif.inc'); ?>
9+
--FILE--
10+
<?php
11+
function switchLong() {
12+
$var = 'foo';
13+
/* The number of case clauses needs to be greater than 5,
14+
* otherwise it will not be compiled into SWITCH_LONG. */
15+
switch ($var) {
16+
case 1:
17+
echo 'no1';
18+
break;
19+
case 2:
20+
echo 'no2';
21+
break;
22+
case 3:
23+
echo 'no3';
24+
break;
25+
case 4:
26+
echo 'no4';
27+
break;
28+
case 5:
29+
echo 'no5';
30+
break;
31+
default:
32+
echo 'yes';
33+
break;
34+
}
35+
echo PHP_EOL;
36+
}
37+
38+
function switchString() {
39+
$var = false;
40+
switch ($var) {
41+
case 'string':
42+
echo 'no';
43+
break;
44+
default:
45+
echo 'yes';
46+
break;
47+
}
48+
echo PHP_EOL;
49+
}
50+
51+
switchLong();
52+
switchString();
53+
?>
54+
--EXPECT--
55+
yes
56+
yes

0 commit comments

Comments
 (0)