Skip to content

Commit ed652a5

Browse files
committed
Fix register allocation (missing store)
This fixes oss-fuzz #52022
1 parent 5ca4113 commit ed652a5

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

ext/opcache/jit/zend_jit_trace.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2428,6 +2428,7 @@ static zend_lifetime_interval** zend_jit_trace_allocate_registers(zend_jit_trace
24282428
const zend_ssa *op_array_ssa;
24292429
const zend_ssa_op *ssa_op;
24302430
int i, j, idx, count, level;
2431+
int last_idx = -1;
24312432
int *start, *end;
24322433
uint8_t *flags;
24332434
const zend_op_array **vars_op_array;
@@ -2831,6 +2832,7 @@ static zend_lifetime_interval** zend_jit_trace_allocate_registers(zend_jit_trace
28312832
}
28322833
}
28332834
} else {
2835+
last_idx = idx;
28342836
for (i = 0; i < op_array->last_var; i++) {
28352837
zend_jit_close_var(stack, i, start, end, flags, idx);
28362838
}
@@ -3140,6 +3142,14 @@ static zend_lifetime_interval** zend_jit_trace_allocate_registers(zend_jit_trace
31403142
}
31413143
phi = phi->next;
31423144
}
3145+
} else {
3146+
for (i = 0; i < ssa->vars_count; i++) {
3147+
if (intervals[i]
3148+
&& intervals[i]->range.end == last_idx
3149+
&& !(intervals[i]->flags & (ZREG_LOAD|ZREG_STORE))) {
3150+
intervals[i]->flags |= ZREG_STORE;
3151+
}
3152+
}
31433153
}
31443154

31453155
if (!count) {
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--TEST--
2+
Register Alloction 017: Missing 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 test() {
11+
for($i = 0; $i < 10; $i++) {
12+
$a = $b = $a + !$a = !$a;
13+
$c = $c = $a;
14+
$c % $a;
15+
}
16+
}
17+
@test();
18+
?>
19+
DONE
20+
--EXPECT--
21+
DONE

0 commit comments

Comments
 (0)