Skip to content

Commit 823888c

Browse files
committed
Start block at loop var free
This ensures that code directly before the loop var free is separated out (and will generally be eliminated as unreachable). This fixes some assumptions we have that unreachable loop var free blocks start with the loop var free. Fixes oss-fuzz #39395.
1 parent ddf8910 commit 823888c

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
--TEST--
2+
Code before loop var free
3+
--FILE--
4+
<?php
5+
switch ($x > 0) {
6+
default:
7+
return;
8+
Y;
9+
}
10+
?>
11+
--EXPECTF--
12+
Warning: Undefined variable $x in %s on line %d

ext/opcache/Optimizer/zend_cfg.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -434,13 +434,12 @@ int zend_build_cfg(zend_arena **arena, const zend_op_array *op_array, uint32_t b
434434
flags |= ZEND_FUNC_HAS_EXTENDED_FCALL;
435435
break;
436436
case ZEND_FREE:
437-
if (opline->extended_value == ZEND_FREE_SWITCH) {
437+
case ZEND_FE_FREE:
438+
if (zend_optimizer_is_loop_var_free(opline)) {
439+
BB_START(i);
438440
flags |= ZEND_FUNC_FREE_LOOP_VAR;
439441
}
440442
break;
441-
case ZEND_FE_FREE:
442-
flags |= ZEND_FUNC_FREE_LOOP_VAR;
443-
break;
444443
}
445444
}
446445

0 commit comments

Comments
 (0)