[php-src] master: Merge branch 'PHP-8.6'
| From: | Arnaud Le Blanc | Date: | Tue, 27 Oct 2026 15:22:11 +0000 |
| Subject: | [php-src] master: Merge branch 'PHP-8.6' | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-142812@lists.php.net to get a copy of this message | ||
Author: Arnaud Le Blanc (arnaud-lb)
Date: 2026-10-27T16:21:55+01:00
Commit: https://github.com/php/php-src/commit/e080842417647c76a8288ae4aaca015532f4184a
Raw diff: https://github.com/php/php-src/commit/e080842417647c76a8288ae4aaca015532f4184a.diff
Merge branch 'PHP-8.6'
* PHP-8.6:
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 ext/opcache/jit/zend_jit_trace.c
M ext/zend_test/object_handlers.c
Diff:
diff --git a/ext/opcache/jit/zend_jit_trace.c b/ext/opcache/jit/zend_jit_trace.c
index e974dd5b1430..9bdbf3a8a887 100644
--- a/ext/opcache/jit/zend_jit_trace.c
+++ b/ext/opcache/jit/zend_jit_trace.c
@@ -3532,6 +3532,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;
@@ -7251,7 +7265,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 9e78e9fdf524..d878b3bf19a6 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;