Skip to content

Commit 7257e7e

Browse files
committed
Handle SWITCH_STRING with optimized away FREE
This can happen in degenerate cases where we know that the SWITCH_STRING argument is not refcounted. We should be treating it in the same way as SWITCH_LONG here.
1 parent 236e7ae commit 7257e7e

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

Zend/zend_opcode.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -767,13 +767,13 @@ static zend_bool keeps_op1_alive(zend_op *opline) {
767767
if (opline->opcode == ZEND_CASE
768768
|| opline->opcode == ZEND_CASE_STRICT
769769
|| opline->opcode == ZEND_SWITCH_LONG
770+
|| opline->opcode == ZEND_SWITCH_STRING
770771
|| opline->opcode == ZEND_MATCH
771772
|| opline->opcode == ZEND_FETCH_LIST_R
772773
|| opline->opcode == ZEND_COPY_TMP) {
773774
return 1;
774775
}
775-
ZEND_ASSERT(opline->opcode != ZEND_SWITCH_STRING
776-
&& opline->opcode != ZEND_FE_FETCH_R
776+
ZEND_ASSERT(opline->opcode != ZEND_FE_FETCH_R
777777
&& opline->opcode != ZEND_FE_FETCH_RW
778778
&& opline->opcode != ZEND_FETCH_LIST_W
779779
&& opline->opcode != ZEND_VERIFY_RETURN_TYPE
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
--TEST--
2+
A SWITCH_STRING operand FREE may be optimized away
3+
--FILE--
4+
<?php
5+
function test($a) {
6+
switch (!$a) {
7+
case '':
8+
r>l;
9+
default:
10+
}
11+
}
12+
?>
13+
===DONE===
14+
--EXPECT--
15+
===DONE===

0 commit comments

Comments
 (0)