Skip to content

Commit 0a3d551

Browse files
author
Dmitry Stogov
committed
Merge branch 'PHP-8.1'
* PHP-8.1: Fixed incorrect guard elimination
2 parents e964c91 + dc3bd55 commit 0a3d551

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
@@ -1066,6 +1066,10 @@ static int is_checked_guard(const zend_ssa *tssa, const zend_op **ssa_opcodes, u
10661066
|| opline->opcode == ZEND_PRE_INC
10671067
|| opline->opcode == ZEND_POST_DEC
10681068
|| opline->opcode == ZEND_POST_INC) {
1069+
if (tssa->ops[idx].op1_use >= 0
1070+
&& (tssa->var_info[tssa->ops[idx].op1_use].type & MAY_BE_STRING)) {
1071+
return 0;
1072+
}
10691073
return 1;
10701074
} else if (opline->opcode == ZEND_ASSIGN_OP
10711075
&& (opline->extended_value == ZEND_ADD
@@ -4272,14 +4276,16 @@ static const void *zend_jit_trace(zend_jit_trace_rec *trace_buffer, uint32_t par
42724276
zend_may_throw(opline, ssa_op, op_array, ssa))) {
42734277
goto jit_failure;
42744278
}
4275-
if ((op1_def_info & (MAY_BE_ANY|MAY_BE_GUARD)) == (MAY_BE_LONG|MAY_BE_GUARD)) {
4279+
if ((op1_def_info & (MAY_BE_ANY|MAY_BE_GUARD)) == (MAY_BE_LONG|MAY_BE_GUARD)
4280+
&& !(op1_info & MAY_BE_STRING)) {
42764281
ssa->var_info[ssa_op->op1_def].type &= ~MAY_BE_GUARD;
42774282
if (opline->result_type != IS_UNUSED) {
42784283
ssa->var_info[ssa_op->result_def].type &= ~MAY_BE_GUARD;
42794284
}
42804285
}
42814286
if (opline->result_type != IS_UNUSED
4282-
&& (res_info & (MAY_BE_ANY|MAY_BE_GUARD)) == (MAY_BE_LONG|MAY_BE_GUARD)) {
4287+
&& (res_info & (MAY_BE_ANY|MAY_BE_GUARD)) == (MAY_BE_LONG|MAY_BE_GUARD)
4288+
&& !(op1_info & MAY_BE_STRING)) {
42834289
ssa->var_info[ssa_op->result_def].type &= ~MAY_BE_GUARD;
42844290
}
42854291
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)