Skip to content

Commit a86ed2d

Browse files
committed
Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0: Tracing JIT: Fixed bug in register allocator.
2 parents a846547 + 1985437 commit a86ed2d

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
@@ -4042,8 +4042,17 @@ static const void *zend_jit_trace(zend_jit_trace_rec *trace_buffer, uint32_t par
40424042

40434043
if (ival) {
40444044
if (ival->flags & ZREG_LOAD) {
4045+
uint32_t info = ssa->var_info[phi->ssa_var].type;
40454046
ZEND_ASSERT(ival->reg != ZREG_NONE);
40464047

4048+
if (info & MAY_BE_GUARD) {
4049+
if (!zend_jit_type_guard(&dasm_state, opline, phi->var, concrete_type(info))) {
4050+
goto jit_failure;
4051+
}
4052+
info &= ~MAY_BE_GUARD;
4053+
ssa->var_info[phi->ssa_var].type = info;
4054+
SET_STACK_TYPE(stack, i, concrete_type(info), 1);
4055+
}
40474056
SET_STACK_REG_EX(stack, phi->var, ival->reg, ZREG_LOAD);
40484057
if (!zend_jit_load_var(&dasm_state, ssa->var_info[phi->ssa_var].type, ssa->vars[phi->ssa_var].var, ival->reg)) {
40494058
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)