Skip to content

Commit dc3bd55

Browse files
author
Dmitry Stogov
committed
Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0: Fixed incorrect guard elimination
2 parents 4a5d75e + 12d02e6 commit dc3bd55

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
@@ -1068,6 +1068,10 @@ static int is_checked_guard(const zend_ssa *tssa, const zend_op **ssa_opcodes, u
10681068
|| opline->opcode == ZEND_PRE_INC
10691069
|| opline->opcode == ZEND_POST_DEC
10701070
|| opline->opcode == ZEND_POST_INC) {
1071+
if (tssa->ops[idx].op1_use >= 0
1072+
&& (tssa->var_info[tssa->ops[idx].op1_use].type & MAY_BE_STRING)) {
1073+
return 0;
1074+
}
10711075
return 1;
10721076
} else if (opline->opcode == ZEND_ASSIGN_OP
10731077
&& (opline->extended_value == ZEND_ADD
@@ -4259,14 +4263,16 @@ static const void *zend_jit_trace(zend_jit_trace_rec *trace_buffer, uint32_t par
42594263
zend_may_throw(opline, ssa_op, op_array, ssa))) {
42604264
goto jit_failure;
42614265
}
4262-
if ((op1_def_info & (MAY_BE_ANY|MAY_BE_GUARD)) == (MAY_BE_LONG|MAY_BE_GUARD)) {
4266+
if ((op1_def_info & (MAY_BE_ANY|MAY_BE_GUARD)) == (MAY_BE_LONG|MAY_BE_GUARD)
4267+
&& !(op1_info & MAY_BE_STRING)) {
42634268
ssa->var_info[ssa_op->op1_def].type &= ~MAY_BE_GUARD;
42644269
if (opline->result_type != IS_UNUSED) {
42654270
ssa->var_info[ssa_op->result_def].type &= ~MAY_BE_GUARD;
42664271
}
42674272
}
42684273
if (opline->result_type != IS_UNUSED
4269-
&& (res_info & (MAY_BE_ANY|MAY_BE_GUARD)) == (MAY_BE_LONG|MAY_BE_GUARD)) {
4274+
&& (res_info & (MAY_BE_ANY|MAY_BE_GUARD)) == (MAY_BE_LONG|MAY_BE_GUARD)
4275+
&& !(op1_info & MAY_BE_STRING)) {
42704276
ssa->var_info[ssa_op->result_def].type &= ~MAY_BE_GUARD;
42714277
}
42724278
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)