Skip to content

Commit bf786d0

Browse files
committed
Fix phpGH-16393: Assertion failure in ext/opcache/jit/zend_jit.c:2897
1 parent d613c0e commit bf786d0

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

ext/opcache/jit/zend_jit.c

+10-5
Original file line numberDiff line numberDiff line change
@@ -4190,16 +4190,19 @@ static void zend_jit_cleanup_func_info(zend_op_array *op_array)
41904190
}
41914191
}
41924192

4193-
static int zend_real_jit_func(zend_op_array *op_array, zend_script *script, const zend_op *rt_opline)
4193+
static int zend_real_jit_func(zend_op_array *op_array, zend_script *script, const zend_op *rt_opline, uint8_t trigger)
41944194
{
41954195
zend_ssa ssa;
41964196
void *checkpoint;
41974197
zend_func_info *func_info;
4198+
uint8_t orig_trigger;
41984199

41994200
if (*dasm_ptr == dasm_end) {
42004201
return FAILURE;
42014202
}
42024203

4204+
orig_trigger = JIT_G(trigger);
4205+
JIT_G(trigger) = trigger;
42034206
checkpoint = zend_arena_checkpoint(CG(arena));
42044207

42054208
/* Build SSA */
@@ -4232,11 +4235,13 @@ static int zend_real_jit_func(zend_op_array *op_array, zend_script *script, cons
42324235

42334236
zend_jit_cleanup_func_info(op_array);
42344237
zend_arena_release(&CG(arena), checkpoint);
4238+
JIT_G(trigger) = orig_trigger;
42354239
return SUCCESS;
42364240

42374241
jit_failure:
42384242
zend_jit_cleanup_func_info(op_array);
42394243
zend_arena_release(&CG(arena), checkpoint);
4244+
JIT_G(trigger) = orig_trigger;
42404245
return FAILURE;
42414246
}
42424247

@@ -4267,7 +4272,7 @@ static int ZEND_FASTCALL zend_runtime_jit(void)
42674272
opline->handler = jit_extension->orig_handler;
42684273

42694274
/* perform real JIT for this function */
4270-
zend_real_jit_func(op_array, NULL, NULL);
4275+
zend_real_jit_func(op_array, NULL, NULL, ZEND_JIT_ON_FIRST_EXEC);
42714276
} zend_catch {
42724277
do_bailout = true;
42734278
} zend_end_try();
@@ -4313,7 +4318,7 @@ void zend_jit_check_funcs(HashTable *function_table, bool is_method) {
43134318
jit_extension = (zend_jit_op_array_extension*)ZEND_FUNC_INFO(op_array);
43144319
opline->handler = jit_extension->orig_handler;
43154320
if (((double)counter / (double)zend_jit_profile_counter) > JIT_G(prof_threshold)) {
4316-
zend_real_jit_func(op_array, NULL, NULL);
4321+
zend_real_jit_func(op_array, NULL, NULL, ZEND_JIT_ON_PROF_REQUEST);
43174322
}
43184323
}
43194324
} ZEND_HASH_FOREACH_END();
@@ -4339,7 +4344,7 @@ void ZEND_FASTCALL zend_jit_hot_func(zend_execute_data *execute_data, const zend
43394344
}
43404345

43414346
/* perform real JIT for this function */
4342-
zend_real_jit_func(op_array, NULL, opline);
4347+
zend_real_jit_func(op_array, NULL, opline, ZEND_JIT_ON_HOT_COUNTERS);
43434348
} zend_catch {
43444349
do_bailout = 1;
43454350
} zend_end_try();
@@ -4507,7 +4512,7 @@ ZEND_EXT_API int zend_jit_op_array(zend_op_array *op_array, zend_script *script)
45074512
} else if (JIT_G(trigger) == ZEND_JIT_ON_HOT_TRACE) {
45084513
return zend_jit_setup_hot_trace_counters(op_array);
45094514
} else if (JIT_G(trigger) == ZEND_JIT_ON_SCRIPT_LOAD) {
4510-
return zend_real_jit_func(op_array, script, NULL);
4515+
return zend_real_jit_func(op_array, script, NULL, ZEND_JIT_ON_SCRIPT_LOAD);
45114516
} else {
45124517
ZEND_UNREACHABLE();
45134518
}

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)