Skip to content

Commit d78693f

Browse files
committed
Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0: Tracing JIT: Fixed incorrect assumption about in-memeory zval type
2 parents b5a6e51 + d325163 commit d78693f

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

ext/opcache/jit/zend_jit_trace.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4807,6 +4807,16 @@ static const void *zend_jit_trace(zend_jit_trace_rec *trace_buffer, uint32_t par
48074807
op2_info = OP2_INFO();
48084808
CHECK_OP2_TRACE_TYPE();
48094809
op1_info = OP1_INFO();
4810+
if (ssa->vars[ssa_op->op1_use].no_val) {
4811+
if ((op1_info & (MAY_BE_ANY|MAY_BE_UNDEF|MAY_BE_GUARD)) == MAY_BE_LONG
4812+
|| (op1_info & (MAY_BE_ANY|MAY_BE_UNDEF|MAY_BE_GUARD)) == MAY_BE_DOUBLE) {
4813+
if (STACK_MEM_TYPE(stack, EX_VAR_TO_NUM(opline->op1.var)) != IS_LONG
4814+
&& STACK_MEM_TYPE(stack, EX_VAR_TO_NUM(opline->op1.var)) != IS_DOUBLE) {
4815+
/* type may be not set */
4816+
op1_info |= MAY_BE_NULL;
4817+
}
4818+
}
4819+
}
48104820
op1_def_info = OP1_DEF_INFO();
48114821
if (op1_type != IS_UNKNOWN && (op1_info & MAY_BE_GUARD)) {
48124822
if (op1_type < IS_STRING
@@ -6171,7 +6181,8 @@ static const void *zend_jit_trace(zend_jit_trace_rec *trace_buffer, uint32_t par
61716181
type = STACK_TYPE(stack, EX_VAR_TO_NUM(opline->op1.var));
61726182
}
61736183
SET_STACK_TYPE(stack, EX_VAR_TO_NUM(opline->op1.var), type,
6174-
(type == IS_UNKNOWN || !ra || !ra[ssa_op->op1_def]));
6184+
(type == IS_UNKNOWN || !ra ||
6185+
(!ra[ssa_op->op1_def] && !ssa->vars[ssa_op->op1_def].no_val)));
61756186
if (type != IS_UNKNOWN) {
61766187
ssa->var_info[ssa_op->op1_def].type &= ~MAY_BE_GUARD;
61776188
if (ra && ra[ssa_op->op1_def]) {
@@ -6214,7 +6225,8 @@ static const void *zend_jit_trace(zend_jit_trace_rec *trace_buffer, uint32_t par
62146225
type = STACK_TYPE(stack, EX_VAR_TO_NUM(opline->op2.var));
62156226
}
62166227
SET_STACK_TYPE(stack, EX_VAR_TO_NUM(opline->op2.var), type,
6217-
(type == IS_UNKNOWN || !ra || !ra[ssa_op->op2_def]));
6228+
(type == IS_UNKNOWN || !ra ||
6229+
(!ra[ssa_op->op2_def] && !ssa->vars[ssa_op->op2_def].no_val)));
62186230
if (type != IS_UNKNOWN) {
62196231
ssa->var_info[ssa_op->op2_def].type &= ~MAY_BE_GUARD;
62206232
if (ra && ra[ssa_op->op2_def]) {

ext/opcache/tests/jit/assign_045.phpt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
--TEST--
2+
JIT ASSIGN: incorrect assumption about in-memeory zval type
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+
--FILE--
10+
<?php
11+
function test($x, $y) {
12+
$a = $b = $a = $y;
13+
var_dump($a + $x);
14+
}
15+
test(null, 1);
16+
?>
17+
--EXPECT--
18+
int(1)
19+

0 commit comments

Comments
 (0)