Skip to content

Commit

Permalink
Fixed incorrect guard elimination
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmitry Stogov committed Nov 12, 2021
1 parent b1e6fde commit 12d02e6
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
10 changes: 8 additions & 2 deletions ext/opcache/jit/zend_jit_trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -964,6 +964,10 @@ static int is_checked_guard(const zend_ssa *tssa, const zend_op **ssa_opcodes, u
|| opline->opcode == ZEND_PRE_INC
|| opline->opcode == ZEND_POST_DEC
|| opline->opcode == ZEND_POST_INC) {
if (tssa->ops[idx].op1_use >= 0
&& (tssa->var_info[tssa->ops[idx].op1_use].type & MAY_BE_STRING)) {
return 0;
}
return 1;
} else if (opline->opcode == ZEND_ASSIGN_OP
&& (opline->extended_value == ZEND_ADD
Expand Down Expand Up @@ -3974,14 +3978,16 @@ static const void *zend_jit_trace(zend_jit_trace_rec *trace_buffer, uint32_t par
zend_may_throw(opline, ssa_op, op_array, ssa))) {
goto jit_failure;
}
if ((op1_def_info & (MAY_BE_ANY|MAY_BE_GUARD)) == (MAY_BE_LONG|MAY_BE_GUARD)) {
if ((op1_def_info & (MAY_BE_ANY|MAY_BE_GUARD)) == (MAY_BE_LONG|MAY_BE_GUARD)
&& !(op1_info & MAY_BE_STRING)) {
ssa->var_info[ssa_op->op1_def].type &= ~MAY_BE_GUARD;
if (opline->result_type != IS_UNUSED) {
ssa->var_info[ssa_op->result_def].type &= ~MAY_BE_GUARD;
}
}
if (opline->result_type != IS_UNUSED
&& (res_info & (MAY_BE_ANY|MAY_BE_GUARD)) == (MAY_BE_LONG|MAY_BE_GUARD)) {
&& (res_info & (MAY_BE_ANY|MAY_BE_GUARD)) == (MAY_BE_LONG|MAY_BE_GUARD)
&& !(op1_info & MAY_BE_STRING)) {
ssa->var_info[ssa_op->result_def].type &= ~MAY_BE_GUARD;
}
goto done;
Expand Down
26 changes: 26 additions & 0 deletions ext/opcache/tests/jit/inc_024.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
--TEST--
PRE_INC/DEC numeric string
--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($b) {
$a = "0";
$i = 0;
while (is_numeric($a)) {
$a .= $b;
$a--;
$i .= $a;
$i++;
}
var_dump($a, $i);
}
test("0");
?>
--EXPECT--
string(5) "-INF0"
string(170) "0-2-12-112-1112-11112-111112-1111112-11111112-111111112-1111111112-11111111112-111111111112-1111111111112-11111111111112-1.1111111111111E+15-1.1111111111111E+141-ING-INF1"

0 comments on commit 12d02e6

Please sign in to comment.