[php-src] PHP-8.6: Merge branch 'PHP-8.5' into PHP-8.6
| From: | Arnaud Le Blanc | Date: | Tue, 27 Oct 2026 15:22:09 +0000 |
| Subject: | [php-src] PHP-8.6: Merge branch 'PHP-8.5' into PHP-8.6 | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-142811@lists.php.net to get a copy of this message | ||
Author: Arnaud Le Blanc (arnaud-lb)
Date: 2026-10-27T16:21:45+01:00
Commit: https://github.com/php/php-src/commit/2b22ae0b36d6a58edec6393cd20afb3bd8468fc7
Raw diff: https://github.com/php/php-src/commit/2b22ae0b36d6a58edec6393cd20afb3bd8468fc7.diff
Merge branch 'PHP-8.5' into PHP-8.6
* PHP-8.5:
JIT: fix lost register-allocated CVs on interrupt at the end of a loop trace (#24610)
Changed paths:
A ext/opcache/tests/jit/loop_vm_interrupt_001.phpt
M NEWS
M ext/opcache/jit/zend_jit_trace.c
M ext/zend_test/object_handlers.c
Diff:
diff --git a/NEWS b/NEWS
index 284f7c8b77cf..a7cbfe0c7de6 100644
--- a/NEWS
+++ b/NEWS
@@ -46,6 +46,8 @@ PHP NEWS
. Fixed bug GH-24438 (Preserve indirect types in JIT side traces). (aasul)
. Fixed bug GH-24577 (CE-cache flag on interned class name visible before
map_ptr offset). (prateekbhujel)
+ . Fixed tracing JIT losing register-allocated CVs when an interrupt is
+ handled at the end of a loop trace. (Levi Morrison)
- OpenSSL:
. Fixed build with OpenSSL 4.1. (Weilin Du)
diff --git a/ext/opcache/jit/zend_jit_trace.c b/ext/opcache/jit/zend_jit_trace.c
index bca70815bad1..4927a03ac8ce 100644
--- a/ext/opcache/jit/zend_jit_trace.c
+++ b/ext/opcache/jit/zend_jit_trace.c
@@ -3534,6 +3534,20 @@ static int zend_jit_trace_stack_needs_deoptimization(zend_jit_trace_stack
*stack
return 0;
}
+/* While a trace is being compiled, a register-allocated variable is tracked by
+ * its IR reference only (STACK_REG() is still ZREG_NONE). */
+static bool zend_jit_trace_stack_has_unstored_refs(zend_jit_trace_stack *stack, uint32_t
stack_size)
+{
+ uint32_t i;
+
+ for (i = 0; i < stack_size; i++) {
+ if (STACK_REF(stack, i) && !(STACK_FLAGS(stack, i) & (ZREG_LOAD|ZREG_STORE))) {
+ return 1;
+ }
+ }
+ return 0;
+}
+
static int zend_jit_trace_exit_needs_deoptimization(uint32_t trace_num, uint32_t exit_num)
{
const zend_op *opline = zend_jit_traces[trace_num].exit_info[exit_num].opline;
@@ -7257,7 +7271,8 @@ static zend_vm_opcode_handler_t zend_jit_trace(zend_jit_trace_rec
*trace_buffer,
if (trace_buffer->stop != ZEND_JIT_TRACE_STOP_RECURSIVE_RET) {
if (!(t->flags & ZEND_JIT_TRACE_USES_INITIAL_IP)
|| (ra
- && zend_jit_trace_stack_needs_deoptimization(stack, op_array->last_var +
op_array->T))) {
+ && (zend_jit_trace_stack_needs_deoptimization(stack, op_array->last_var +
op_array->T)
+ || zend_jit_trace_stack_has_unstored_refs(stack, op_array->last_var + op_array->T))))
{
/* Deoptimize to the first instruction of the loop */
uint32_t exit_point = zend_jit_trace_get_exit_point(trace_buffer[1].opline,
ZEND_JIT_EXIT_TO_VM);
diff --git a/ext/opcache/tests/jit/loop_vm_interrupt_001.phpt
b/ext/opcache/tests/jit/loop_vm_interrupt_001.phpt
new file mode 100644
index 000000000000..42196d595c4c
--- /dev/null
+++ b/ext/opcache/tests/jit/loop_vm_interrupt_001.phpt
@@ -0,0 +1,38 @@
+--TEST--
+Tracing JIT: register-allocated loop variable must survive a VM interrupt raised in the loop body
+--DESCRIPTION--
+Comparing two VmInterruptComparable objects sets EG(vm_interrupt) without a
+PHP function call, so the JIT only notices the interrupt at the end of the
+loop. Before handing control to the VM there, it has to write $s back to
+memory, or the loop continues with a stale value.
+
+This only shows up if $s is kept in a callee-saved register across the
+comparison, which is why it's an int: x86_64 has no callee-saved floating
+point registers, so a float would always be spilled to memory first.
+--EXTENSIONS--
+opcache
+zend_test
+--INI--
+opcache.enable=1
+opcache.enable_cli=1
+opcache.jit=tracing
+opcache.jit_buffer_size=64M
+opcache.jit_hot_loop=1
+--FILE--
+<?php
+function sum(array $objs, VmInterruptComparable $t): int {
+ $s = 0;
+ foreach ($objs as $o) {
+ $s += 3;
+ // Only VmInterruptComparable's compare handler raises the interrupt.
+ $r = $o == $t;
+ }
+ return $s;
+}
+
+$objs = array_fill(0, 200, new stdClass);
+$objs[150] = new VmInterruptComparable(0);
+var_dump(sum($objs, new VmInterruptComparable(0)));
+?>
+--EXPECT--
+int(600)
diff --git a/ext/zend_test/object_handlers.c b/ext/zend_test/object_handlers.c
index 6b8bf4ab9912..3f26f687f45f 100644
--- a/ext/zend_test/object_handlers.c
+++ b/ext/zend_test/object_handlers.c
@@ -230,6 +230,8 @@ ZEND_METHOD(NumericCastableNoOperations, __construct)
ZVAL_COPY(OBJ_PROP_NUM(Z_OBJ_P(ZEND_THIS), 0), n);
}
+/* Comparing two VmInterruptComparable objects raises EG(vm_interrupt) without a
+ * function call. Used by ext/opcache/tests/jit/loop_vm_interrupt_001.phpt. */
static zend_class_entry *vm_interrupt_comparable_ce;
static zend_object_handlers vm_interrupt_comparable_object_handlers;