Skip to content

Commit f68dcc5

Browse files
committed
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3: Fix phpGH-16393: Assertion failure in ext/opcache/jit/zend_jit.c:2897
2 parents 37db2ed + dd45d85 commit f68dcc5

File tree

2 files changed

+30
-7
lines changed

2 files changed

+30
-7
lines changed

ext/opcache/jit/zend_jit.c

+12-7
Original file line numberDiff line numberDiff line change
@@ -2805,26 +2805,29 @@ static void zend_jit_cleanup_func_info(zend_op_array *op_array)
28052805
}
28062806
}
28072807

2808-
static int zend_real_jit_func(zend_op_array *op_array, zend_script *script, const zend_op *rt_opline)
2808+
static int zend_real_jit_func(zend_op_array *op_array, zend_script *script, const zend_op *rt_opline, uint8_t trigger)
28092809
{
28102810
zend_ssa ssa;
28112811
void *checkpoint;
28122812
zend_func_info *func_info;
2813+
uint8_t orig_trigger;
28132814

28142815
if (*dasm_ptr == dasm_end) {
28152816
return FAILURE;
28162817
}
28172818

2819+
orig_trigger = JIT_G(trigger);
2820+
JIT_G(trigger) = trigger;
28182821
checkpoint = zend_arena_checkpoint(CG(arena));
28192822

28202823
/* Build SSA */
28212824
memset(&ssa, 0, sizeof(zend_ssa));
28222825

28232826
if (op_array->fn_flags & ZEND_ACC_CLOSURE) {
2824-
if (JIT_G(trigger) == ZEND_JIT_ON_FIRST_EXEC) {
2827+
if (trigger == ZEND_JIT_ON_FIRST_EXEC) {
28252828
zend_jit_op_array_extension *jit_extension = (zend_jit_op_array_extension*)ZEND_FUNC_INFO(op_array);
28262829
op_array = (zend_op_array*) jit_extension->op_array;
2827-
} else if (JIT_G(trigger) == ZEND_JIT_ON_HOT_COUNTERS) {
2830+
} else if (trigger == ZEND_JIT_ON_HOT_COUNTERS) {
28282831
zend_jit_op_array_hot_extension *jit_extension = (zend_jit_op_array_hot_extension*)ZEND_FUNC_INFO(op_array);
28292832
op_array = (zend_op_array*) jit_extension->op_array;
28302833
} else {
@@ -2859,11 +2862,13 @@ static int zend_real_jit_func(zend_op_array *op_array, zend_script *script, cons
28592862

28602863
zend_jit_cleanup_func_info(op_array);
28612864
zend_arena_release(&CG(arena), checkpoint);
2865+
JIT_G(trigger) = orig_trigger;
28622866
return SUCCESS;
28632867

28642868
jit_failure:
28652869
zend_jit_cleanup_func_info(op_array);
28662870
zend_arena_release(&CG(arena), checkpoint);
2871+
JIT_G(trigger) = orig_trigger;
28672872
return FAILURE;
28682873
}
28692874

@@ -2894,7 +2899,7 @@ static int ZEND_FASTCALL zend_runtime_jit(void)
28942899
opline->handler = jit_extension->orig_handler;
28952900

28962901
/* perform real JIT for this function */
2897-
zend_real_jit_func(op_array, NULL, NULL);
2902+
zend_real_jit_func(op_array, NULL, NULL, ZEND_JIT_ON_FIRST_EXEC);
28982903
} zend_catch {
28992904
do_bailout = true;
29002905
} zend_end_try();
@@ -2940,7 +2945,7 @@ void zend_jit_check_funcs(HashTable *function_table, bool is_method) {
29402945
jit_extension = (zend_jit_op_array_extension*)ZEND_FUNC_INFO(op_array);
29412946
opline->handler = jit_extension->orig_handler;
29422947
if (((double)counter / (double)zend_jit_profile_counter) > JIT_G(prof_threshold)) {
2943-
zend_real_jit_func(op_array, NULL, NULL);
2948+
zend_real_jit_func(op_array, NULL, NULL, ZEND_JIT_ON_PROF_REQUEST);
29442949
}
29452950
}
29462951
} ZEND_HASH_FOREACH_END();
@@ -2966,7 +2971,7 @@ void ZEND_FASTCALL zend_jit_hot_func(zend_execute_data *execute_data, const zend
29662971
}
29672972

29682973
/* perform real JIT for this function */
2969-
zend_real_jit_func(op_array, NULL, opline);
2974+
zend_real_jit_func(op_array, NULL, opline, ZEND_JIT_ON_HOT_COUNTERS);
29702975
} zend_catch {
29712976
do_bailout = 1;
29722977
} zend_end_try();
@@ -3137,7 +3142,7 @@ int zend_jit_op_array(zend_op_array *op_array, zend_script *script)
31373142
} else if (JIT_G(trigger) == ZEND_JIT_ON_HOT_TRACE) {
31383143
return zend_jit_setup_hot_trace_counters(op_array);
31393144
} else if (JIT_G(trigger) == ZEND_JIT_ON_SCRIPT_LOAD) {
3140-
return zend_real_jit_func(op_array, script, NULL);
3145+
return zend_real_jit_func(op_array, script, NULL, ZEND_JIT_ON_SCRIPT_LOAD);
31413146
} else {
31423147
ZEND_UNREACHABLE();
31433148
}

ext/opcache/tests/jit/gh16393.phpt

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
--TEST--
2+
GH-16393 (Assertion failure in ext/opcache/jit/zend_jit.c:2897)
3+
--EXTENSIONS--
4+
opcache
5+
--INI--
6+
opcache.jit=1215
7+
opcache.jit_buffer_size=64M
8+
--FILE--
9+
<?php
10+
ini_set('opcache.jit', 'tracing');
11+
class Test {
12+
}
13+
$appendProp2 = (function() {
14+
})->bindTo($test, Test::class);
15+
$appendProp2();
16+
?>
17+
--EXPECTF--
18+
Warning: Undefined variable $test in %sgh16393.php on line 6

0 commit comments

Comments
 (0)