Skip to content

Commit 023d66d

Browse files
committed
Merge branch 'PHP-8.4'
* PHP-8.4: Fix phpGH-16393: Assertion failure in ext/opcache/jit/zend_jit.c:2897
2 parents edf351c + f68dcc5 commit 023d66d

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
@@ -2871,26 +2871,29 @@ static void zend_jit_cleanup_func_info(zend_op_array *op_array)
28712871
}
28722872
}
28732873

2874-
static int zend_real_jit_func(zend_op_array *op_array, zend_script *script, const zend_op *rt_opline)
2874+
static int zend_real_jit_func(zend_op_array *op_array, zend_script *script, const zend_op *rt_opline, uint8_t trigger)
28752875
{
28762876
zend_ssa ssa;
28772877
void *checkpoint;
28782878
zend_func_info *func_info;
2879+
uint8_t orig_trigger;
28792880

28802881
if (*dasm_ptr == dasm_end) {
28812882
return FAILURE;
28822883
}
28832884

2885+
orig_trigger = JIT_G(trigger);
2886+
JIT_G(trigger) = trigger;
28842887
checkpoint = zend_arena_checkpoint(CG(arena));
28852888

28862889
/* Build SSA */
28872890
memset(&ssa, 0, sizeof(zend_ssa));
28882891

28892892
if (op_array->fn_flags & ZEND_ACC_CLOSURE) {
2890-
if (JIT_G(trigger) == ZEND_JIT_ON_FIRST_EXEC) {
2893+
if (trigger == ZEND_JIT_ON_FIRST_EXEC) {
28912894
zend_jit_op_array_extension *jit_extension = (zend_jit_op_array_extension*)ZEND_FUNC_INFO(op_array);
28922895
op_array = (zend_op_array*) jit_extension->op_array;
2893-
} else if (JIT_G(trigger) == ZEND_JIT_ON_HOT_COUNTERS) {
2896+
} else if (trigger == ZEND_JIT_ON_HOT_COUNTERS) {
28942897
zend_jit_op_array_hot_extension *jit_extension = (zend_jit_op_array_hot_extension*)ZEND_FUNC_INFO(op_array);
28952898
op_array = (zend_op_array*) jit_extension->op_array;
28962899
} else {
@@ -2925,11 +2928,13 @@ static int zend_real_jit_func(zend_op_array *op_array, zend_script *script, cons
29252928

29262929
zend_jit_cleanup_func_info(op_array);
29272930
zend_arena_release(&CG(arena), checkpoint);
2931+
JIT_G(trigger) = orig_trigger;
29282932
return SUCCESS;
29292933

29302934
jit_failure:
29312935
zend_jit_cleanup_func_info(op_array);
29322936
zend_arena_release(&CG(arena), checkpoint);
2937+
JIT_G(trigger) = orig_trigger;
29332938
return FAILURE;
29342939
}
29352940

@@ -2960,7 +2965,7 @@ static int ZEND_FASTCALL zend_runtime_jit(void)
29602965
opline->handler = jit_extension->orig_handler;
29612966

29622967
/* perform real JIT for this function */
2963-
zend_real_jit_func(op_array, NULL, NULL);
2968+
zend_real_jit_func(op_array, NULL, NULL, ZEND_JIT_ON_FIRST_EXEC);
29642969
} zend_catch {
29652970
do_bailout = true;
29662971
} zend_end_try();
@@ -3006,7 +3011,7 @@ void zend_jit_check_funcs(HashTable *function_table, bool is_method) {
30063011
jit_extension = (zend_jit_op_array_extension*)ZEND_FUNC_INFO(op_array);
30073012
opline->handler = jit_extension->orig_handler;
30083013
if (((double)counter / (double)zend_jit_profile_counter) > JIT_G(prof_threshold)) {
3009-
zend_real_jit_func(op_array, NULL, NULL);
3014+
zend_real_jit_func(op_array, NULL, NULL, ZEND_JIT_ON_PROF_REQUEST);
30103015
}
30113016
}
30123017
} ZEND_HASH_FOREACH_END();
@@ -3032,7 +3037,7 @@ void ZEND_FASTCALL zend_jit_hot_func(zend_execute_data *execute_data, const zend
30323037
}
30333038

30343039
/* perform real JIT for this function */
3035-
zend_real_jit_func(op_array, NULL, opline);
3040+
zend_real_jit_func(op_array, NULL, opline, ZEND_JIT_ON_HOT_COUNTERS);
30363041
} zend_catch {
30373042
do_bailout = 1;
30383043
} zend_end_try();
@@ -3203,7 +3208,7 @@ int zend_jit_op_array(zend_op_array *op_array, zend_script *script)
32033208
} else if (JIT_G(trigger) == ZEND_JIT_ON_HOT_TRACE) {
32043209
return zend_jit_setup_hot_trace_counters(op_array);
32053210
} else if (JIT_G(trigger) == ZEND_JIT_ON_SCRIPT_LOAD) {
3206-
return zend_real_jit_func(op_array, script, NULL);
3211+
return zend_real_jit_func(op_array, script, NULL, ZEND_JIT_ON_SCRIPT_LOAD);
32073212
} else {
32083213
ZEND_UNREACHABLE();
32093214
}

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)