Skip to content

Commit b3db7f7

Browse files
committed
Merge branch 'PHP-8.4'
* PHP-8.4: Fix phpGH-16879: JIT dead code skipping does not update call_level
2 parents cef23c4 + de30ba5 commit b3db7f7

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed

ext/opcache/jit/zend_jit.c

+28-1
Original file line numberDiff line numberDiff line change
@@ -2714,7 +2714,34 @@ static int zend_jit(const zend_op_array *op_array, zend_ssa *ssa, const zend_op
27142714
}
27152715
/* THROW and EXIT may be used in the middle of BB */
27162716
/* don't generate code for the rest of BB */
2717-
i = end;
2717+
2718+
/* Skip current opline for call_level computation
2719+
* Don't include last opline because end of loop already checks call level of last opline */
2720+
i++;
2721+
for (; i < end; i++) {
2722+
opline = op_array->opcodes + i;
2723+
switch (opline->opcode) {
2724+
case ZEND_INIT_FCALL:
2725+
case ZEND_INIT_FCALL_BY_NAME:
2726+
case ZEND_INIT_NS_FCALL_BY_NAME:
2727+
case ZEND_INIT_METHOD_CALL:
2728+
case ZEND_INIT_DYNAMIC_CALL:
2729+
case ZEND_INIT_STATIC_METHOD_CALL:
2730+
case ZEND_INIT_PARENT_PROPERTY_HOOK_CALL:
2731+
case ZEND_INIT_USER_CALL:
2732+
case ZEND_NEW:
2733+
call_level++;
2734+
break;
2735+
case ZEND_DO_FCALL:
2736+
case ZEND_DO_ICALL:
2737+
case ZEND_DO_UCALL:
2738+
case ZEND_DO_FCALL_BY_NAME:
2739+
case ZEND_CALLABLE_CONVERT:
2740+
call_level--;
2741+
break;
2742+
}
2743+
}
2744+
opline = op_array->opcodes + i;
27182745
break;
27192746
/* stackless execution */
27202747
case ZEND_INCLUDE_OR_EVAL:

ext/opcache/tests/jit/gh16879.phpt

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--TEST--
2+
GH-16879 (JIT dead code skipping does not update call_level)
3+
--EXTENSIONS--
4+
opcache
5+
--INI--
6+
opcache.enable=1
7+
opcache.enable_cli=1
8+
opcache.file_update_protection=0
9+
opcache.jit_buffer_size=32M
10+
opcache.jit=1235
11+
opcache.jit_hot_func=1
12+
--FILE--
13+
<?php
14+
match(0){};
15+
var_dump(new stdClass);
16+
var_dump(3);
17+
?>
18+
--EXPECTF--
19+
Fatal error: Uncaught UnhandledMatchError: Unhandled match case 0 in %s:%d
20+
Stack trace:
21+
#0 {main}
22+
thrown in %s on line %d

0 commit comments

Comments
 (0)