Skip to content

Commit 09bf346

Browse files
committed
Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0: JIT: Fix register alloction (missed store)
2 parents 7184783 + 478448d commit 09bf346

File tree

4 files changed

+53
-4
lines changed

4 files changed

+53
-4
lines changed

ext/opcache/jit/zend_jit_arm64.dasc

+12
Original file line numberDiff line numberDiff line change
@@ -3615,6 +3615,18 @@ static int zend_jit_update_regs(dasm_State **Dst, uint32_t var, zend_jit_addr sr
36153615
} else {
36163616
ZEND_UNREACHABLE();
36173617
}
3618+
if (!Z_LOAD(src) && !Z_STORE(src) && Z_STORE(dst)) {
3619+
zend_jit_addr var_addr = ZEND_ADDR_MEM_ZVAL(ZREG_FP, var);
3620+
3621+
if (!zend_jit_spill_store(Dst, dst, var_addr, info,
3622+
JIT_G(trigger) != ZEND_JIT_ON_HOT_TRACE ||
3623+
JIT_G(current_frame) == NULL ||
3624+
STACK_MEM_TYPE(JIT_G(current_frame)->stack, EX_VAR_TO_NUM(var)) == IS_UNKNOWN ||
3625+
(1 << STACK_MEM_TYPE(JIT_G(current_frame)->stack, EX_VAR_TO_NUM(var))) != (info & MAY_BE_ANY)
3626+
)) {
3627+
return 0;
3628+
}
3629+
}
36183630
} else if (Z_MODE(dst) == IS_MEM_ZVAL) {
36193631
if (!Z_LOAD(src) && !Z_STORE(src)) {
36203632
if (!zend_jit_spill_store(Dst, src, dst, info,

ext/opcache/jit/zend_jit_trace.c

+3-4
Original file line numberDiff line numberDiff line change
@@ -4119,7 +4119,7 @@ static const void *zend_jit_trace(zend_jit_trace_rec *trace_buffer, uint32_t par
41194119

41204120
ssa->var_info[i].type &= ~MAY_BE_GUARD;
41214121
op_type = concrete_type(ssa->var_info[i].type);
4122-
if (!zend_jit_type_guard(&dasm_state, opline, i, op_type)) {
4122+
if (!zend_jit_type_guard(&dasm_state, opline, EX_NUM_TO_VAR(i), op_type)) {
41234123
goto jit_failure;
41244124
}
41254125
SET_STACK_TYPE(stack, i, op_type, 1);
@@ -4152,7 +4152,7 @@ static const void *zend_jit_trace(zend_jit_trace_rec *trace_buffer, uint32_t par
41524152
ZEND_ASSERT(ival->reg != ZREG_NONE);
41534153

41544154
if (info & MAY_BE_GUARD) {
4155-
if (!zend_jit_type_guard(&dasm_state, opline, phi->var, concrete_type(info))) {
4155+
if (!zend_jit_type_guard(&dasm_state, opline, EX_NUM_TO_VAR(phi->var), concrete_type(info))) {
41564156
goto jit_failure;
41574157
}
41584158
info &= ~MAY_BE_GUARD;
@@ -6270,8 +6270,7 @@ static const void *zend_jit_trace(zend_jit_trace_rec *trace_buffer, uint32_t par
62706270
|| opline->opcode == ZEND_COALESCE
62716271
|| opline->opcode == ZEND_JMP_NULL
62726272
|| opline->opcode == ZEND_FE_RESET_R) {
6273-
if (!ra[ssa_op->op1_use]
6274-
|| ra[ssa_op->op1_use]->reg != ra[ssa_op->op1_def]->reg) {
6273+
if (!ra[ssa_op->op1_use]) {
62756274
flags |= ZREG_LOAD;
62766275
}
62776276
}

ext/opcache/jit/zend_jit_x86.dasc

+12
Original file line numberDiff line numberDiff line change
@@ -3955,6 +3955,18 @@ static int zend_jit_update_regs(dasm_State **Dst, uint32_t var, zend_jit_addr sr
39553955
} else {
39563956
ZEND_UNREACHABLE();
39573957
}
3958+
if (!Z_LOAD(src) && !Z_STORE(src) && Z_STORE(dst)) {
3959+
zend_jit_addr var_addr = ZEND_ADDR_MEM_ZVAL(ZREG_FP, var);
3960+
3961+
if (!zend_jit_spill_store(Dst, dst, var_addr, info,
3962+
JIT_G(trigger) != ZEND_JIT_ON_HOT_TRACE ||
3963+
JIT_G(current_frame) == NULL ||
3964+
STACK_MEM_TYPE(JIT_G(current_frame)->stack, EX_VAR_TO_NUM(var)) == IS_UNKNOWN ||
3965+
(1 << STACK_MEM_TYPE(JIT_G(current_frame)->stack, EX_VAR_TO_NUM(var))) != (info & MAY_BE_ANY)
3966+
)) {
3967+
return 0;
3968+
}
3969+
}
39583970
} else if (Z_MODE(dst) == IS_MEM_ZVAL) {
39593971
if (!Z_LOAD(src) && !Z_STORE(src)) {
39603972
if (!zend_jit_spill_store(Dst, src, dst, info,
+26
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)