Skip to content

Commit

Permalink
Tracing JIT: Fixed incorrect assumption about in-memeory zval type
Browse files Browse the repository at this point in the history
  • Loading branch information
dstogov committed Oct 22, 2021
1 parent c7e974f commit d325163
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
16 changes: 14 additions & 2 deletions ext/opcache/jit/zend_jit_trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -4564,6 +4564,16 @@ static const void *zend_jit_trace(zend_jit_trace_rec *trace_buffer, uint32_t par
op2_info = OP2_INFO();
CHECK_OP2_TRACE_TYPE();
op1_info = OP1_INFO();
if (ssa->vars[ssa_op->op1_use].no_val) {
if ((op1_info & (MAY_BE_ANY|MAY_BE_UNDEF|MAY_BE_GUARD)) == MAY_BE_LONG
|| (op1_info & (MAY_BE_ANY|MAY_BE_UNDEF|MAY_BE_GUARD)) == MAY_BE_DOUBLE) {
if (STACK_MEM_TYPE(stack, EX_VAR_TO_NUM(opline->op1.var)) != IS_LONG
&& STACK_MEM_TYPE(stack, EX_VAR_TO_NUM(opline->op1.var)) != IS_DOUBLE) {
/* type may be not set */
op1_info |= MAY_BE_NULL;
}
}
}
CHECK_OP1_TRACE_TYPE();
op1_def_info = OP1_DEF_INFO();
op1_addr = OP1_REG_ADDR();
Expand Down Expand Up @@ -5887,7 +5897,8 @@ static const void *zend_jit_trace(zend_jit_trace_rec *trace_buffer, uint32_t par
type = STACK_TYPE(stack, EX_VAR_TO_NUM(opline->op1.var));
}
SET_STACK_TYPE(stack, EX_VAR_TO_NUM(opline->op1.var), type,
(type == IS_UNKNOWN || !ra || !ra[ssa_op->op1_def]));
(type == IS_UNKNOWN || !ra ||
(!ra[ssa_op->op1_def] && !ssa->vars[ssa_op->op1_def].no_val)));
if (type != IS_UNKNOWN) {
ssa->var_info[ssa_op->op1_def].type &= ~MAY_BE_GUARD;
if (ra && ra[ssa_op->op1_def]) {
Expand Down Expand Up @@ -5930,7 +5941,8 @@ static const void *zend_jit_trace(zend_jit_trace_rec *trace_buffer, uint32_t par
type = STACK_TYPE(stack, EX_VAR_TO_NUM(opline->op2.var));
}
SET_STACK_TYPE(stack, EX_VAR_TO_NUM(opline->op2.var), type,
(type == IS_UNKNOWN || !ra || !ra[ssa_op->op2_def]));
(type == IS_UNKNOWN || !ra ||
(!ra[ssa_op->op2_def] && !ssa->vars[ssa_op->op2_def].no_val)));
if (type != IS_UNKNOWN) {
ssa->var_info[ssa_op->op2_def].type &= ~MAY_BE_GUARD;
if (ra && ra[ssa_op->op2_def]) {
Expand Down
19 changes: 19 additions & 0 deletions ext/opcache/tests/jit/assign_045.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
--TEST--
JIT ASSIGN: incorrect assumption about in-memeory zval type
--INI--
opcache.enable=1
opcache.enable_cli=1
opcache.file_update_protection=0
opcache.jit_buffer_size=1M
opcache.protect_memory=1
--FILE--
<?php
function test($x, $y) {
$a = $b = $a = $y;
var_dump($a + $x);
}
test(null, 1);
?>
--EXPECT--
int(1)

0 comments on commit d325163

Please sign in to comment.