Skip to content

Commit 8ed14f6

Browse files
committed
Merge branch 'PHP-8.1'
* PHP-8.1: JIT: Fix register alloction (missed store)
2 parents 107997e + 09bf346 commit 8ed14f6

File tree

4 files changed

+53
-4
lines changed

4 files changed

+53
-4
lines changed

ext/opcache/jit/zend_jit_arm64.dasc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3610,6 +3610,18 @@ static int zend_jit_update_regs(dasm_State **Dst, uint32_t var, zend_jit_addr sr
36103610
} else {
36113611
ZEND_UNREACHABLE();
36123612
}
3613+
if (!Z_LOAD(src) && !Z_STORE(src) && Z_STORE(dst)) {
3614+
zend_jit_addr var_addr = ZEND_ADDR_MEM_ZVAL(ZREG_FP, var);
3615+
3616+
if (!zend_jit_spill_store(Dst, dst, var_addr, info,
3617+
JIT_G(trigger) != ZEND_JIT_ON_HOT_TRACE ||
3618+
JIT_G(current_frame) == NULL ||
3619+
STACK_MEM_TYPE(JIT_G(current_frame)->stack, EX_VAR_TO_NUM(var)) == IS_UNKNOWN ||
3620+
(1 << STACK_MEM_TYPE(JIT_G(current_frame)->stack, EX_VAR_TO_NUM(var))) != (info & MAY_BE_ANY)
3621+
)) {
3622+
return 0;
3623+
}
3624+
}
36133625
} else if (Z_MODE(dst) == IS_MEM_ZVAL) {
36143626
if (!Z_LOAD(src) && !Z_STORE(src)) {
36153627
if (!zend_jit_spill_store(Dst, src, dst, info,

ext/opcache/jit/zend_jit_trace.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4130,7 +4130,7 @@ static const void *zend_jit_trace(zend_jit_trace_rec *trace_buffer, uint32_t par
41304130

41314131
ssa->var_info[i].type &= ~MAY_BE_GUARD;
41324132
op_type = concrete_type(ssa->var_info[i].type);
4133-
if (!zend_jit_type_guard(&dasm_state, opline, i, op_type)) {
4133+
if (!zend_jit_type_guard(&dasm_state, opline, EX_NUM_TO_VAR(i), op_type)) {
41344134
goto jit_failure;
41354135
}
41364136
SET_STACK_TYPE(stack, i, op_type, 1);
@@ -4163,7 +4163,7 @@ static const void *zend_jit_trace(zend_jit_trace_rec *trace_buffer, uint32_t par
41634163
ZEND_ASSERT(ival->reg != ZREG_NONE);
41644164

41654165
if (info & MAY_BE_GUARD) {
4166-
if (!zend_jit_type_guard(&dasm_state, opline, phi->var, concrete_type(info))) {
4166+
if (!zend_jit_type_guard(&dasm_state, opline, EX_NUM_TO_VAR(phi->var), concrete_type(info))) {
41674167
goto jit_failure;
41684168
}
41694169
info &= ~MAY_BE_GUARD;
@@ -6274,8 +6274,7 @@ static const void *zend_jit_trace(zend_jit_trace_rec *trace_buffer, uint32_t par
62746274
|| opline->opcode == ZEND_COALESCE
62756275
|| opline->opcode == ZEND_JMP_NULL
62766276
|| opline->opcode == ZEND_FE_RESET_R) {
6277-
if (!ra[ssa_op->op1_use]
6278-
|| ra[ssa_op->op1_use]->reg != ra[ssa_op->op1_def]->reg) {
6277+
if (!ra[ssa_op->op1_use]) {
62796278
flags |= ZREG_LOAD;
62806279
}
62816280
}

ext/opcache/jit/zend_jit_x86.dasc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3950,6 +3950,18 @@ static int zend_jit_update_regs(dasm_State **Dst, uint32_t var, zend_jit_addr sr
39503950
} else {
39513951
ZEND_UNREACHABLE();
39523952
}
3953+
if (!Z_LOAD(src) && !Z_STORE(src) && Z_STORE(dst)) {
3954+
zend_jit_addr var_addr = ZEND_ADDR_MEM_ZVAL(ZREG_FP, var);
3955+
3956+
if (!zend_jit_spill_store(Dst, dst, var_addr, info,
3957+
JIT_G(trigger) != ZEND_JIT_ON_HOT_TRACE ||
3958+
JIT_G(current_frame) == NULL ||
3959+
STACK_MEM_TYPE(JIT_G(current_frame)->stack, EX_VAR_TO_NUM(var)) == IS_UNKNOWN ||
3960+
(1 << STACK_MEM_TYPE(JIT_G(current_frame)->stack, EX_VAR_TO_NUM(var))) != (info & MAY_BE_ANY)
3961+
)) {
3962+
return 0;
3963+
}
3964+
}
39533965
} else if (Z_MODE(dst) == IS_MEM_ZVAL) {
39543966
if (!Z_LOAD(src) && !Z_STORE(src)) {
39553967
if (!zend_jit_spill_store(Dst, src, dst, info,
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
--TEST--
2+
Register Alloction 007: 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 < 100; $i++) {
12+
$a = $a + $a = $a + !$a = $a;
13+
$aZ = $a;
14+
@$aZ %= $a;
15+
}
16+
}
17+
test();
18+
?>
19+
--EXPECTF--
20+
Warning: Undefined variable $a in %sreg_alloc_007.php on line 4
21+
22+
Fatal error: Uncaught DivisionByZeroError: Modulo by zero in %sreg_alloc_007.php:6
23+
Stack trace:
24+
#0 %sreg_alloc_007.php(9): test()
25+
#1 {main}
26+
thrown in %sreg_alloc_007.php on line 6

0 commit comments

Comments
 (0)