Skip to content

Commit b47a48f

Browse files
committed
Fixed bug #81512 (Unexpected behavior with arrays and JIT)
1 parent 56c9ea1 commit b47a48f

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ PHP NEWS
2828
- Opcache:
2929
. Fixed bug #81472 (Cannot support large linux major/minor device number when
3030
read /proc/self/maps). (Lin Yang)
31+
. Fixed bug #81512 (Unexpected behavior with arrays and JIT). (Dmitry)
3132

3233
- Reflection:
3334
. ReflectionAttribute is no longer final. (sasezaki)

ext/opcache/jit/zend_jit_trace.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1840,6 +1840,18 @@ static zend_ssa *zend_jit_trace_build_tssa(zend_jit_trace_rec *trace_buffer, uin
18401840
case ZEND_CHECK_UNDEF_ARGS:
18411841
case ZEND_INCLUDE_OR_EVAL:
18421842
max_used_stack = used_stack = -1;
1843+
case ZEND_TYPE_CHECK:
1844+
if (opline->extended_value == MAY_BE_RESOURCE) {
1845+
// TODO: support for is_resource() ???
1846+
break;
1847+
}
1848+
if (op1_type != IS_UNKNOWN
1849+
&& (opline->extended_value == (1 << op1_type)
1850+
|| opline->extended_value == MAY_BE_ANY - (1 << op1_type))) {
1851+
/* add guards only for exact checks, to avoid code duplication */
1852+
ADD_OP1_TRACE_GUARD();
1853+
}
1854+
break;
18431855
default:
18441856
break;
18451857
}
@@ -4904,6 +4916,7 @@ static const void *zend_jit_trace(zend_jit_trace_rec *trace_buffer, uint32_t par
49044916
break;
49054917
}
49064918
op1_info = OP1_INFO();
4919+
CHECK_OP1_TRACE_TYPE();
49074920
if ((opline->result_type & (IS_SMART_BRANCH_JMPZ|IS_SMART_BRANCH_JMPNZ)) != 0) {
49084921
zend_bool exit_if_true = 0;
49094922
const zend_op *exit_opline = zend_jit_trace_get_exit_opline(p + 1, opline + 1, &exit_if_true);

ext/opcache/tests/jit/bug81512.phpt

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
--TEST--
2+
Bug #81512: Unexpected behavior with arrays and JIT
3+
--INI--
4+
opcache.enable=1
5+
opcache.enable_cli=1
6+
opcache.file_update_protection=0
7+
opcache.jit_buffer_size=1M
8+
--FILE--
9+
<?php
10+
$pipe = [['val1'],['val2'],];
11+
12+
for ($i = 0; $i < 30; ++$i) {
13+
echo "$i ";
14+
if (!is_pipeline($pipe)) {
15+
echo 'ERROR ';
16+
}
17+
}
18+
19+
function is_pipeline($pipeline): bool {
20+
foreach ($pipeline as $stage) {
21+
if (!is_array($stage)) {
22+
var_dump($stage);
23+
return false; // must never happen
24+
}
25+
26+
$stage = (array) $stage;
27+
reset($stage);
28+
}
29+
30+
return true;
31+
}
32+
?>
33+
--EXPECT--
34+
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29

0 commit comments

Comments
 (0)