Skip to content

Commit 12d02e6

Browse files
author
Dmitry Stogov
committed
Fixed incorrect guard elimination
1 parent b1e6fde commit 12d02e6

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

ext/opcache/jit/zend_jit_trace.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -964,6 +964,10 @@ static int is_checked_guard(const zend_ssa *tssa, const zend_op **ssa_opcodes, u
964964
|| opline->opcode == ZEND_PRE_INC
965965
|| opline->opcode == ZEND_POST_DEC
966966
|| opline->opcode == ZEND_POST_INC) {
967+
if (tssa->ops[idx].op1_use >= 0
968+
&& (tssa->var_info[tssa->ops[idx].op1_use].type & MAY_BE_STRING)) {
969+
return 0;
970+
}
967971
return 1;
968972
} else if (opline->opcode == ZEND_ASSIGN_OP
969973
&& (opline->extended_value == ZEND_ADD
@@ -3974,14 +3978,16 @@ static const void *zend_jit_trace(zend_jit_trace_rec *trace_buffer, uint32_t par
39743978
zend_may_throw(opline, ssa_op, op_array, ssa))) {
39753979
goto jit_failure;
39763980
}
3977-
if ((op1_def_info & (MAY_BE_ANY|MAY_BE_GUARD)) == (MAY_BE_LONG|MAY_BE_GUARD)) {
3981+
if ((op1_def_info & (MAY_BE_ANY|MAY_BE_GUARD)) == (MAY_BE_LONG|MAY_BE_GUARD)
3982+
&& !(op1_info & MAY_BE_STRING)) {
39783983
ssa->var_info[ssa_op->op1_def].type &= ~MAY_BE_GUARD;
39793984
if (opline->result_type != IS_UNUSED) {
39803985
ssa->var_info[ssa_op->result_def].type &= ~MAY_BE_GUARD;
39813986
}
39823987
}
39833988
if (opline->result_type != IS_UNUSED
3984-
&& (res_info & (MAY_BE_ANY|MAY_BE_GUARD)) == (MAY_BE_LONG|MAY_BE_GUARD)) {
3989+
&& (res_info & (MAY_BE_ANY|MAY_BE_GUARD)) == (MAY_BE_LONG|MAY_BE_GUARD)
3990+
&& !(op1_info & MAY_BE_STRING)) {
39853991
ssa->var_info[ssa_op->result_def].type &= ~MAY_BE_GUARD;
39863992
}
39873993
goto done;

ext/opcache/tests/jit/inc_024.phpt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
--TEST--
2+
PRE_INC/DEC numeric string
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($b) {
12+
$a = "0";
13+
$i = 0;
14+
while (is_numeric($a)) {
15+
$a .= $b;
16+
$a--;
17+
$i .= $a;
18+
$i++;
19+
}
20+
var_dump($a, $i);
21+
}
22+
test("0");
23+
?>
24+
--EXPECT--
25+
string(5) "-INF0"
26+
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 commit comments

Comments
 (0)