Skip to content

Commit 984f9c4

Browse files
committed
Merge branch 'PHP-8.1'
* PHP-8.1: Tracing JIT: Fixed bug in register allocator.
2 parents 2067388 + a86ed2d commit 984f9c4

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

ext/opcache/jit/zend_jit_trace.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4040,8 +4040,17 @@ static const void *zend_jit_trace(zend_jit_trace_rec *trace_buffer, uint32_t par
40404040

40414041
if (ival) {
40424042
if (ival->flags & ZREG_LOAD) {
4043+
uint32_t info = ssa->var_info[phi->ssa_var].type;
40434044
ZEND_ASSERT(ival->reg != ZREG_NONE);
40444045

4046+
if (info & MAY_BE_GUARD) {
4047+
if (!zend_jit_type_guard(&dasm_state, opline, phi->var, concrete_type(info))) {
4048+
goto jit_failure;
4049+
}
4050+
info &= ~MAY_BE_GUARD;
4051+
ssa->var_info[phi->ssa_var].type = info;
4052+
SET_STACK_TYPE(stack, i, concrete_type(info), 1);
4053+
}
40454054
SET_STACK_REG_EX(stack, phi->var, ival->reg, ZREG_LOAD);
40464055
if (!zend_jit_load_var(&dasm_state, ssa->var_info[phi->ssa_var].type, ssa->vars[phi->ssa_var].var, ival->reg)) {
40474056
goto jit_failure;
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
--TEST--
2+
Register Alloction 004: Check guard before register load
3+
--INI--
4+
opcache.enable=1
5+
opcache.enable_cli=1
6+
opcache.file_update_protection=0
7+
opcache.jit_buffer_size=1M
8+
opcache.protect_memory=1
9+
opcache.jit=tracing
10+
opcache.jit_hot_func=1
11+
--EXTENSIONS--
12+
opcache
13+
--FILE--
14+
<?php
15+
function createTree($depth) {
16+
if (!$depth) {
17+
return;
18+
}
19+
$depth--;
20+
[createTree($d), createTree($depth)]();
21+
}
22+
createTree(4);
23+
?>
24+
--EXPECTF--
25+
Warning: Undefined variable $d in %sreg_alloc_004.php on line 7
26+
27+
Warning: Undefined variable $d in %sreg_alloc_004.php on line 7
28+
29+
Warning: Undefined variable $d in %sreg_alloc_004.php on line 7
30+
31+
Warning: Undefined variable $d in %sreg_alloc_004.php on line 7
32+
33+
Fatal error: Uncaught Error: First array member is not a valid class name or object in %sreg_alloc_004.php:7
34+
Stack trace:
35+
#0 %sreg_alloc_004.php(7): createTree(0)
36+
#1 %sreg_alloc_004.php(7): createTree(1)
37+
#2 %sreg_alloc_004.php(7): createTree(2)
38+
#3 %sreg_alloc_004.php(9): createTree(3)
39+
#4 {main}
40+
thrown in %sreg_alloc_004.php on line 7

0 commit comments

Comments
 (0)