Skip to content

Commit d508ff9

Browse files
committed
Improve fix for #69038
1 parent ffdc572 commit d508ff9

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

ext/opcache/Optimizer/zend_optimizer.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -290,15 +290,24 @@ static void replace_tmp_by_const(zend_op_array *op_array,
290290
* and allows its reuse. The number of ZEND_CASE instructions
291291
* usually terminated by ZEND_FREE that finally kills the value.
292292
*/
293-
if (opline->opcode == ZEND_CASE) {
293+
if (opline->opcode == ZEND_CASE || opline->opcode == ZEND_FREE) {
294294
zend_op *m, *n;
295295
int brk = op_array->last_brk_cont;
296+
zend_bool in_case = 0;
296297
while (brk--) {
297298
if (op_array->brk_cont_array[brk].start <= (opline - op_array->opcodes) &&
298299
op_array->brk_cont_array[brk].brk > (opline - op_array->opcodes)) {
300+
in_case = 1;
299301
break;
300302
}
301303
}
304+
305+
if (!in_case) {
306+
MAKE_NOP(opline);
307+
zval_dtor(val);
308+
break;
309+
}
310+
302311
m = opline;
303312
n = op_array->opcodes + op_array->brk_cont_array[brk].brk + 1;
304313
while (m < n) {
@@ -320,10 +329,6 @@ static void replace_tmp_by_const(zend_op_array *op_array,
320329
}
321330
zval_dtor(val);
322331
break;
323-
} else if (opline->opcode == ZEND_FREE) {
324-
MAKE_NOP(opline);
325-
zval_dtor(val);
326-
break;
327332
} else {
328333
update_op1_const(op_array, opline, val TSRMLS_CC);
329334
break;

ext/opcache/tests/bug69038.phpt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,17 @@ function b($b = "bad") {
3939
return $b;
4040
}
4141
var_dump(b());
42+
43+
function c() {
44+
switch (PHP_OS) {
45+
default: return "bad";
46+
case PHP_OS: return "okey";
47+
}
48+
}
49+
50+
var_dump(c());
4251
?>
4352
--EXPECT--
4453
string(4) "okey"
4554
string(4) "okey"
55+
string(4) "okey"

0 commit comments

Comments
 (0)