Skip to content

Commit 6487875

Browse files
committed
Fix scdf loop var free check for phi vars
The variable may come from a phi node, in which case we should take the defining block from it. Fixes oss-fuzz #40453.
1 parent 55aadc6 commit 6487875

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

Zend/Optimizer/scdf.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -190,14 +190,18 @@ static bool is_live_loop_var_free(
190190
return false;
191191
}
192192

193-
int ssa_var = ssa_op->op1_use;
194-
if (ssa_var < 0) {
193+
int var = ssa_op->op1_use;
194+
if (var < 0) {
195195
return false;
196196
}
197197

198-
int op_num = scdf->ssa->vars[ssa_var].definition;
199-
ZEND_ASSERT(op_num >= 0);
200-
uint32_t def_block = scdf->ssa->cfg.map[op_num];
198+
zend_ssa_var *ssa_var = &scdf->ssa->vars[var];
199+
uint32_t def_block;
200+
if (ssa_var->definition >= 0) {
201+
def_block = scdf->ssa->cfg.map[ssa_var->definition];
202+
} else {
203+
def_block = ssa_var->definition_phi->block;
204+
}
201205
return zend_bitset_in(scdf->executable_blocks, def_block);
202206
}
203207

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
--TEST--
2+
Unreachable code elimination when match argument is a phi node
3+
--FILE--
4+
<?php
5+
$x = true;
6+
match ($x and true or true) {
7+
false => $x
8+
};
9+
?>
10+
--EXPECTF--
11+
Fatal error: Uncaught UnhandledMatchError: Unhandled match case true in %s:%d
12+
Stack trace:
13+
#0 {main}
14+
thrown in %s on line %d

0 commit comments

Comments
 (0)