Skip to content

Commit

Permalink
Handle SWITCH_STRING with optimized away FREE
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
nikic committed Sep 16, 2021
1 parent 236e7ae commit 7257e7e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Zend/zend_opcode.c
Original file line number Diff line number Diff line change
Expand Up @@ -767,13 +767,13 @@ static zend_bool keeps_op1_alive(zend_op *opline) {
if (opline->opcode == ZEND_CASE
|| opline->opcode == ZEND_CASE_STRICT
|| opline->opcode == ZEND_SWITCH_LONG
|| opline->opcode == ZEND_SWITCH_STRING
|| opline->opcode == ZEND_MATCH
|| opline->opcode == ZEND_FETCH_LIST_R
|| opline->opcode == ZEND_COPY_TMP) {
return 1;
}
ZEND_ASSERT(opline->opcode != ZEND_SWITCH_STRING
&& opline->opcode != ZEND_FE_FETCH_R
ZEND_ASSERT(opline->opcode != ZEND_FE_FETCH_R
&& opline->opcode != ZEND_FE_FETCH_RW
&& opline->opcode != ZEND_FETCH_LIST_W
&& opline->opcode != ZEND_VERIFY_RETURN_TYPE
Expand Down
15 changes: 15 additions & 0 deletions ext/opcache/tests/switch_string_free_opt.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
--TEST--
A SWITCH_STRING operand FREE may be optimized away
--FILE--
<?php
function test($a) {
switch (!$a) {
case '':
r>l;
default:
}
}
?>
===DONE===
--EXPECT--
===DONE===

0 comments on commit 7257e7e

Please sign in to comment.