Skip to content

Commit 3198b87

Browse files
committed
JIT: Fix register allocation
Fixes oss-fuzz #44689
1 parent 84a638a commit 3198b87

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

ext/opcache/jit/zend_jit.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,8 @@ static zend_bool zend_ssa_is_last_use(const zend_op_array *op_array, const zend_
145145
} while (phi);
146146
}
147147

148-
next_use = zend_ssa_next_use(ssa->ops, var, use);
149-
if (next_use < 0) {
148+
if (ssa->cfg.blocks[ssa->cfg.map[use]].loop_header > 0
149+
|| (ssa->cfg.blocks[ssa->cfg.map[use]].flags & ZEND_BB_LOOP_HEADER)) {
150150
int b = ssa->cfg.map[use];
151151
int prev_use = ssa->vars[var].use_chain;
152152

@@ -158,6 +158,10 @@ static zend_bool zend_ssa_is_last_use(const zend_op_array *op_array, const zend_
158158
}
159159
prev_use = zend_ssa_next_use(ssa->ops, var, prev_use);
160160
}
161+
}
162+
163+
next_use = zend_ssa_next_use(ssa->ops, var, use);
164+
if (next_use < 0) {
161165
return 1;
162166
} else if (zend_ssa_is_no_val_use(op_array->opcodes + next_use, ssa->ops + next_use, var)) {
163167
return 1;
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
--TEST--
2+
Register Alloction 010: Missed store
3+
--INI--
4+
opcache.enable=1
5+
opcache.enable_cli=1
6+
opcache.file_update_protection=0
7+
opcache.jit_buffer_size=1M
8+
--FILE--
9+
<?php
10+
function foo($y) {
11+
for (; $cnt < 6; $cnt++) {
12+
for ($i=0; $i <.1; $i++)
13+
for(;$y;);
14+
[$i=$y];
15+
}
16+
}
17+
foo(null);
18+
?>
19+
DONE
20+
--EXPECTF--
21+
Warning: Undefined variable $cnt in %sreg_alloc_010.php on line 3
22+
23+
Warning: Undefined variable $cnt in %sreg_alloc_010.php on line 3
24+
DONE

0 commit comments

Comments
 (0)