Skip to content

Commit

Permalink
Fixed bug #81512 (Unexpected behavior with arrays and JIT)
Browse files Browse the repository at this point in the history
  • Loading branch information
dstogov committed Oct 7, 2021
1 parent 56c9ea1 commit b47a48f
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
1 change: 1 addition & 0 deletions NEWS
Expand Up @@ -28,6 +28,7 @@ PHP NEWS
- Opcache:
. Fixed bug #81472 (Cannot support large linux major/minor device number when
read /proc/self/maps). (Lin Yang)
. Fixed bug #81512 (Unexpected behavior with arrays and JIT). (Dmitry)

- Reflection:
. ReflectionAttribute is no longer final. (sasezaki)
Expand Down
13 changes: 13 additions & 0 deletions ext/opcache/jit/zend_jit_trace.c
Expand Up @@ -1840,6 +1840,18 @@ static zend_ssa *zend_jit_trace_build_tssa(zend_jit_trace_rec *trace_buffer, uin
case ZEND_CHECK_UNDEF_ARGS:
case ZEND_INCLUDE_OR_EVAL:
max_used_stack = used_stack = -1;
case ZEND_TYPE_CHECK:
if (opline->extended_value == MAY_BE_RESOURCE) {
// TODO: support for is_resource() ???
break;
}
if (op1_type != IS_UNKNOWN
&& (opline->extended_value == (1 << op1_type)
|| opline->extended_value == MAY_BE_ANY - (1 << op1_type))) {
/* add guards only for exact checks, to avoid code duplication */
ADD_OP1_TRACE_GUARD();
}
break;
default:
break;
}
Expand Down Expand Up @@ -4904,6 +4916,7 @@ static const void *zend_jit_trace(zend_jit_trace_rec *trace_buffer, uint32_t par
break;
}
op1_info = OP1_INFO();
CHECK_OP1_TRACE_TYPE();
if ((opline->result_type & (IS_SMART_BRANCH_JMPZ|IS_SMART_BRANCH_JMPNZ)) != 0) {
zend_bool exit_if_true = 0;
const zend_op *exit_opline = zend_jit_trace_get_exit_opline(p + 1, opline + 1, &exit_if_true);
Expand Down
34 changes: 34 additions & 0 deletions ext/opcache/tests/jit/bug81512.phpt
@@ -0,0 +1,34 @@
--TEST--
Bug #81512: Unexpected behavior with arrays and JIT
--INI--
opcache.enable=1
opcache.enable_cli=1
opcache.file_update_protection=0
opcache.jit_buffer_size=1M
--FILE--
<?php
$pipe = [['val1'],['val2'],];

for ($i = 0; $i < 30; ++$i) {
echo "$i ";
if (!is_pipeline($pipe)) {
echo 'ERROR ';
}
}

function is_pipeline($pipeline): bool {
foreach ($pipeline as $stage) {
if (!is_array($stage)) {
var_dump($stage);
return false; // must never happen
}

$stage = (array) $stage;
reset($stage);
}

return true;
}
?>
--EXPECT--
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 comments on commit b47a48f

Please sign in to comment.